Welcome 微信登录

首页 / 数据库 / MySQL / MySQL统计函数记录

按年汇总,统计:select sum(mymoney) as totalmoney, count(*) as sheets from mytable group by date_format(col, "%Y");按月汇总,统计:select sum(mymoney) as totalmoney, count(*) as sheets from mytable group by date_format(col, "%Y-%m");按季度汇总,统计:select sum(mymoney) as totalmoney,count(*) as sheets from mytable group by concat(date_format(col, "%Y"),FLOOR((date_format(col, "%m")+2)/3));select sum(mymoney) as totalmoney,count(*) as sheets from mytable group by concat(date_format(col, "%Y"),FLOOR((date_format(col, "%m")+2)/3));按小时:select sum(mymoney) as totalmoney,count(*) as sheets from mytable group by date_format(col, "%Y-%m-%d %H ");查询 本年度的数据:SELECT * FROM mytable WHERE year(FROM_UNIXTIME(my_time)) = year(curdate())查询数据附带季度数:SELECT id, quarter(FROM_UNIXTIME(my_time)) FROM mytable;查询 本季度的数据:SELECT * FROM mytable WHERE quarter(FROM_UNIXTIME(my_time)) = quarter(curdate());本月统计:select * from mytable where month(my_time1) = month(curdate()) and year(my_time2) = year(curdate())本周统计:select * from mytable where month(my_time1) = month(curdate()) and week(my_time2) = week(curdate())N天内记录:WHERE TO_DAYS(NOW())-TO_DAYS(时间字段)<=N
  • 1
  • 2
  • 3
  • 4
  • 5
  • 下一页
【内容导航】
第1页:时间段统计第2页:GROUP_CONCAT()函数
第3页:按条件计数第4页:Join连接详解
第5页:数值函数
Oracle Database 实例关闭和启动logfile文件损坏的问题处理(ORA-00327)相关资讯      MySQL基础教程  MySQL统计函数 
  • MySQL基础教程:关于varchar(N)  (01月22日)
  • MySQL SELECT同时UPDATE同一张表  (02/19/2013 07:20:18)
  • Linux修改MySQL最大并发连接数  (02/15/2013 15:37:21)
  • 高性能MySQL(第3版) 中文PDF带目  (10/26/2014 10:03:50)
  • 如何在MySQL中的获取IP地址的网段  (02/18/2013 12:23:33)
  • C++和C#访问MySQL的简单代码示例  (12/21/2012 09:04:10)
本文评论 查看全部评论 (1)
表情: 姓名: 字数


评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款