团长,有空帮我看看,谢谢!

2018-2-13 20:56:44 鱼影 Forever棒(班班号码:72269312 | 分类:其他 | 浏览335次
想调用本月、上月、今年、本周、上周的一个表的数据,但是条件语句不知道怎么写,我试着写如下:
  1. <!--{eval $benyueo = date("Ym",time()); $benyue= DB::result(DB::query("SELECT sum(price) FROM ".DB::table('caiwu')." WHERE FROM_UNIXTIME(dateline, '%Y%m') = '$benyueo' "));}-->
  2. <!--{eval $shangyueo = date("Ym",time()); $lastyuecza = DB::result(DB::query("SELECT sum(price) FROM ".DB::table('caiwu')." WHERE  PERIOD_DIFF($shangyueo,FROM_UNIXTIME(dateline,'%Y%m')) = 1"));}-->
  3. <!--{eval $jinniano = date("Y",time()); $jinnian = DB::result(DB::query("SELECT sum(price) FROM ".DB::table('caiwu')." WHERE  FROM_UNIXTIME(dateline, '%Y') = '$jinniano' "));}-->
复制代码
这个上面写的是本月、上月、和今年的调用但是前台不出数据,不知道为啥?后来去网上找了内容如下:
  1. 查询当前这周的数据
  2. SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,'%Y-%m-%d')) = YEARWEEK(now());

  3. 查询上周的数据
  4. SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,'%Y-%m-%d')) = YEARWEEK(now())-1;

  5. 查询当前月份的数据
  6. select name,submittime from enterprise where date_format(submittime,'%Y-%m')=date_format(now(),'%Y-%m');

  7. 查询上个月的数据
  8. select name,submittime from enterprise where date_format(submittime,'%Y-%m')=date_format(DATE_SUB(curdate(), INTERVAL 1 MONTH),'%Y-%m');  


  9. 查询本年数据
  10. SELECT * FROM  表名 WHERE YEAR(create_date)=YEAR(NOW());
复制代码
我将where后面一到调用语句上去,也不行,不知道为啥?
2018-2-26 20:37:34
提问者采纳
已私信联系处理!

班班学院院长(班班号码:1000,来自:班班学院