create table #(id int,vote int)
insert into # values(44,-2)
insert into # values(51,-3)
insert into # values(51,1)
insert into # values(52,-1)
select id,max(case when vote<0 then vote else null end) as '-vote',max(case when vote>0 then vote else null end) as '+vote' from # group by id
id -vote +vote
----------- ----------- -----------
44 -2 NULL
51 -3 1
52 -1 NULL
警告: 聚合或其他 SET 操作消除了空值。
(3 行受影响)
insert into # values(44,-2)
insert into # values(51,-3)
insert into # values(51,1)
insert into # values(52,-1)
select id,max(case when vote<0 then vote else null end) as '-vote',max(case when vote>0 then vote else null end) as '+vote' from # group by id
id -vote +vote
----------- ----------- -----------
44 -2 NULL
51 -3 1
52 -1 NULL
警告: 聚合或其他 SET 操作消除了空值。
(3 行受影响)