【问题标题】:Statistic of sales per day in the last 30 day过去 30 天每天的销售额统计
【发布时间】:2022-01-18 07:11:57
【问题描述】:

我有一个任务是统计过去 30 天每天的销售额...我找到了一种只显示上个月的方法:

SELECT * 
FROM purchase
WHERE date >= date('01-05-2021', current_date - interval '1 month')
  and date < date('01-05-2021', current_date)

购买中的列只是 id、value、date、cashier 和 store id 你认为最好的方法是什么? 我有这个,但我不知道它不工作......我是 postgresql 的新手,所以请不要被这个冒犯

【问题讨论】:

    标签: sql postgresql


    【解决方案1】:

    date 分组并使用sum 查找总数。

    select date,sum(value)
    from purchase
    where date between current_date - interval '1 month' and current_date - 1
    group by date
    

    【讨论】:

      猜你喜欢
      • 2014-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-18
      • 2018-08-12
      • 1970-01-01
      • 1970-01-01
      • 2016-03-26
      相关资源
      最近更新 更多