根据“起始日期”和“截止日期”,SQL语句应该怎样写

zhanghaojiefeng 2011-10-29 12:17:50
根据“起始日期”和“截止日期”来查询一个字段“RQ”,这个应该怎样写???

好像是“between and” ,要和“ where XM="????" ”这样的条件组合起来,“between and”是不是要用“()”扩起来???
...全文
518 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
zzccjj11 2011-10-31
  • 打赏
  • 举报
回复
学习了
houyajin 2011-10-31
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 dawugui 的回复:]

引用楼主 zhanghaojiefeng 的回复:
根据“起始日期”和“截止日期”来查询一个字段“RQ”,这个应该怎样写???

好像是“between and” ,要和“ where XM="????" ”这样的条件组合起来,“between and”是不是要用“()”扩起来???

select * from tb where 日期字段 between '起始日期' and '截止……
[/Quote]

++
blackwolves 2011-10-31
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 dawugui 的回复:]
引用楼主 zhanghaojiefeng 的回复:
根据“起始日期”和“截止日期”来查询一个字段“RQ”,这个应该怎样写???

好像是“between and” ,要和“ where XM="????" ”这样的条件组合起来,“between and”是不是要用“()”扩起来???

select * from tb where 日期字段 between '起始日期' and '截止日……
[/Quote]

++
lantian_019 2011-10-31
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 dawugui 的回复:]
引用楼主 zhanghaojiefeng 的回复:
根据“起始日期”和“截止日期”来查询一个字段“RQ”,这个应该怎样写???

好像是“between and” ,要和“ where XM="????" ”这样的条件组合起来,“between and”是不是要用“()”扩起来???

select * from tb where 日期字段 between '起始日期' and '截止日……
[/Quote]
正解
bushy 2011-10-30
  • 打赏
  • 举报
回复
select * from tb where 日期字段 (between '起始日期' and '截止日期)
or (between '起始日期2' and '截止日期2)
or (between '起始日期3' and '截止日期3)

select * from tb where datepart(hh,日期字段 )between 0 and 23
select * from tb where datepart(yy,日期字段) between 1 and 12

dendenge
中国风 2011-10-30
  • 打赏
  • 举报
回复
不需要括号

可有多个or+and条件时需要加
starrycheng 2011-10-30
  • 打赏
  • 举报
回复
select * from tb where 日期字段 between '起始日期' and '截止日期'
select * from tb where 日期字段 between '起始日期' and '截止日期' and XM = '????'
select * from tb where 日期字段 >= '起始日期' and 日期字段 <= '截止日期'
select * from tb where 日期字段 >= '起始日期' and 日期字段 <= '截止日期' and XM = '????'

好经典。
-晴天 2011-10-29
  • 打赏
  • 举报
回复
select * from tb where RQ between startdate and enddate
dawugui 2011-10-29
  • 打赏
  • 举报
回复
[Quote=引用楼主 zhanghaojiefeng 的回复:]
根据“起始日期”和“截止日期”来查询一个字段“RQ”,这个应该怎样写???

好像是“between and” ,要和“ where XM="????" ”这样的条件组合起来,“between and”是不是要用“()”扩起来???
[/Quote]
select * from tb where 日期字段 between '起始日期' and '截止日期'
select * from tb where 日期字段 between '起始日期' and '截止日期' and XM = '????'
select * from tb where 日期字段 >= '起始日期' and 日期字段 <= '截止日期'
select * from tb where 日期字段 >= '起始日期' and 日期字段 <= '截止日期' and XM = '????'
快溜 2011-10-29
  • 打赏
  • 举报
回复
select * from where XM='???' and RQ between 起始日期 and 截止日期
xiaohei0491 2011-10-29
  • 打赏
  • 举报
回复
select * from tb where 日期字段 between '起始日期' and '截止日期'
select * from tb where 日期字段 >= '起始日期' and 日期字段 <= '截止日期'
如果你测试的话, 这两句得出的结果是不一样的。上一句会少一些。
--小F-- 2011-10-29
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 dawugui 的回复:]
引用楼主 zhanghaojiefeng 的回复:
根据“起始日期”和“截止日期”来查询一个字段“RQ”,这个应该怎样写???

好像是“between and” ,要和“ where XM="????" ”这样的条件组合起来,“between and”是不是要用“()”扩起来???

select * from tb where 日期字段 between '起始日期' and '截止日……
[/Quote]
全被写光了
dusttosky 2011-10-29
  • 打赏
  • 举报
回复
select * from tb where RQ between 开始日期 and 结束日期
zhanghaojiefeng 2011-10-29
  • 打赏
  • 举报
回复
谢谢大家。

34,590

社区成员

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

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