How to display rows that when added together equal zero

后端 未结 6 1687
一生所求
一生所求 2021-01-29 01:39

Been searching for a few weeks for a solution to this but have come up blank.

I have table of data similar to this:

client_ref  supplier_key  client_amou         


        
6条回答
  •  失恋的感觉
    2021-01-29 02:02

    One possible approach is to use the SUM() windowing function:

    SELECT * 
    FROM
    ( SELECT tbis.client_ref ,tbis.supplier_key,tbis.client_amount,
      SUM(tbis.client_amount) OVER (
        PARTITION BY tbis.client_ref, tbis.supplier_key) AS total_client_amount
      FROM [XXXX].[dbo].[transaction] tbis 
      WHERE tbis.client_amount !=0 
    )
    WHERE total_client_amount = 0
    

    SQL Fiddle

提交回复
热议问题