SQL数据库中如何筛选某一个表中的时间字段的范围

例如:表a中的datetime字段都是‘2013-05-11 13:10:00‘这种格式的我想筛选其中8:00到10:00之间的如何做
补充:前面的年月日可能不一样

例如:表a中的datetime字段都是‘2013-05-11 13:10:00‘这种格式的,筛选其中8:00到10:00之间的。

select * from 表a
where substring(convert(varchar,字段名,120),12,8) between '08:00:00' and '10:00:00'

怎么利用SQL语句查询数据库中具体某个字段的重复行?

可用group by……having来实现。

可做如下测试:

1、创建表插入数据:

create table test

(id int,name varchar(10))

insert into test values (1,'张三')

insert into test values (2,'李四')

insert into test values (3,'张三')

insert into test values (4,'王五')

insert into test values (5,'赵六')其中name是张三的有两行,也就是重复行。

2、执行sql语句如下:

select * from test where name in 

(select name from test group by name having COUNT(*)>1)

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-11-25
select * from 表a
where substring(convert(varchar,字段名,120),12,8) between '08:00:00' and '10:00:00'

试试这样,看看结果对不本回答被提问者采纳
第2个回答  2013-05-23
SQL2005
数据表数据
b_1 b_2(datetime)
1 2013-05-23 10:44:46.780
2 2013-05-23 10:44:48.090
3 2013-05-23 10:44:49.857
4 2013-05-23 10:44:50.700

select b_1,b_2 from bb where b_2>'2013-05-23 10:40:45' and b_2<'2013-05-23 10:44:50'

查询结果:
b_1 b_2
1 2013-05-23 10:44:46.780
2 2013-05-23 10:44:48.090
3 2013-05-23 10:44:49.857
第3个回答  2013-05-23
首先 把所有的 转换成 日期类型,之后用日期 所对应的函数,BETWEEN AND 即可
第4个回答  2013-05-23
select * from a where datedepart(hh,datetime)>=8 and datedepart(hh,datetime)<10追问

我想到的也是这样但是这样不能精确到分钟!同样也谢谢你!