Oracle 查询当天、当周、当月和当季度的所有记录
2011-12-17 23:38
471 查看
Oracle
字段类型为varchar2,格式要与格式化的样式匹配
当天
select * from 表名 where to_char(to_date(字段名,'yyyy-mm-dd hh24:mi:ss'),'dd')=to_char(sysdate,'dd')
当周
select * from 表名 where to_char(to_date(字段名,'yyyy-mm-dd hh24:mi:ss'),'iw')=to_char(sysdate,'iw')
当月
select * from 表名 where to_char(to_date(字段名,'yyyy-mm-dd hh24:mi:ss'),'mm')=to_char(sysdate,'mm')
当季度
select * from 表名 where to_char(to_date(字段名,'yyyy-mm-dd hh24:mi:ss'),'q')=to_char(sysdate,'q')
字段类型为date
当天
select * from 表名 where to_char(字段名,'dd')=to_char(sysdate,'dd')
当周
select * from 表名 where to_char(字段名,'iw')=to_char(sysdate,'iw')
当月
select * from 表名 where to_char(字段名,'mm')=to_char(sysdate,'mm')
当季度
select * from 表名 where to_char(字段名,'q')=to_char(sysdate,'q')
SQL
当天
select * from 表名 where DATEPART(dd,字段名) = DATEPART(dd, GETDATE()) and DATEPART(mm, 字段名) = DATEPART(mm, GETDATE()) and DATEPART(yy, 字段名) = DATEPART(yy, GETDATE())
当周
select * from 表名 where DATEPART(wk, 字段名) = DATEPART(wk, GETDATE()) and DATEPART(yy, 字段名) = DATEPART(yy, GETDATE())
当月
select * from 表名 where DATEPART(mm, 字段名) = DATEPART(mm, GETDATE()) and DATEPART(yy, 字段名) = DATEPART(yy, GETDATE())
当季度
select * from 表名 where DATEPART(qq, 字段名) = DATEPART(qq, GETDATE()) and DATEPART(yy,字段名) = DATEPART(yy, GETDATE())
字段类型为varchar2,格式要与格式化的样式匹配
当天
select * from 表名 where to_char(to_date(字段名,'yyyy-mm-dd hh24:mi:ss'),'dd')=to_char(sysdate,'dd')
当周
select * from 表名 where to_char(to_date(字段名,'yyyy-mm-dd hh24:mi:ss'),'iw')=to_char(sysdate,'iw')
当月
select * from 表名 where to_char(to_date(字段名,'yyyy-mm-dd hh24:mi:ss'),'mm')=to_char(sysdate,'mm')
当季度
select * from 表名 where to_char(to_date(字段名,'yyyy-mm-dd hh24:mi:ss'),'q')=to_char(sysdate,'q')
字段类型为date
当天
select * from 表名 where to_char(字段名,'dd')=to_char(sysdate,'dd')
当周
select * from 表名 where to_char(字段名,'iw')=to_char(sysdate,'iw')
当月
select * from 表名 where to_char(字段名,'mm')=to_char(sysdate,'mm')
当季度
select * from 表名 where to_char(字段名,'q')=to_char(sysdate,'q')
SQL
当天
select * from 表名 where DATEPART(dd,字段名) = DATEPART(dd, GETDATE()) and DATEPART(mm, 字段名) = DATEPART(mm, GETDATE()) and DATEPART(yy, 字段名) = DATEPART(yy, GETDATE())
当周
select * from 表名 where DATEPART(wk, 字段名) = DATEPART(wk, GETDATE()) and DATEPART(yy, 字段名) = DATEPART(yy, GETDATE())
当月
select * from 表名 where DATEPART(mm, 字段名) = DATEPART(mm, GETDATE()) and DATEPART(yy, 字段名) = DATEPART(yy, GETDATE())
当季度
select * from 表名 where DATEPART(qq, 字段名) = DATEPART(qq, GETDATE()) and DATEPART(yy,字段名) = DATEPART(yy, GETDATE())
相关文章推荐
- Oracle 查询当天、当周、当月和当季度的所有记录
- oracle 查询当天、当月、当年范围的记录
- Oracle 查询今天、昨日、本周、本月和本季度的所有记录
- Oracle 查询今日、昨日、本周、本月和本季度的所有记录
- Oracle 查询今天、昨日、本周、本月和本季度的所有记录
- Oracle 查询今天、昨日、本周、本月和本季度的所有记录
- Oracle查询数据库中所有表的记录数
- mysql 查询当天当周当月的数据
- oracle查询所有表的表名+注释+记录数
- Oracle查询数据库中所有表的记录数
- Oracle_查询当天记录 三种方法效率比较
- Oracle 数据库下 查询当前用户下所有表的记录总数
- oracle中查询所有外键引用到某张表的记录
- Oracle生成查询包含指定字段名对应的所有数据表记录语句
- oracle查询所有表的记录数SQL
- 查询当天 当月 当年的记录
- Oracle生成查询包括对应于所有数据表记录语句中指定的字段名
- mysql 关于limit 子查询和获取某当天所有记录
- Oracle生成查询包含指定字段名对应的所有数据表记录语句
- sql 查询 当天 当月 上月 记录