select count(id) as c from dede_archives where from_unixtime(pubdate,'%m') = month(curdate( ))以上SQL语句是统计一个月的信息数量,如何改成统计一周的信息数量?

解决方案 »

  1.   

    select count(id) as c from dede_archives where week(pubdate) = week(curdate( ))
      

  2.   

    不计算字段pubdate的月份,程序中计算出时间戳就好了,这样效率更高,否则不是浪费unix_timestamp的pubdate字段了?
    另外,月份统计你这句也是有问题的,每年都有某个月份哦【除非按年分表了……
      

  3.   

    保存的是时间戳 可用 pubdate>=xx and pubdate<=xx 或下面 between 
    select count(id) as c from dede_archives where pubdate between xx and xxxfrom_unixtime(pubdate,'%Y-%m-%d') 转换成  2011-07-29  这种日期类型比较
      

  4.   

    pubdate有索引的情况,用时间戳统计效率更高……否则是扫全表
      

  5.   

    严格的说用 week 是不行的 返回为一年的第几周
    应该用 date_format( date, '%X%V')