logo
down
shadow

sql Group by columns to the same row without join


sql Group by columns to the same row without join

By : user2185699
Date : November 22 2020, 04:01 AM
it fixes the issue I have grouped sales from a sales view with sales below using , You can do conditional aggregation :
code :
select id, name,
       sum(case when Product = 'Fridge' then 1 else 0 end) as [Fridge Sales],
       sum(case when Product = 'Fridge' then Amount else 0 end) as [fridge Amt], 
       sum(case when Product = 'Washer' then 1 else 0 end) as [Washer Sales],
       sum(case when Product = 'Washer' then Amount else 0 end) as [Washer Amt]
from vwSales
Group by id, name; 


Share : facebook icon twitter icon
Adding other columns into a join with a group by

Adding other columns into a join with a group by


By : denebx3
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further In Oracle 11g Express, I have the following query: , Vendor should also be included in the GROUP BY clause.
code :
GROUP BY t1.product_name, t2.vendor
SELECT t1.product_name,
    (
        select sum(product_cost_per_month) 
         from table2 t2 
         where 
            t1.product_name = t2.product_name 
            and t2.date > sysdate
    ) as total_product_cost,
    t1.another_field,
    t1.another_field2,
    t1.another_field3
FROM table1
Doing a LINQ join, then group by, then a sum on two different columns

Doing a LINQ join, then group by, then a sum on two different columns


By : 姜堰哪里能买到印度神油
Date : March 29 2020, 07:55 AM
help you fix your problem Your problem is likely that the Budget amount is incorrect, because you are summing them for every combination. For example, if you had budget data looking like this:
code :
Budget | Amount
Dev    | 2500
Budget | Amount
Dev    | 1000
Dev    | 750
BA   | BT
2500 | 1000
2500 | 750
Budget | Actual
5000   | 1750
var q =
   (from ii in
        (from a in table1 group a by a.BudgetUnitID into g
         select new { BudgetUnitID = g.Key, Amount = g.Sum(x => x.Amount) })
    join jj in
        (from b in table2 group b by b.BudgetUnitID into g
         select new { BudgetUnitID = g.Key, Amount = g.Sum(x => x.Amount) })
        on ii.BudgetUnitID equals jj.BudgetUnitID
         select new { Actual = ii.Amount, Budget = jj.Amount, Variance = jj.Amount - ii.Amount, BUID = ii.BudgetUnitID }
    ).ToList();
Join two tables and group by two columns

Join two tables and group by two columns


By : Griek
Date : March 29 2020, 07:55 AM
hope this fix your issue I have two MySQL tables.
code :
SELECT b.country, 
       SUM(a.type = 'Social') as social,
       SUM(a.type = 'Economic') as economic,
       SUM(a.type = 'Culture') as culture
FROM Post a 
INNER JOIN User b ON a.id = b.id 
GROUP BY b.country
Group By two Date columns and Sum Two Columns in a join

Group By two Date columns and Sum Two Columns in a join


By : c.pane20
Date : March 29 2020, 07:55 AM
wish helps you I want to group my data by two dates (dateDu and DateAu)and sum two columns (Debit and Credit)from different tables join. , I believe that what you need is a query like below
code :
select   
    DateDu,
    DateAu,
    'Solde'=SUM(Det.Debit) - SUM(Det.Credit) 
from AffectationAbonnement Aff
    join DetailAbonnements Det 
        on Aff.Abonnement_Id = Det.Abonnements_Id
where Abonnement_Id= 8
group by DateDu, DateAu
How to get the sum of columns from a group of records in a join?

How to get the sum of columns from a group of records in a join?


By : user3565136
Date : March 29 2020, 07:55 AM
seems to work fine I have a request that returns documents to me. I would like to join the sums of goods of each document and summarize them. , Add group by document id and sum of total sum
code :
$result = DB::table('documents as docs')
    ->leftJoin('products as t_products', function($join) {
        $join->on('t_products.document_id', '=', 'docs.document_id');
    })
    ->where('docs.owner_id', '=', $currentUserId)
    ->selectRaw('docs.document_id, sum(t_products.total_sum) as total_sum')
    ->groupBy('docs.document_id')
    ->get();
Related Posts Related Posts :
  • Splitting 24 hours into 96 equal 15 minute intervals in T-SQL
  • WHERE clause not hitting on LEFT JOIN
  • SQL Pivot String Data
  • Redshift - Find % as compared to total value
  • How to find count of N columns in a table
  • SQL statement giving no result
  • IN condition is not working when the data is like 'Test','Test' from a result query
  • SUM of COUNT with only certain variables
  • How to get all products with at least X reviews in SQL?
  • Check if an integer is within the next 5 increments in SQL, when the numbers can wrap
  • Case and When query give me both column filled
  • How to check JSON string on contains field AND like value?
  • Find uncovered periods without exploding each combination
  • How to compare date to format date on oracle
  • SQL Server : duplicate rows when joining tables and inserting new data?
  • Oracle - Combine timestamp with date and remove duplicates
  • Array to json and row to json in SQL Server 2016
  • Modifying SQL code to pick the Dropdown list instead of constant text
  • How to get max value of column values in a record ? (BigQuery)
  • Elasticsearch filter after aggregation
  • Teradata: varchar to timestamp 2
  • specific row number with all the fields
  • INSERT INTO SELECT query in SQL where primary key is used and multiple duplicates are in another table
  • SQL Query - Eliminate records
  • What is wrong with this SQL join query
  • Hybris Flexible search union query to fetch products
  • Stale Data Count
  • Adding new column of total_event
  • Query to Skip the first Delimiter and select the second Delimiter In SQL
  • Very slow (12+ hours) large table joins in postgres
  • LINQ query for specific group
  • SQL - return xpath for multiple XML results
  • Can't compile my trigger in Apex Oracle SQL/PL PLS-00103
  • Select 1 field from a group
  • Airflow + pandas read_sql_query() with commit
  • Get higest value of each relation
  • SQL - select limit column2 values for distinct column 1
  • Compilation failed, PLS-00103 pl/sql
  • SQL Query for all IDs where all rows with that ID match a value in another column
  • How to correctly translate sql-code in Delphi
  • How do I join 2 tables to allocate items?
  • PARTITION BY in CASE doesn't work with several AND statements
  • SQL. How to combine two records with the same ID into one line based on value's in a column
  • How to update tables from an external Access database with identical tables?
  • Trying to find records between two dates on one table and some information on another
  • Why does adding ORDER BY drastically speed up query?
  • SQL syntax explanation (CAST, INSERT, DATE)
  • My query with <> to / NOT IN () clause not returning any values?
  • Comparing 2 tables
  • How do I filter my table to show the result in Oracle?
  • SQL Server 2016: How to read different substrings from a text with special characters
  • Oracle - Left Anti Join on same table
  • Maximum Capacity for BULK INSERT from files such as CSV
  • simple JSON array to Rows
  • SQL Server - matching attributes query
  • SQL Server - Duplicate rows and add date iterator column between two date values
  • Oracle - hh mm ss to hh:mm:ss with one exotic
  • Delete an element from a certain row in an XML-type column in SQL?
  • SQL how to find tables with more than 1 row with criteria?
  • query to get count, subtotal and total over a date range
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org