Home  >  Article  >  Backend Development  >  求教一个数据库有关问题,有张表,里面有每天存入的数据,如何取出每个月数据的条数

求教一个数据库有关问题,有张表,里面有每天存入的数据,如何取出每个月数据的条数

WBOY
WBOYOriginal
2016-06-13 12:27:05795browse

求教一个数据库问题,有张表,里面有每天存入的数据,怎么取出每个月数据的条数。
这是ec_ip_article表,iptime是每天的时间戳。有没有简便一点的方法,不想每个月一条条sql取出来,然后再count得出数目,那样sql太多了。

------解决思路----------------------

select FROM_UNIXTIME(iptime,'%Y-%m') as m, count(*) as cnt from ec_ip_article group by 1

------解决思路----------------------
<br />select FROM_UNIXTIME(iptime,'%Y%m%d'),count(0) from ec_ip_article group by FROM_UNIXTIME(iptime,'%Y%m%d')<br />

------解决思路----------------------

引用:
<br />select FROM_UNIXTIME(iptime,'%Y%m%d'),count(0) from ec_ip_article group by FROM_UNIXTIME(iptime,'%Y%m%d')<br />


select FROM_UNIXTIME(iptime,'%Y%m'),count(0) from ec_ip_article group by FROM_UNIXTIME(iptime,'%Y%m')
------解决思路----------------------
<br />SELECT ip_id,count(ip_id) count,FROM_UNIXTIME(iptime, '%Y%m%d') date FROM test GROUP BY FROM_UNIXTIME(iptime, '%c') ORDER BY iptime<br />

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn