34,594
社区成员
发帖
与我相关
我的任务
分享
declare @tb table([id] int,[ip] varchar(9),[IP_datetime] datetime,[IP_url] varchar(49))
insert @tb
select 749,'127.0.0.1','2009-11-17 11:48:01.967','Index.aspx' union all
select 749,'127.0.0.1','2009-11-17 11:48:01.967','Index.aspx' union all
select 749,'127.0.0.1','2009-11-18 11:48:01.967','Index.aspx' union all
select 749,'127.0.0.2','2009-11-18 11:48:01.967','Index.aspx' union all
select 749,'127.0.0.2','2009-11-18 11:48:01.967','Index.aspx' union all
select 750,'127.0.0.2','2009-11-17 11:48:03.403','ChatRoom' union all
select 751,'127.0.0.4','2009-11-17 11:48:04.543','Task' union all
select 752,'127.0.0.2','2009-11-17 11:48:11.780','VFClassroom' union all
select 753,'127.0.0.4','2009-11-17 11:48:12.717','Game' union all
select 754,'127.0.0.3','2009-11-17 11:48:13.717','Zsy' union all
select 755,'127.0.0.1','2009-11-17 11:48:14.733','CoursewareManagement' union all
select 756,'127.0.0.2','2009-11-17 11:48:16.000','friend' union all
select 757,'127.0.0.5','2009-11-17 11:48:18.687','http://localhost:1147/ttxs/user/RefLog.aspx' union all
select 758,'127.0.0.6','2009-11-17 11:48:19.047','http://localhost:1147/ttxs/user/ValidateCode.aspx' union all
select 759,'127.0.0.1','2009-11-17 11:48:20.750','http://localhost:1147/ttxs/index.aspx' union all
select 760,'127.0.0.2','2009-11-17 11:48:22.530','friend' union all
select 761,'127.0.0.3','2009-11-17 11:48:23.937','VFClassroom' union all
select 762,'127.0.0.2','2009-11-17 11:48:25.043','Task' union all
select 763,'127.0.0.2','2009-11-17 11:48:27.750','ChatRoom' union all
select 764,'127.0.0.2','2009-11-17 11:48:29.357','http://localhost:1147/ttxs/about/help.aspx' union all
select 765,'127.0.0.3','2009-11-17 11:48:33.187','CoursewareManagement' union all
select 766,'127.0.0.3','2009-11-17 11:48:34.403','http://localhost:1147/ttxs/index.aspx'
select convert(varchar(10),IP_datetime,120) as fldDate,
T_index=sum(case when IP_url='Index.aspx' then ipcount else 0 end),
T_Chat=sum(case when IP_url='ChatRoom' then ipcount else 0 end),
T_task=sum(case when IP_url='Task' then ipcount else 0 end),
T_KL_room=sum(case when IP_url='KL_room' then ipcount else 0 end),
T_class_room=sum(case when IP_url='VFClassroom' then ipcount else 0 end),
T_game=sum(case when IP_url='Game' then ipcount else 0 end),
T_Course=sum(case when IP_url='CoursewareManagement' then ipcount else 0 end),
T_friend=sum(case when IP_url='friend' then ipcount else 0 end)
from (
select count(ip) as ipcount,IP_datetime, IP_url
from (
select distinct ip, convert(nvarchar, IP_datetime,111) as IP_datetime, IP_url
from @tb
) as a
group by IP_datetime, IP_url
) as b
group by convert(varchar(10),IP_datetime,120)
/*
fldDate T_index T_Chat T_task T_KL_room T_class_room T_game T_Course T_friend
---------- ----------- ----------- ----------- ----------- ------------ ----------- ----------- -----------
2009/11/17 1 1 2 0 2 1 2 1
2009/11/18 2 0 0 0 0 0 0 0
(所影响的行数为 2 行)
select
min(id) as id
,IP_datetime
,sum(case when IP_url = 'Index.aspx' then 1 else 0 end) as T_index
,sum(case when IP_url = 'ChatRoom' then 1 else 0 end) as T_chat
-- ... 其他类似
from IP_Liulang
group by IP_datetime
insert into IP_page(T_index,T_chat,T_task,T_KL_room,T_class_room,T_game,T_zsy,T_Course,T_friend,IP_datetime)
select
T_index=sum(case when IP_url='Index.aspx' then 1 else 0 end),
T_Chat=sum(case when IP_url='ChatRoom' then 1 else 0 end),
T_task=sum(case when IP_url='Task' then 1 else 0 end),
T_KL_room=sum(case when IP_url='KL_room' then 1 else 0 end),
T_class_room=sum(case when IP_url='Index.aspx' then 1 else 0 end),
T_game=sum(case when IP_url='Game' then 1 else 0 end),
T_Course=sum(case when IP_url='CoursewareManagement' then 1 else 0 end),
T_friend=sum(case when IP_url='friend' then 1 else 0 end),
convert(varchar(10),IP_datetime,120)
from IP_Liulang group by convert(varchar(10),IP_datetime,120)