求一条SQL语句?查询当天、一周或一个月内的数据?

tang1114 2010-07-20 01:19:54
oracle中有没有什么函数可以查询当天、一周和一个月的数据
a表中的一个字段generateTime(写入数据库时间,DATE类型),现在想根据generateTime分别查询当天、一个星期、一个月的数据,请问SQL语句该怎么写?谢谢...
...全文
3873 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
seekeyl 2012-08-24
  • 打赏
  • 举报
回复
Select * From agent_calu a Where trunc(create_date) = trunc(Sysdate);
如果create_date有索引的话,可以用吗?
xxiangyuan 2012-04-27
  • 打赏
  • 举报
回复
九楼的可以实现
haoran_521 2011-06-30
  • 打赏
  • 举报
回复
4楼正解!~
gisinfo 2010-07-21
  • 打赏
  • 举报
回复
搜索时间处理函数(oracle)
malun666 2010-07-21
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zhuomingwang 的回复:]

SQL code
--查询当天的数据
select * from a where generateTime=sysdate
--查询一个星期的数据
select * from a where (sysdate-generaeTime)=7
--查询一个月的数据
select * from a where months_between(sysdate,generateTime)=1
[/Quote]

9楼的也可以。呵呵,学了不少
minitoy 2010-07-20
  • 打赏
  • 举报
回复
楼上的正确
jjaihua 2010-07-20
  • 打赏
  • 举报
回复
当天
Select * From agent_calu a Where trunc(create_date)
= trunc(Sysdate); (借5楼)

当月的

Select * From agent_calu a Where to_char(create_date,'yyyymm')
= to_char(Sysdate,'yyyymm');

当星期的
trunc(Sysdate,'d')这是这个星期的第一天。
Next_day(trunc(sysdate,'d'),7) 这是这个星期的最后天。
Select * From agent_calu a Where trunc(create_date)>=trunc(Sysdate,'d')
AND trunc(create_date)<= Next_day(trunc(sysdate,'d'),7)
licelandray 2010-07-20
  • 打赏
  • 举报
回复
取一个星期的怎么取的 就是不管当前是星期几 取的都是这一个星期的数据 不带上个星期的

logdate >=to_char(sysdate-7,'yyyy-mm-dd') and logdate<=to_char(sysdate,'yyyy-mm-dd')
这样不行。。取的有上个星期的
huhuhelen 2010-07-20
  • 打赏
  • 举报
回复
我还没学到这个呢~~~~~~~~~~~~
zhizhuo89 2010-07-20
  • 打赏
  • 举报
回复
Select * From agent_calu a Where to_char(trunc(create_date),'yyyymm')
= to_char(trunc(Sysdate),'yyyymm');

当月的
zhizhuo89 2010-07-20
  • 打赏
  • 举报
回复
Select * From agent_calu a Where trunc(create_date)
= trunc(Sysdate);

当天的
  • 打赏
  • 举报
回复
--查询当天的数据
select * from a where generateTime=sysdate
--查询一个星期的数据
select * from a where (sysdate-generaeTime)=7
--查询一个月的数据
select * from a where months_between(sysdate,generateTime)=1
chens_1218 2010-07-20
  • 打赏
  • 举报
回复
恩,自己去写个函数就可以了,顶3楼
luoyoumou 2010-07-20
  • 打赏
  • 举报
回复
-- 可以按自己的需求去创建这个函数............
chens_1218 2010-07-20
  • 打赏
  • 举报
回复
select sysdate from dual;取当前日期
select extract(month from sysdate) from dual;取当前月
至于星期还真不知道怎么去取

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧