select count(1), extract(year_month from pubtime) from articles group by extract(year_month from pubtime);我这个不行吗?
1.select FROM_UNIXTIME(pubtime, '%Y-%m') as pubtime, count(*) as cnt from articles group by FROM_UNIXTIME(pubtime, '%Y-%m')2.select count(1), extract(year_month from pubtime) from articles group by extract(year_month from pubtime);这两句sql得到的结构不一样?领教了
SELECT SUM(CASE when MONTH( FROM_UNIXTIME(pubtime, '%Y-%m-%d'))=6 THEN 1 ELSE 0 END)AS sum_6, SUM(CASE when MONTH( FROM_UNIXTIME(pubtime, '%Y-%m-%d'))=8 THEN 1 ELSE 0 END)AS sum_8 FROM dc_admin 数字表示是 哪个月份的
...复制错了个单词SELECT count(1) FROM `articles` WHERE `pubtime` > 6月1号0点时间戳 and `pubtime` < 7月1号0点时间戳查文章 就select *
然后在拼接sql查询,应该很容易的。
别着急,你试试
select FROM_UNIXTIME(pubtime, '%Y-%m') as pubtime, count(*) as cnt from articles group by FROM_UNIXTIME(pubtime, '%Y-%m')
>select count(1), extract(year_month from pubtime) from articles group by extract(year_month from pubtime);
你想一次性得到6月和8月的文章,你就要多写个函数,6,8作为数组array(6,8)传进去,这样你就可以查几个月的文章,然后生成时间戳查询就OK了,我sql不咋个样,不清楚sql可以直接查处不...
SELECT
SUM(CASE when MONTH( FROM_UNIXTIME(pubtime, '%Y-%m-%d'))=6 THEN 1 ELSE 0 END)AS sum_6,
SUM(CASE when MONTH( FROM_UNIXTIME(pubtime, '%Y-%m-%d'))=8 THEN 1 ELSE 0 END)AS sum_8
FROM dc_admin
数字表示是 哪个月份的