dqc18251 2014-05-25 10:21
浏览 693
已采纳

按日期对一组数据进行分组

The question is a little on the noobish end as I'm just starting to mess with PHP. However my project is to create a basic statistics page. So let me go ahead and explain exactly what I'm looking for (in it's most basic form).

Basically I have an table with the following structure. [ TransactionID, Date, Amount ]
What I want to do is group everything by a certain date and display all of the transactions that happened on that date, so I believe the query would look something like this.

Select * from table where date = 2014-05-24

Alright, that's all fine and dandy and I can easily get the sum like that, but How would I get the transactions for a certain month, or year even?

This is a personal project and won't be used at all on a professional scale, but it's something that I'm working on as a hobby.

  • 写回答

3条回答 默认 最新

  • dongwen3437 2014-05-25 10:41
    关注

    If your Date column is of type DateTime, you may see date functions in Mysql.

    To get all records for a specific date like 2014-05-24 :

    Select * from table T where Date(T.date) = Date('2014-05-24')
    

    To get all records for a specific year like 2014 :

    Select * from table T where Year(T.date) = Year('2014-05-24')
    

    For a specific month of year like 5th of 2014

    Select * from table T where Year(T.date) = Year('2014-05-24') 
    and 
    Month(T.date) = Month('2014-05-24')
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建