0
0
0ldn0mad2019-04-25 19:49:57
SQL
0ldn0mad, 2019-04-25 19:49:57

Where is the error in the request?

There is a table (pictured). The task is to find the total purchases for a certain month.
I made this request, but it doesn't work. Please tell me where to correct it.5cc1e52984c51433979412.png

SELECT goods.purchase_date, SUM(price), MONTH(purchase_date) AS mont
FROM goods
GROUP BY mont

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2019-04-25
@0ldn0mad

SELECT MONTH(purchase_date) AS mont, SUM(price) AS goods_sum
FROM goods
GROUP BY MONTH(purchase_date)

Addition, because life does not end tomorrow.
SELECT YEAR(purchase_date) AS goods_year,
  MONTH(purchase_date) AS goods_month, 
  SUM(price) AS goods_sum
FROM goods
GROUP BY YEAR(purchase_date), MONTH(purchase_date)
ORDER BY 1, 2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question