num1 num2
1 -1
2 2
1 2
2 2
1 1
2 -4num1 num2
1 -1 只要是相加之和为零的的项
1 1 num1相当于编号
2 2 注:num1=1的
2 2
2 -4
1 -1
2 2
1 2
2 2
1 1
2 -4num1 num2
1 -1 只要是相加之和为零的的项
1 1 num1相当于编号
2 2 注:num1=1的
2 2
2 -4
(select sum(num2) as a from t group by num1) b
on t.num1=b.a
where b.a=0
(select num1, sum(num2) as a from t group by num1) b
on t.num1=b.num1
where b.a=0
(num1 Int,
num2 Int)
Insert TEST Select 1, -1
Union All Select 2, 2
Union All Select 1, 2
Union All Select 2, 2
Union All Select 1, 1
Union All Select 2, -4
Union All Select 2, -5
GO
Select * From TEST A
Where (Select SUM(num2) From TEST Where num1=A.num1 And num2<>A.num2)<>0
Order By num1,num2
GO
Drop Table TEST
GO
--Result
/*
num1 num2
1 -1
1 1
2 -4
2 2
2 2
*/
select test.num1,num2 from test join
(select num1, sum(num2) as a from test group by num1) b
on test.num1=b.num1
where b.a=0
是什么意思,不明白