0
点赞
收藏
分享

微信扫一扫

本日、本周、本月和按月取数据的SQL语句

weipeng2k 2022-09-15 阅读 171


$time = time()+8*3600;
$nowtime = date("Y-m-d",$time);
$weekfirst = strtotime('-1 week Monday');
$monthfirst = mktime(0,0,0,date('m'),01,date('Y'));

本日的SQL语句:

select order_amount from ecm_order where status=20 AND DATEDIFF(from_unixtime(add_time),'".$nowtime."')=0


本周的SQL语句:

select order_amount from ecm_order where status=20 AND ".$weekfirst." <= add_time AND add_time <= ".$time."


本月的SQL语句:

select order_amount from ecm_order where status=20 AND  ".$monthfirst." <= add_time AND add_time <= ".$time."



按月取数据的SQL语句:

SELECT DATE_FORMAT(from_unixtime(dateline),'%Y-%m') as s_date,SUM(saleamount) AS s_saleamount  FROM sale_record a LEFT JOIN area b ON a.salepointnum=b.salepointnum GROUP BY DATE_FORMAT(from_unixtime(dateline),'%Y-%m');



举报

相关推荐

0 条评论