我无法sum()在数据库中使用某个功能。我要查询表purchases中的store_id(从表中检索到的stores),month(+年)购买量(存储为timestamp 指定的不带时区)以及按月显示sum的total销售收入。问题在于没有聚合发生,因此每个销售的总计被报告为给定商店的每月销售总计。我想我没有正确使用`sum()’,但是我还没有找到解决方案。建议和意见表示赞赏。
SELECT --month of purchase, total sales purchases.store_id AS store_id, TO_CHAR(timestamp, 'Month'||'YYYY') AS month, sum(total) AS total_sales FROM purchases GROUP BY store_id, timestamp, purchases.total ORDER BY month, store_id;