急。。。在线等候。。。高人帮忙

fifidog 2003-08-30 10:13:46
如何取一个表中从今天开始到前十五天的数据
select * from table where rq="?"取当天数据
select * from table where rq="?"取昨天天数据
。。。。。。
select * from table where rq="?"取天15天的数据

万分感谢。。谢谢
...全文
41 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
txlicenhe 2003-08-30
  • 打赏
  • 举报
回复
select * from table where datediff(day,rq,getdate())=0
select * from table where datediff(day,rq,getdate())=1
select * from table where datediff(day,rq,getdate())=15


select * from table where rq= getdate() --取当天数据
select * from table where rq=getdate() -1 --取昨天天数据
select * from table where rq=dateadd(day,-15,getdate()) --取昨天天数据
。。。。。。
select * from table where rq= dateadd(day,-15,getdate()) --取天15天的数据

以下为格式转换:

select CONVERT(varchar(10), getDate(),120) --不要时间2002-1-1
select convert(char(8),getdate(),112) ----20020101
select convert(char(8),getdate(),108) ---06:05:05

101 美国 mm/dd/yyyy
2 102 ANSI yy.mm.dd
3 103 英国/法国 dd/mm/yy
4 104 德国 dd.mm.yy
5 105 意大利 dd-mm-yy
6 106 - dd mon yy
7 107 - mon dd, yy
8 108 - hh:mm:ss
- 9 或 109 (*) 默认值 + 毫秒 mon dd yyyy hh:mi:ss:mmmAM(或 PM)
10 110 美国 mm-dd-yy
11 111 日本 yy/mm/dd
12 112 ISO yymmdd
- 13 或 113 (*) 欧洲默认值 + 毫秒 dd mon yyyy hh:mm:ss:mmm(24h)
14 114 - hh:mi:ss:mmm(24h)
- 20 或 120 (*) ODBC 规范 yyyy-mm-dd hh:mm:ss[.fff]
- 21 或 121 (*) ODBC 规范(带毫秒) yyyy-mm-dd hh:mm:ss[.fff]
- 126(***) ISO8601 yyyy-mm-dd Thh:mm:ss:mmm(不含空格)
- 130* 科威特 dd mon yyyy hh:mi:ss:mmmAM
- 131* 科威特 dd/mm/yy hh:mi:ss:mmmAM

yujohny 2003-08-30
  • 打赏
  • 举报
回复
SELECT * FROM TABLE WHERE DATEDIFF(DAY,rq,GETDATE())=0
SELECT * FROM TABLE WHERE DATEDIFF(DAY,rq,GETDATE())=1
SELECT * FROM TABLE WHERE DATEDIFF(DAY,rq,GETDATE())<=15
cdshelf 2003-08-30
  • 打赏
  • 举报
回复
select * from table where datediff(day,rq,getdate())<15 可以,但这条语句的效率会很低,因为在 where 表达式的左边使用函数会显著降低效率。最好是

select * from table where rq>=DateAdd(day,-15,GetDate()) and rq<=GetDate()
whaisheng 2003-08-30
  • 打赏
  • 举报
回复
select * from where date between getdate()-15 and getdate()
zclxyh 2003-08-30
  • 打赏
  • 举报
回复
select * from table where datediff(day,rq,getdate())<15 order by rq
yczzg 2003-08-30
  • 打赏
  • 举报
回复
select * from table where datediff(day,rq,getdate())<15
97866 2003-08-30
  • 打赏
  • 举报
回复
1,select * from table where Convert(varChar(10),rq,20)=Convert(varChar(10),GetDate(),20)

2,select * from table where Convert(varChar(10),rq,20)=Convert(varChar(10),DateAdd(d,-1,GetDate()),20)

3,select * from table where Convert(varChar(10),rq,20)<=Convert(varChar(10),GetDate(),20) and Convert(varChar(10),rq,20)>=Convert(varChar(10),DateAdd(d,-15,GetDate()),20)

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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