sql时间查询

#当天的

select count(id), SUM(balance) from tb_app_user where to_days(create_time) = to_days(now())

#昨天的

SELECT count(id), SUM(balance) FROM tb_app_user WHERE TO_DAYS( NOW( ) ) - TO_DAYS( create_time) =1

#本月的

SELECT count(id), SUM(balance) FROM tb_app_user WHERE DATE_FORMAT( create_time, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )

#上月的

SELECT count(id)AS number, SUM(payment_price) AS order_amount FROM tb_commodity_order WHERE PERIOD_DIFF( date_format( now( ) , '%Y%m' ) , date_format( create_time, '%Y%m' ) ) =1  AND order_type=2

你可能感兴趣的:(sql时间查询)