有 articles表
id class title content pubtime
1 10 标题1 内容1 1342756599
2 11 标题2 内容2 1339392385
3 12 标题3 内容3 1339390661
4 10 标题4 内容4 1339139926
5 13 标题5 内容5 1339139892
6 16 标题6 内容6 1342756624
希望查询的结果是:
1.如2012年8月、2012年6月内有文章,输出一次 2012年8月、2012年6月的链接,最好能计算出汇总,有多少篇文章。
2.如2012年7月16日、2012年7月28日有文章 则倒序输出 2012年7月28日、2012年7月16日的链接,最好能计算出汇总,有多少篇文章。
不会写,给个思路也行啊。
------解决方案--------------------
sql codeselect count(1) from `articles` where `pubtime` > 6月1号0点时间戳 and `postdate` ------解决方案--------------------
探讨
select count(1) from `articles` where `pubtime` > 6月1号0点时间戳 and `postdate`
------解决方案--------------------
sql code>select count(1), date(pubtime) from articles group by date(pubtime);
------解决方案--------------------
先把几个点的时间戳取出来.如2012年8月、2012年6月。
然后在拼接sql查询,应该很容易的。
别着急,你试试
------解决方案--------------------
1、
select from_unixtime(pubtime, '%y-%m') as pubtime, count(*) as cnt from articles group by from_unixtime(pubtime, '%y-%m')
------解决方案--------------------
这是每个月:
sql code>select count(1), extract(year_month from pubtime) from articles group by extract(year_month from pubtime);
------解决方案--------------------
有个问题,在sql中使用函数会影响sql的执行效率,被用字段的主键什么的,有时候也没效果
探讨
这是每个月:
sql code
>select count(1), extract(year_month from pubtime) from articles group by extract(year_month from pubtime);
引用:
sql code
>select count(1), date(pubtime) from article……
------解决方案--------------------
探讨
我怎么能一次性查出 2012年6月 和 2012年8月
一年有12个月 我不能每个月都写一个语句吧,我想一次性查询一个月每一天是否有文章 一个月30天呢
就是这儿 怎么做呢
------解决方案--------------------
sql codeselectsum(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_8from dc_admin
