求救SQL语句,在线等待

Amani 2002-06-28 07:07:22
比如一个数据表中其中有个字段是日期型StartTime
有一条记录的值为2002-6-28 12:00:00
用SQL语句查询出2002年5月的所有记录,
select * from User where后面怎么写
...全文
23 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
laoyang 2002-06-28
  • 打赏
  • 举报
回复
StartTime>='2002-05-1' and StartTime<'2002-06-01'
OpenVMS 2002-06-28
  • 打赏
  • 举报
回复
last 1 - 2 week

where datepart(ww,StartTime)>=datepart(ww,getdate())-2
and datepart(ww,StartTime)<=datepart(ww,getdate())-1
Amani 2002-06-28
  • 打赏
  • 举报
回复
得到上一周,上两周,怎么写才行
billyliu 2002-06-28
  • 打赏
  • 举报
回复
select * from User where to_char(startTime,'YYYY-MM-DD HH24:MI:SS')>'2002-6-22 00:00:00'
上周的, sorry
OpenVMS 2002-06-28
  • 打赏
  • 举报
回复
last week:
where datepart(ww,StartTime)=datepart(ww,getdate())-1
billyliu 2002-06-28
  • 打赏
  • 举报
回复
比如一个数据表中其中有个字段是日期型StartTime
有一条记录的值为2002-6-28 12:00:00
用SQL语句查询出2002年5月的所有记录,
select * from User where to_char(startTime,'YYYY-MM-DD HH24:MI:SS')>'2002-6-22 00:00:00'
foolishchao 2002-06-28
  • 打赏
  • 举报
回复
to 空空大师:
应为char(7)
CONVERT (char(7), StartTime, 20)='2002-05'


StartTime>='2002-05-1' and StartTime<'2002-06-01'
OpenVMS 2002-06-28
  • 打赏
  • 举报
回复
where year(StartTime)=2002 and month(StartTime)=5
Amani 2002-06-28
  • 打赏
  • 举报
回复
还有比如我要查上一周的记录,又该如何写
OpenVMS 2002-06-28
  • 打赏
  • 举报
回复
where month(StartTime)=5
nononono 2002-06-28
  • 打赏
  • 举报
回复
DATEPART(year, StartTime)=2002 and DATEPART(month, StartTime)=5



CONVERT (char(6), StartTime, 20)='2002-05'

34,594

社区成员

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

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