[SQL]Summing a column while ignoring duplicate records(row_number())


SELECT custid, SUM(amount)
FROM (SELECT t.*,
             ROW_NUMBER() OVER (PARTITION BY custid, transid ORDER BY transid) AS seqnum
      FROM table_1 t
     ) t
WHERE seqnum = 1;
#SQL






你可能感興趣的文章

Pinia練習-製作購物車

Pinia練習-製作購物車

另一個與 styled-components 相關的 debug 紀錄

另一個與 styled-components 相關的 debug 紀錄

實作 Redux(五):reducer

實作 Redux(五):reducer






留言討論