Question: SQL question Note: Google bigquery - handy-bonbon - order_entry_dataset(free, public) Question: Which month (be sure to say from which year) had thelargest percentage decrease in
SQL question
Note: Google bigquery - handy-bonbon - order_entry_dataset(free, public)
Question:
Which month (be sure to say from which year) had thelargest percentage decrease in sales over the prior month? Justifyyour rationale and show your SQL query (Hint: use the LAGfunction).
This is my code and I don't know how to fix it.
SELECT
FORMAT_DATE("%Y-%m", order_date) ASOrder_month,
ROUND(SUM(unit_price * quantity), 2) ASAmount_Ordered,
LAG(ROUND( SUM(unit_price * quantity), 2),1,0) OVER(ORDER BY FORMAT_DATE("%Y-%m", order_date)) ASLast_Row
FROM`handy-bonbon-142723.order_entry_dataset.customers_table`
INNER JOIN
`handy-bonbon-142723.order_entry_dataset.orders_table`USING (customer_id)
INNER JOIN
`handy-bonbon-142723.order_entry_dataset.order_items_table`USING(order_id)
INNER JOIN
`handy-bonbon-142723.order_entry_dataset.products_table`USING(PRODUCT_ID)
GROUP BY ORDER_DATE
;
Step by Step Solution
3.40 Rating (159 Votes )
There are 3 Steps involved in it
Answer The month with the largest percentage decrease in sales over the prior month is July 2019 To ... View full answer
Get step-by-step solutions from verified subject matter experts
