日期:2014-05-19  浏览次数:20487 次

关于日期与时间的查询问题
我的数据表如下:
id         indate                   intime             dd
1           2007-06-02           08:21:00         12
2           2007-03-21           09:25:10         32
3           2007-05-11           10:22:00         22
4           2007-06-08           11:33:22         126
5           2006-12-11           06:01:00         87
6           2007-02-30           12:13:05         45
7           2007-01-27           15:24:50         95
8           2006-07-22           18:01:40         76
9           2006-11-19           20:28:45         10
其中id、dd字段为int,indate、intime为varchar字段
请问两个查询语句:
1、查询indate字段中在2006-11-01至2007-03-31的数据
2、查询在intime字段中在08:00:00至12:00:00的数据

------解决方案--------------------

--1、查询indate字段中在2006-11-01至2007-03-31的数据
SELECT * FROM TABLENAME WHERE indate BETWEEN '2006-11-01 ' AND '2007-03-31 '
------解决方案--------------------
1、查询indate字段中在2006-11-01至2007-03-31的数据
2、查询在intime字段中在08:00:00至12:00:00的数据

1:
select * from 表 where indate between '2006-11-01 ' and '2007-03-31 '

2:
select * from 表 where intime between '08:00:00 ' and '12:00:00 '
------解决方案--------------------

--2、查询在intime字段中在08:00:00至12:00:00的数据
SELECT * FROM TABLENAME WHERE intime BETWEEN '08:00:00 ' AND '12:00:00 '