查询前一天数据及时间统一
mysql
1. 前一天日期格式化:SELECT date_sub(curdate(),interval 1 day) , curdate()
2. 时间格式化:SELECT DATE_FORMAT(CURDATE(),'%Y-%m-%d')
3. 离散时间按天选取:order_time BETWEEN date_sub(curdate(),interval 7 day) AND curdate()
- curdate()=2018-02-18 为 2018-02-18 00:00:00,不包含当天数据`
sqlserver
1. 整除四舍五入:SELECT round(1.0*56/100,2)
2. 前一天日期格式化:SELECT convert(varchar(100),dateadd(day,-1,getdate()),23),getdate()
3. 离散时间按天选取,最近7天:SELECT convert(varchar(100),dateadd(day,-7,getdate()),23),convert(varchar(100),dateadd(day,0,getdate()),23)
oracle
SELECT to_date(to_char(sysdate-1,'yyyy-mm-dd'),'yyyy-mm-dd')
SELECT to_char(sysdate-1,'yyyy-mm-dd')
postgre
select date(now()),to_char(now()-interval'1 year','yyyy-mm'),
to_char(now()-interval'1 month','yyyy-mm'),to_char(now()-interval'1 day','yyyy-mm')