按日期查詢

2021-08-03 12:30:59 字數 1231 閱讀 6434

select date_format(create_time,'

%y%u

') weeks,count(caseid) count

from tc_case group

byweeks;

select date_format(create_time,'

%y%m%d

') days,count(caseid) count

from tc_case group

bydays;

select date_format(create_time,'

%y%m

') months,count(caseid) count

from tc_case group

by months;

date_format(date,format) 

根據format字串格式化date值。下列修飾符可以被用在format字串中: 

%m 月名字(january……december) 

%w 星期名字(sunday……saturday) 

%d 有英語字首的月份的日期(1st, 2nd, 3rd, 等等。) 

%y 年, 數字, 4 位 

%y 年, 數字, 2 位 

%a 縮寫的星期名字(sun……sat) 

%d 月份中的天數, 數字(00……31) 

%e 月份中的天數, 數字(0……31) 

%m 月, 數字(01……12) 

%c 月, 數字(1……12) 

%b 縮寫的月份名字(jan……dec) 

%j 一年中的天數(001……366) 

%h 小時(00……23) 

%k 小時(0……23) 

%h 小時(01……12) 

%i 小時(01……12) 

%l 小時(1……12) 

%i 分鐘, 數字(00……59) 

%r 時間,12 小時(hh:mm:ss [ap]m) 

%t 時間,24 小時(hh:mm:ss) 

%s 秒(00……59) 

%s 秒(00……59) 

%p am或pm 

%w 乙個星期中的天數(0=sunday ……6=saturday ) 

%u 星期(0……52), 這裡星期天是星期的第一天 

%u 星期(0……52), 這裡星期一是星期的第一天 

%% 乙個文字「%」。

mysql按日期查詢資料 mysql按日期查詢資料

問題 mysql按日期查詢乙個月內的資料,查詢返回時結果集中只顯示有資料的結果 需求 查詢結果中假如當天沒有資料,自動填零並輸出 事件描述 sql語句 select date format date added,m.d as day,count product id as total from ht...

sql按日期查詢

查詢當天 1 select from shoporder where datediff day,ordtime,getdate 1 0 查詢當天 2 select from info where datediff dd,datetime,getdate 0 前30天 select from a wh...

sql中按日期查詢

查詢當天 1 select from shoporder where datediff day,ordtime,getdate 1 0 查詢當天 2 select from info where datediff dd,datetime,getdate 0 前30天 select from a wh...