dongtan6206 2017-07-06 15:00
浏览 100
已采纳

在两个日期之间获取数据并按个别日期对其进行分组

The title of the question might be a bit confusing but, essentially, what I'm trying to do is to retrieve DAILY data from a database that is in a certain date range using PHP.

For example, assume that I have a table like so:

ID  |  Value  |  Date
1   |  12     |  2017-01-01
2   |  8      |  2017-01-01
3   |  10     |  2017-01-02

I need to retrieve the daily total value.

TotalValue  |  Date
   20       |  2017-01-01
   10       |  2017-01-02

At the current time, I'm using a query that retrieves the total value for a given date and I do this for every single day in the date range. As you can imagine, this is not an efficient way of doing this, especially if you are retrieving records for the past year. I've not found an answer which closely resembles my problem.

  • 写回答

1条回答 默认 最新

  • doubu4406 2017-07-06 15:06
    关注

    you could use group by and between

       select sum(value) as TotalValue, Date
       from my_table 
       where date between '2017-01-01' and '2017-01-02'
       group by date
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器