±íA
declare @a table (a_xm varchar(6),a_time varchar(5),a_log varchar(1),a_rs int,a_ys int)
insert into @a
select 'ÕÅÈý','06:00','q',1,7 union all
select 'ÕÅÈý','07:00','f',2,8 union all
select 'ÕÅÈý','08:00','q',3,9 union all
select 'ÕÅÈý','09:00','f',3,10 union all
select 'ÀîËÄ','08:00','q',5,11 union all
select 'ÀîËÄ','19:00','f',6,12 union all
select 'ÍõÎå','06:00','q',7,8 union all
select 'ÍõÎå','07:00','f',8,9
select a_xm,
max(case (px - 1)%2 when 0 then a_time end) a_time1,
max(case (px - 1)%2 when 1 then a_time end) a_time2,
sum(a_rs) a_rs,
sum(a_ys) a_ys
from
(
select * , px = (select count(1) from @a n where a_xm = m.a_xm and n.a_time < m.a_time) + 1 from @a m
) m
group by a_xm , (px - 1) / 2
½á¹ûΪ£º
a_xm a_time1 a_time2 a_rs a_ys
ÀîËÄ 08:00 19:00 11 23
ÍõÎå 06:00 07:00 15 17
ÕÅÈý 06:00 07:00 3 15
ÕÅÈý 08:00 09:00 6 19
-------------------------------------------------------------------
ÎÒÓжà¸ö±íA B C ½á¹¹ÊÇÒ»ÑùµÄ£¬¶¼ÓÐ2¸ö×Ö¶ÎnameºÍcontent,ÎÒÒªËÑË÷ËùÒÔ±íËùÓÐ×Ö¶ÎÖаüº¬¡°Öйú¡±µÄÄÚÈÝ Õâ¸öSQLÓï¾äÔõôд
ÈçºÎ½«¶à¸ö±íµÄ²éѯ½á¹ûÁ¬³ÉÒ»¸ö±í Õâ¸öSQLÓï¾äÔõôд ±íµÄ½á¹¹ÊÇÒ»ÑùµÄ
ÀýÈç£ ......
ÇëÎÊһϣ¬ÍâÍøÁ½Ì¨SQLSERVERʵÀýÊý¾Ý´«Ê䣬ÓÐûÓвÉÓÃÊý¾ÝѹËõºÍ¼ÓÃÜ¡£Ñ¹Ëõ±ÈÊǶàÉÙ£¬¼ÓÃÜÊÇʲô¼ÓÃÜËã·¨£¿Ïà¹ØÎĵµÄÄÀï¿ÉÒÔÕÒµ½£¿Ð»Ð»
ÎÒÒ²ÏëÖªµÀ£¡¹Ø×¢´ËÌù£¡
¹Ø×¢¡«¡«
Êý¾Ý¿â´óÅ£¶¼ÄÄÈ¥Á˰¡£¿
......