Difference between revisions of "GROUP BY"

From rbachwiki
Jump to navigation Jump to search
(Created page with "== Returns queries in groups == SELECT SALES_DATE, SUM(TOTAL_AMOUNT) FROM SALES GROUP BY SALES_DATE; ''' This will take the sales made on the dates add them and return a c...")
 
Line 2: Line 2:
  SELECT SALES_DATE, SUM(TOTAL_AMOUNT)
  SELECT SALES_DATE, SUM(TOTAL_AMOUNT)
  FROM SALES
  FROM SALES
  GROUP BY SALES_DATE;
  GROUP BY SALES_DATE
ORDER BY SALES_DATE;
''' This will take the sales made on the dates add them and return a column with the date -> total amount '''


''' This will take the sales made on the dates add them and return a column with the date -> total amount '''
==Grouping Data using Multiple Columns ==
SELECT SALES_DATE, PRODUCT_ID, SUM(TOTAL_AMOUNT)
FROM SALES
WHERE SALES_DATE BETWEEN '01-JAN-15' AND '31-JAN-15'
GROUP BY SALES_DATE, PRODUCT_ID;
 
'''Ex: a report containing total sales volume for January group by day and product'''

Revision as of 00:15, 1 November 2017

Returns queries in groups

SELECT SALES_DATE, SUM(TOTAL_AMOUNT)
FROM SALES
GROUP BY SALES_DATE
ORDER BY SALES_DATE;

This will take the sales made on the dates add them and return a column with the date -> total amount

Grouping Data using Multiple Columns

SELECT SALES_DATE, PRODUCT_ID, SUM(TOTAL_AMOUNT)
FROM SALES
WHERE SALES_DATE BETWEEN '01-JAN-15' AND '31-JAN-15'
GROUP BY SALES_DATE, PRODUCT_ID;

Ex: a report containing total sales volume for January group by day and product