0% found this document useful (0 votes)
29 views1 page

Query

The document contains four SQL queries that select data from a sales table and perform aggregations and extracts on date fields to group or partition the results by month, year, and city.

Uploaded by

An Ngo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views1 page

Query

The document contains four SQL queries that select data from a sales table and perform aggregations and extracts on date fields to group or partition the results by month, year, and city.

Uploaded by

An Ngo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

SELECT city, MONTH(date) AS MONTH, YEAR(date) AS YEAR,

SUM(CONVERT(SUBSTR(invoice,2,5),INT)) AS SUM FROM sales GROUP BY city, YEAR(date),


MONTH(date)

SELECT DISTINCT MONTH(DATE) AS MONTH, YEAR(date) AS YEAR, SUM(VENDOR)


OVER(PARTITION BY YEAR, MONTH) FROM sales

SELECT city, EXTRACT(MONTH FROM DATE) AS MONTH, EXTRACT(YEAR FROM DATE) AS YEAR,
SUM(CAST(SUBSTR(invoice,2,5) AS INT64)) AS SUM FROM sales GROUP BY city, YEAR,
MONTH

SELECT DISTINCT EXTRACT(MONTH FROM DATE) AS MONTH, EXTRACT(YEAR FROM DATE) AS YEAR,
SUM(CAST(VENDOR AS INT64)) OVER(PARTITION BY YEAR, MONTH) FROM sales

You might also like