鏈接:https://www.yiibai.com/mysql/substring.html
博客:https://www.cnblogs.com/Fooo/p/3435687.html
問:
sql題 如何統(tǒng)計查詢一個月中每天的記錄
比如說要查2010年3月份每天的記錄
答:(原博底下評論說不對,這里不做討論,學習它用到的函數(shù),可以看第一個鏈接)
select count(*),substr(t.date,1,10) from table t where t.date like '2010-03%' group by substr(t.date,1,10)
date的格式是YYYY-mm-dd hh:mm:ss
函數(shù):
聚合函數(shù) count()
substring() 函數(shù) ,我試過用 substr(), 得到的答案是一樣的。作用:從字符串中提取子字符串
兩種形式:
substring(string,position);

image.png
substring(string,position,length)

image.png