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.   

    select * from 表 where num1=-num2
      

  2.   

    暈你,itblog,你又不看清題目就答題。
      

  3.   

    select num1,num2 from t join
    (select sum(num2) as a from t group by num1) b
    on t.num1=b.a
    where b.a=0
      

  4.   

    OMG 刚才写错啦... 这个论坛不能编辑么...select num1,num2 from t join
    (select num1, sum(num2) as a from t group by num1) b
    on t.num1=b.num1
    where b.a=0
      

  5.   

    多加了一條數據做測試。不過此語句有局限,就是加上後不等於0的數據最多只能有一條,超過一條,以下語句無效。Create Table TEST
    (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
    */
      

  6.   

    phommy(顽石宫主),你的語句除了稍微有點語法錯誤外,結果也是不正確的。
      

  7.   

    嗯 看到了~ 执行时提示num1不明确~ 不过结果应该正确,下面是按你的数据改后的句子
    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
      

  8.   

    你語句,num1為1的沒有顯示出來。
      

  9.   

    Where (Select SUM(num2) From TEST Where num1=A.num1 And num2<>A.num2)<>0
    是什么意思,不明白