sql中datetime日期类型字段比较(mysql&oracle)

mysql

可以直接用大于号,也可以用  between  and

SELECT * FROM users WHERE UPDATE_DATE >= '2021-08-12 11:22:09' AND UPDATE_DATE <= '2021-08-15 11:22:33';
 
SELECT * FROM users WHERE UPDATE_DATE BETWEEN '2021-08-12 11:22:09' AND '2021-08-15 11:22:33';


Oracle

oracle sql日期比较:


在今天之前:

select * from up_date where update < to_date('2021-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')
select * from up_date where update <= to_date('2021-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')


在今天只后:

select * from up_date where update > to_date('2022-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')
select * from up_date where update >= to_date('2022-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')


精确时间:

select * from up_date where update = to_date('2022-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')


在某段时间内:

select * from up_date where update between to_date('2022-07-07 00:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('2022-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')
select * from up_date where update < to_date('2022-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss') and update > to_date('2022-07-07 00:00:00','yyyy-mm-dd hh24:mi:ss')
select * from up_date where update <= to_date('2022-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss') and update >= to_date('2022-07-07 00:00:00','yyyy-mm-dd hh24:mi:ss')


上一篇:【蓝桥杯Java_C组·从零开始卷】第四节(附)、河图洛书【九宫格】(卷王必备,不想卷的略过,使用优化暴力破解,与网上莫名其妙的规律不一样)


下一篇:mysql.sock的作用