有两个数据,表格名为test
A          B
206271     2
205283     -1
206271     -1
206283     1
用SQL语句如何实现结果如下
206271  1我用这些语句实现
select A,sum(B) from test group by A
但是会出现
206271 1
205283 0
如何把0的数据行也隐藏掉

解决方案 »

  1.   

    有两个数据,表格名为test
    A          B
    206271     2
    205283     -1
    206271     -1
    205283     1 (上面打错了,更正一下)
    用SQL语句如何实现结果如下
    206271  1
      

  2.   

    select A,sum(B) as B
    from table
    group by A
      

  3.   

    select A,sum(B) as B
    from table
    where A = 206271 //针对一个id 求和
    group by A
      

  4.   

    select A, sum(B) 
    from test 
    group by A
    having sum(b) <> 0
      

  5.   

    select A, sum(B) 
    from test 
    group by A
    having sum(b) <> 0
    应该对的