日期:2014-05-18 浏览次数:20636 次
create table tb(Person_No varchar(10),A1 int,A2 int,B1 int,B2 int,B3 int,Check_Name_No varchar(10),Business_No int)
insert into tb values('26001', 8, 8, 8, 8, 8, '26004', 1)
insert into tb values('26002', 8, 8, 8, 8, 8, '26004', 1)
insert into tb values('26001', 8, 8, 8, 8, 8, '26005', 1)
insert into tb values('26002', 8, 8, 8, 8, 8, '26005', 1)
insert into tb values('26001', 8, 8, 8, 8, 8, '26006', 3)
insert into tb values('26002', 8, 8, 8, 8, 8, '26006', 3)
insert into tb values('26001', 8, 8, 8, 8, 8, '26007', 3)
insert into tb values('26002', 8, 8, 8, 8, 8, '26007', 3)
insert into tb values('26001', 8, 8, 8, 8, 8, '26008', 4)
insert into tb values('26002', 8, 8, 8, 8, 8, '26008', 4)
go
select m.Person_No ,
max(case m.Business_No when 1 then (a1+a2+b1+b2+b3)*0.4/n.person_num else 0 end) '1',
max(case m.Business_No when 3 then (a1+a2+b1+b2+b3)*0.3/n.person_num else 0 end) '3',
max(case m.Business_No when 4 then (a1+a2+b1+b2+b3)*0.3/n.person_num else 0 end) '4'
from tb m,(select Person_No , sum(a1+a2+b1+b2+b3) person_num from tb group by Person_No) n
where m.Person_No = n.Person_No
group by m.Person_No
drop table tb
/*
Person_No 1 3 4
---------- ------------------------- ------------------------- -------------------------
26001 .080000000000 .060000000000 .060000000000
26002 .080000000000 .060000000000 .060000000000
(所影响的行数为 2 行)
*/