Please modify the following query to reflect the data only from Qtr. #2 of the s
ID: 3566408 • Letter: P
Question
Please modify the following query to reflect the data only from Qtr. #2 of the standard year (Jan-Mar.).
SELECT Extract(YEAR from orderdate) as year,
Extract(MONTH from orderdate) as month,
COUNT(*) as numorders, COUNT(DISTINCT customerid) as numcust,
SUM(totalprice) as totspend,
SUM(totalprice)*1.0/COUNT(*) as avgordersize,
SUM(totalprice)*1.0/COUNT(DISTINCT customerid) as avgcustorder
FROM dw.orders o
WHERE Extract(MONTH from orderdate) > 9
GROUP BY Extract(YEAR from orderdate),
Extract(MONTH from orderdate)
ORDER BY 1, 2;
*************************************************************
The answer to the query is listed below, however, it does not work. The query does not work. error message: "SQL command not properly ended". Please check it again.
SELECT Extract(YEAR from orderdate) as year,
Extract(MONTH from orderdate) as month,
COUNT(*) as numorders, COUNT(DISTINCT customerid) as numcust,
SUM(totalprice) as totspend,
SUM(totalprice)*1.0/COUNT(*) as avgordersize,
SUM(totalprice)*1.0/COUNT(DISTINCT customerid) as avgcustorder
FROM dw.orders o
WHERE Extract(MONTH from orderdate) >=4 , Extract(MONTH from orderdate) <=6
GROUP BY Extract(YEAR from orderdate),
Extract(MONTH from orderdate)
ORDER BY 1, 2;
Explanation / Answer
SELECT Extract(YEAR from orderdate) as year,
Extract(MONTH from orderdate) as month,
COUNT(*) as numorders, COUNT(DISTINCT customerid) as numcust,
SUM(totalprice) as totspend,
SUM(totalprice)*1.0/COUNT(*) as avgordersize,
SUM(totalprice)*1.0/COUNT(DISTINCT customerid) as avgcustorder
FROM dw.orders o
WHERE Extract(MONTH from orderdate) > 9
GROUP BY Extract(YEAR from orderdate),
Extract(MONTH from orderdate)
ORDER BY 1, 2;
----------------------------------------------------------------------------------------------------------------------------------------
SELECT Extract(YEAR from orderdate) as year,
Extract(MONTH from orderdate) as month,
COUNT(*) as numorders, COUNT(DISTINCT customerid) as numcust,
SUM(totalprice) as totspend,
SUM(totalprice)*1.0/COUNT(*) as avgordersize,
SUM(totalprice)*1.0/COUNT(DISTINCT customerid) as avgcustorder
FROM dw.orders o
WHERE Extract(MONTH from orderdate) >=4 AND Extract(MONTH from orderdate) <=6
GROUP BY Extract(YEAR from orderdate),
Extract(MONTH from orderdate)
ORDER BY 1, 2;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.