日報(bào)數(shù)據(jù)統(tǒng)計(jì)中會(huì)用到當(dāng)天數(shù)據(jù)的查詢,下列就是日期要對應(yīng)的條件:
between
to_date(to_char(sysdate,'yyyy-mm-dd') || ' 00:00:01','yyyy-mm-dd hh24:mi:ss') and
to_date(to_char(sysdate,'yyyy-mm-dd') || ' 23:59:59','yyyy-mm-dd hh24:mi:ss');
Oracle
字段類型為varchar2,格式要與格式化的樣式匹配
當(dāng)天
select * from 表名 where to_char(to_date(字段名,'yyyy-mm-dd hh24:mi:ss'),'dd')=to_char(sysdate,'dd')
當(dāng)周
select * from 表名 where to_char(to_date(字段名,'yyyy-mm-dd hh24:mi:ss'),'iw')=to_char(sysdate,'iw')
當(dāng)月
select * from 表名 where to_char(to_date(字段名,'yyyy-mm-dd hh24:mi:ss'),'mm')=to_char(sysdate,'mm')
當(dāng)季度
select * from 表名 where to_char(to_date(字段名,'yyyy-mm-dd hh24:mi:ss'),'q')=to_char(sysdate,'q')
字段類型為date
當(dāng)天
select * from 表名 where to_char(字段名,'dd')=to_char(sysdate,'dd')
當(dāng)周
select * from 表名 where to_char(字段名,'iw')=to_char(sysdate,'iw')
當(dāng)月
select * from 表名 where to_char(字段名,'mm')=to_char(sysdate,'mm')
當(dāng)季度
select * from 表名 where to_char(字段名,'q')=to_char(sysdate,'q')
SQL
當(dāng)天
select * from 表名 where DATEPART(dd,字段名) = DATEPART(dd, GETDATE()) and DATEPART(mm, 字段名) = DATEPART(mm, GETDATE()) and DATEPART(yy, 字段名) = DATEPART(yy, GETDATE())
當(dāng)周
select * from 表名 where DATEPART(wk, 字段名) = DATEPART(wk, GETDATE()) and DATEPART(yy, 字段名) = DATEPART(yy, GETDATE())
當(dāng)月
select * from 表名 where DATEPART(mm, 字段名) = DATEPART(mm, GETDATE()) and DATEPART(yy, 字段名) = DATEPART(yy, GETDATE())
當(dāng)季度
select * from 表名 where DATEPART(qq, 字段名) = DATEPART(qq, GETDATE()) and DATEPART(yy,字段名) = DATEPART(yy, GETDATE())
您可能感興趣的文章:- oracle使用to_date查詢一周的第一天日期
- Oracle查詢最近幾天每小時(shí)歸檔日志產(chǎn)生數(shù)量的腳本寫法
- oracle實(shí)現(xiàn)按天,周,月,季度,年查詢排序方法
- Oracle 獲取上周一到周末日期的查詢sql語句
- Oracle中查詢本月星期5的所有日期列表的語句
- Oracle查詢優(yōu)化日期運(yùn)算實(shí)例詳解
- oracle查詢截至到當(dāng)前日期月份所在年份的所有月份
- Oracle實(shí)現(xiàn)查詢2個(gè)日期所跨過的月份列表/日期列表的方法分析
- oracle實(shí)現(xiàn)動(dòng)態(tài)查詢前一天早八點(diǎn)到當(dāng)天早八點(diǎn)的數(shù)據(jù)功能示例