按年彙總,統計:
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
MySql分時間段統計
在統計業務辦理人數的時候,需要從task 201907表裡面統計7月內每一天辦理的人數,網羅上查到大家用格式化時間戳的方法,剛開始還沒看懂,原來是利用的from unixtime函式。查詢邏輯 表中有時間字段,按照時間 天 分組統計參與人數。問題 如果直接按照時間 datetime 字段分組,是精確...
時間段函式
在sql server中,操作select查詢時,將時間型別的字段作為搜尋條件,如果稍微不注意,也許沒有辦法查詢到意想的結果。條件不能用等於,而是時間段。如某一天,應該是從00 00 00至23 59 59之間,方可查詢出結果出來。因此,為了開發方便,寫了乙個函式 setansi nulls ong...
mysql按照時間段內 每天統計
sql select t.report time,count report time from select date format report time,y m d as report time from report count as t group by t.report time date...