赞
踩
SELECT IFNULL(SUM(p.settle_price),0) AS settlePrice,'本月' AS typeName
FROM package p
WHERE DATE_FORMAT( p.consume_time, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )
UNION
SELECT IFNULL(SUM(p.settle_price),0) AS settlePrice,'上月' AS typeName
FROM package p
WHERE PERIOD_DIFF( DATE_FORMAT( NOW( ) , '%Y%m' ) , DATE_FORMAT( p.consume_time, '%Y%m' ) ) =1
UNION
SELECT IFNULL(SUM(p.settle_price),0) AS settlePrice,'上上月' AS typeName
FROM package p
WHERE PERIOD_DIFF( DATE_FORMAT( NOW( ) , '%Y%m' ) , DATE_FORMAT( p.consume_time, '%Y%m' ) ) =2
<!-- 按日查询 --> SELECT DATE_FORMAT(created_date,'%Y-%m-%d') as time,sum(money) money FROM shpping_order where shop_id = 1000 GROUP BY time <!-- 按月查询 --> SELECT DATE_FORMAT(created_date,'%Y-%m') as time,sum(money) money FROM shpping_order where shop_id = 1000 GROUP BY time <!-- 按年查询 --> SELECT DATE_FORMAT(created_date,'%Y') as time,sum(money) money FROM shpping_order where shop_id = 1000 GROUP BY time <!-- 按周查询 --> SELECT DATE_FORMAT(created_date,'%Y-%u') as time,sum(money) money FROM shpping_order where shop_id = 1000 GROUP BY time
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。