SQL question Note: Google bigquery - handy-bonbon - order_entry_dataset(free, public) Question: Which month (be sure to say
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 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
;
Cost management a strategic approach
ISBN: 978-0073526942
5th edition
Authors: Edward J. Blocher, David E. Stout, Gary Cokins