我有一个名为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
但是,它给了我无效的结果。非常感谢您的帮助。谢谢
答案 0 :(得分:1)
您的group by
和select
应该匹配。我怀疑:
SELECT DATE(created_timestamp_at) as date, SUM(price)
FROM orders
GROUP BY DATE(created_timestamp_at)
ORDER BY MIN(created_timestamp_at) DESC