比如 我要查询 上网时间在9点到15点内 上网的用户 上机时间 是从会员资料 表里导入的 下机时间是从 会员下机资料 表里导入的
with query1 do begin
Close;
SQL.Clear;
SQL.Add('select COUNT(会员帐号) as identity(int,0,1) as 上机人数 from 会员下机资料,会员资料 where 会员资料.会员帐号=会员下机资料.会员帐号 and DATEPART(Hour,上机时间) > 9 and DATEPART(Hour,下机时间) <15 '); select COUNT(会员帐号) as 上机人数 from 会员下机资料,会员资料 where 会员资料.会员帐号=会员下机资料.会员帐号 and 上机时间 >= '2008-05-14 09:00:00' and 下机时间 < '2008-05-14 15:00:00'也不行
如上的 SQL 代码 还要如何改进 才能查询出结果!
谢谢了朋友门了,帮忙解决下!非常感谢!
with query1 do begin
Close;
SQL.Clear;
SQL.Add('select COUNT(会员帐号) as identity(int,0,1) as 上机人数 from 会员下机资料,会员资料 where 会员资料.会员帐号=会员下机资料.会员帐号 and DATEPART(Hour,上机时间) > 9 and DATEPART(Hour,下机时间) <15 '); select COUNT(会员帐号) as 上机人数 from 会员下机资料,会员资料 where 会员资料.会员帐号=会员下机资料.会员帐号 and 上机时间 >= '2008-05-14 09:00:00' and 下机时间 < '2008-05-14 15:00:00'也不行
如上的 SQL 代码 还要如何改进 才能查询出结果!
谢谢了朋友门了,帮忙解决下!非常感谢!
--try
select rkrq from tb where rkrq between '2006-01-07 09:00:00.000'and '2006-01-07 15:00:00.000'
--result
/*
rkrq
2006-01-07 09:22:17.700
2006-01-07 09:23:52.000
2006-01-07 09:24:23.327
2006-01-07 09:24:56.030
2006-01-07 09:58:54.170
2006-01-07 10:34:50.920
2006-01-07 11:09:53.983
2006-01-07 14:26:12.653
2006-01-07 14:49:35.403
2006-01-07 13:40:13.060
2006-01-07 09:24:11.937
2006-01-07 14:29:03.357*/
create table tb(rkrq datetime)
insert into tb select '2006-01-07 06:22:17.700'
insert into tb select'2006-01-07 09:22:17.700'
insert into tb select'2006-01-07 09:23:52.000'
insert into tb select'2006-01-07 09:24:23.327'
insert into tb select'2006-01-07 09:24:56.030'
insert into tb select'2006-01-07 09:58:54.170'
insert into tb select'2006-01-07 10:34:50.920'
insert into tb select'2006-01-07 11:09:53.983'
insert into tb select'2006-01-07 14:26:12.653'
insert into tb select'2006-01-07 14:49:35.403'
insert into tb select'2006-01-07 13:40:13.060'
insert into tb select'2006-01-07 09:24:11.937'
insert into tb select'2006-01-07 14:29:03.357'select rkrq from tb where rkrq between '2006-01-07 09:00:00.000'and '2006-01-07 15:00:00.000'
--result
/*
rkrq
2006-01-07 09:22:17.700
2006-01-07 09:23:52.000
2006-01-07 09:24:23.327
2006-01-07 09:24:56.030
2006-01-07 09:58:54.170
2006-01-07 10:34:50.920
2006-01-07 11:09:53.983
2006-01-07 14:26:12.653
2006-01-07 14:49:35.403
2006-01-07 13:40:13.060
2006-01-07 09:24:11.937
2006-01-07 14:29:03.357*/
from 会员下机资料 a inner join 会员资料 b
on a.会员帐号=b.会员帐号
where a.上机时间 >= '2008-05-14 09:00:00'
and a.下机时间 < '2008-05-14 15:00:00'