================================
日期(号) 0:00 2:00 2:00 4:00.............. 日统计
1
2
3
4
5
6
7
8
9
...
问题如下:
在线用户统计问题:
现有一张表A,里面有字段logintime,expirce(秒).
我要判断在线用户在哪个时间段登陆的人的总数,而且还要判断出这个用户是在几号登陆的就放在那个日期的一行里.我想的头都暴了,就是没想出来?
求给位大哥帮忙啊!!!!!!!!
------解决方案--------------------------------------------------------
这个是数据库查询问题吧,不关DataGird的问题
先帮你顶一下。
------解决方案--------------------------------------------------------
SELECT t.f_bjhtxxbh, sum(to_char(F_KSRQ, 'hh ')) Hour,
sum(to_char(F_KSRQ, 'ss ')) Minment
FROM TB_GG_BJHTXX t group by f_bjhtxxbh
------解决方案--------------------------------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N '[dbo].[userLogInfo] ') and OBJECTPROPERTY(id, N 'IsUserTable ') = 1)
drop table [dbo].[userLogInfo]
GO
建立表
CREATE TABLE [dbo].[userLogInfo] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[name] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[loginTime] [datetime] NOT NULL ,
[logoutTime] [datetime] NOT NULL
) ON [PRIMARY]
GO
插入事例数据
declare @timeSpan int
set @timeSpan=10--10表示10s,单位是秒
declare @i int
set @i=1
while @i <20
begin
insert userLogInfo (name,loginTime,logoutTime)
select 'nayc '+cast(@i as varchar),dateAdd(second,@i,getdate()),dateAdd(minute,@timeSpan+@i,getdate())
set @i=@i+1
end
查询sql语句
select [name],
cast(dateDiff(year,loginTime,logoutTime) as varchar) + '年 '+
cast(dateDiff(month,loginTime,logoutTime) as varchar) + '月 '+
cast(dateDiff(day,loginTime,logoutTime) as varchar) + '日 '+
cast(dateDiff(hour,loginTime,logoutTime) as varchar) + '时 '+
cast(dateDiff(minute,loginTime,logoutTime) as varchar) + '分 '+
cast(dateDiff(second,loginTime,logoutTime) as varchar) + '秒 '
as 登陆时间间隔
from userLogInfo
------解决方案--------------------------------------------------------
比如在某一天在 下午 2:00 到4:00之间登陆的人数
select cout(id) from userLogInfo where loginTime > dateAdd(hour,2,getdate()) and loginTime <dateAdd(hour,4,getdate())
------解决方案--------------------------------------------------------
select 2:00=case dt between 2:00 and 2:59 then 1 else 0...