How to display rows that when added together equal zero

后端 未结 6 1679
一生所求
一生所求 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 01:51

    SELECT 
        * 
    FROM 
        tbis
    INNER JOIN
    (
        SELECT
            client_ref, supplier_key
        FROM
            tbis
        GROUP by client_ref, supplier_key
        HAVING sum(client_amount) = 0
    ) match
    ON match.client_ref = tbis.client_ref 
    AND match.supplier_key = tbis.supplier_key
    

    Demo at http://sqlfiddle.com/#!3/a3447/8/0

提交回复
热议问题