MySql按分鐘,小時,天,月,年進行統計查詢

2021-09-17 03:14:03 字數 1327 閱讀 1912

很多日誌統計的情況中,會出現按照小時,天,月來進行統計分析

以分鐘為單位做日誌統計分析

select count(*) as n,date_format(inserttime,'%y-%m-%d %h:%i:00')  from `data_log_201904-u`

where inserttime>='2019-04-01 01:00:00' and inserttime <= '2019-04-01 01:59:59'

group by date_format(inserttime,'%y-%m-%d %h:%i');

以小時為單位做日誌統計分析

select count(*) as n,date_format(inserttime,'%y-%m-%d %h:00:00')  from `data_log_201904-u`

where inserttime>='2019-04-01 00:00:00' and inserttime <= '2019-04-01 23:59:59'

group by date_format(inserttime,'%y-%m-%d %h');

以天為單位做日誌統計分析

select count(*) as n,date_format(inserttime,'%y-%m-%d')  from `data_log_201904-u`

where inserttime>='2019-04-01 00:00:00' and inserttime <= '2019-04-16 23:59:59'

group by date_format(inserttime,'%y-%m-%d');

以月為單位做日誌統計分析

select count(*) as n,date_format(inserttime,'%y-%m')  from `data_log_2019-u`

where inserttime>='2019-00-01 00:00:00' and inserttime <= '2019-04-01 23:59:59'

group by date_format(inserttime,'%y-%m');

以年為單位做日誌統計分析

select count(*) as n,date_format(inserttime,'%y')  from `data_log_all-u` group by date_format(inserttime,'%y');
年月日表達格式(注意大小寫的區分

按小時,天,周,月進行查詢

按小時統計 查詢當天存在的所有時刻 即00 23時刻 select sdays level 1 24 dates from select to date 2012 01 05 00 yyyy mm dd hh24 sdays,to date 2012 01 05 23 yyyy mm dd hh24...

資料庫時間按天 小時 分鐘來進行分組

group by left convert nvarchar 11 addtime,21 00 00 00 19 按小時分組,按分鐘,按天,以最長的為準,然後再擷取,先以統一的標準來增加,再以統一的標準來裁剪 select left convert nvarchar 11 getdate 21 00...

mysql 按小時,按天,按周等 統計

按周 select date format create time,y u weeks,count caseid count from tc case group by weeks 按月select date format create time,y m months,count caseid co...