SQL查询给出无效结果

时间:2019-05-09 15:12:19

标签: mysql sql

我有一个名为orders的表,其中包含“ price”,“ order_id”,“ cust_id”,“ product_id”,“ timestamp_at”等列

我正在尝试编写一条SQL语句,以打印出该月的每一天的日期和总收入,

我的sql查询如下

SELECT date, SUM(price) 
FROM orders 
GROUPBY DATE(created_timestamp_at) 
ORDER BY created_timestamp_at DESC

但是,它给了我无效的结果。非常感谢您的帮助。谢谢

1 个答案:

答案 0 :(得分:1)

您的group byselect应该匹配。我怀疑:

SELECT DATE(created_timestamp_at) as date, SUM(price)
FROM orders
GROUP BY DATE(created_timestamp_at)
ORDER BY MIN(created_timestamp_at) DESC