明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

mysql如何取得規(guī)定時(shí)間段內(nèi)的統(tǒng)計(jì)數(shù)據(jù)的代碼詳細(xì)說(shuō)明

[摘要]這篇文章主要介紹了mysql 獲取規(guī)定時(shí)間段內(nèi)的統(tǒng)計(jì)數(shù)據(jù)的相關(guān)資料,需要的朋友可以參考下mysql 獲取規(guī)定時(shí)間段內(nèi)的統(tǒng)計(jì)數(shù)據(jù)按年統(tǒng)計(jì)SELECT count(*), DATE_FORMAT(order_info.create_time, %Y-%m-%d) AS count_by_date FR...
這篇文章主要介紹了mysql 獲取規(guī)定時(shí)間段內(nèi)的統(tǒng)計(jì)數(shù)據(jù)的相關(guān)資料,需要的朋友可以參考下

mysql 獲取規(guī)定時(shí)間段內(nèi)的統(tǒng)計(jì)數(shù)據(jù)

按年統(tǒng)計(jì)

SELECT 
  count(*), 
  DATE_FORMAT(order_info.create_time, '%Y-%m-%d') AS count_by_date 
FROM 
  order_info 
WHERE 
  DATE_FORMAT(order_info.create_time, '%Y') = '2017' 
GROUP BY 
  count_by_date 
ORDER BY NULL

按月統(tǒng)計(jì)

SELECT 
  count(*), 
  DATE_FORMAT(order_info.create_time, '%Y-%m-%d') AS count_by_date 
FROM 
  order_info 
WHERE 
  DATE_FORMAT(order_info.create_time, '%Y-%m') = '2017-04' 
GROUP BY 
  count_by_date 
ORDER BY NULL

具體變換可以自己根據(jù)需求變更

以上就是mysql如何獲取規(guī)定時(shí)間段內(nèi)的統(tǒng)計(jì)數(shù)據(jù)的代碼詳解的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注php中文網(wǎng)其它相關(guān)文章!


學(xué)習(xí)教程快速掌握從入門(mén)到精通的SQL知識(shí)。