求一句SQL2000语句 可能我表达不好 在这里重新讲下

luofenghen 2011-03-16 03:50:32


我需要查询出 start_time 为 2011-03-03 00:00:00 end_time 为 2011-03-15 00:00:00
的这条记录

查询条件为 大于 '2011/3/5 0:00:00' 和 小于 '2011/3/10 0:00:00'
请问这句SQL 语句应该怎么写
如我上图的方法是行不通的
...全文
112 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
luofenghen 2011-03-16
  • 打赏
  • 举报
回复
已经结了呢 你分特别多 几分到没仔细算
快溜 2011-03-16
  • 打赏
  • 举报
回复
你可以结贴了,发那么多就为一个问题。
luofenghen 2011-03-16
  • 打赏
  • 举报
回复
select * from  TB where (start_date between '2011/3/5 0:00:00' and '2011/3/10 0:00:00')
or (end_date between '2011/3/5 0:00:00' and '2011/3/10 0:00:00')
or ('2011/3/5 0:00:00' between start_date and end_date)
or ( '2011/3/10 0:00:00' between start_date and end_date)
luofenghen 2011-03-16
  • 打赏
  • 举报
回复
神啊 14楼对了 谢了
bala7229291 2011-03-16
  • 打赏
  • 举报
回复
select *
from tb
where start_time >= '2011/3/5 0:00:00' and
end_time <''2011/3/10 0:00:00'

难道这样不行,为什么?
cutebear2008 2011-03-16
  • 打赏
  • 举报
回复
哥哥你还是没讲清楚啊!
查询条件为 大于 '2011/3/5 0:00:00' 和 小于 '2011/3/10 0:00:00'
哪个字段啊!

救命啊!
救命啊!
救命啊!
救命啊!
杀人啦!
快溜 2011-03-16
  • 打赏
  • 举报
回复
select * from  tb where (start_time between '2011/3/5 0:00:00' and '2011/3/10 0:00:00'
and end_time between '2011/3/5 0:00:00' and '2011/3/10 0:00:00')
or ('2011/3/5 0:00:00' between start_time and end_time
and '2011/3/10 0:00:00' between start_time and end_time)
AcHerat 2011-03-16
  • 打赏
  • 举报
回复
select top 1 * from tb where start_time < '2011/3/5 0:00:00' order by start_time desc
luofenghen 2011-03-16
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 bluesmiler 的回复:]
按你结果来看属于当@start_date <='2011/3/5' @end_date>='2011/3/10'条件
select * from tb where start_date <='2011-03-05' and end_date >='2011-03-10'
[/Quote]
这个我试了 查不出 第一条记录的
luofenghen 2011-03-16
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 ssp2009 的回复:]
引用 4 楼 luofenghen 的回复:
start_date 和 end_date 在 时间段内的都算 都要查出来

select * from tb where start_time between '2011/3/5 0:00:00' and '2011/3/10 0:00:00'
or end_time between '2011/3/5 0:00:00' and '201……
[/Quote]
我已经在 图片里的查询试了~ 不行的
快溜 2011-03-16
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 luofenghen 的回复:]
start_date 和 end_date 在 时间段内的都算 都要查出来
[/Quote]
select * from tb where start_time between '2011/3/5 0:00:00' and '2011/3/10 0:00:00'
or end_time between '2011/3/5 0:00:00' and '2011/3/10 0:00:00'
这个呢?
bluesmiler 2011-03-16
  • 打赏
  • 举报
回复
按你结果来看属于当@start_date <='2011/3/5' @end_date>='2011/3/10'条件
select * from tb where start_date <='2011-03-05' and end_date >='2011-03-10'
luofenghen 2011-03-16
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 fredrickhu 的回复:]
救命..
[/Quote]
救命..
救命..
救命..
luofenghen 2011-03-16
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 acherat 的回复:]
select *
from tb
where start_time = (select top 1 start_time from tb where start_time between '2011/3/1' and '2011/3/10')
and end_time = (select top 1 end_time from tb where start_time between '……
[/Quote]
..............我很无语 ~
luofenghen 2011-03-16
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 ssp2009 的回复:]
SQL code
select * from tb where start_time between '2011/3/5 0:00:00' and '2011/3/10 0:00:00'
and end_time between '2011/3/5 0:00:00' and '2011/3/10 0:00:00'
[/Quote]
..............我很无语 ~
AcHerat 2011-03-16
  • 打赏
  • 举报
回复
select *
from tb
where start_time = (select top 1 start_time from tb where start_time between '2011/3/1' and '2011/3/10')
and end_time = (select top 1 end_time from tb where start_time between '2011/3/1' and '2011/3/10')
luofenghen 2011-03-16
  • 打赏
  • 举报
回复
start_date 和 end_date 在 时间段内的都算 都要查出来
快溜 2011-03-16
  • 打赏
  • 举报
回复
select * from  tb where start_time between '2011/3/5 0:00:00' and '2011/3/10 0:00:00'
and end_time between '2011/3/5 0:00:00' and '2011/3/10 0:00:00'
bluesmiler 2011-03-16
  • 打赏
  • 举报
回复
看出来了。区间为:start_date between '2011/3/1' and '2011/3/10'
当@start_date <='2011/3/1' 且 @end_date落于区间'2011/3/1' and '2011/3/10' 算符合条件吗?
当@start_date 落于区间 且@end_date落于区间算符合条件吗?
当@start_date 落于区间 且@end_date>='2011/3/10'算符合条件吗?
当@start_date <='2011/3/1' @end_date>='2011/3/10'算符合条件吗?
请针对上述4种组合给出为真,就有sql语句了

22,210

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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