Filter duplicate rows based on a field

后端 未结 4 847
余生分开走
余生分开走 2021-01-01 23:39

I have several records (bills) that are basically duplicates of each other, except for one field, which represents the language that bill is in.

For example:

<
4条回答
  •  庸人自扰
    2021-01-02 00:13

    Probably the easiest way would be to use ROW_NUMBER and PARTITION BY

    SELECT * FROM (
       SELECT b.*,
       ROW_NUMBER() OVER (PARTITION BY BillID ORDER BY Lang) as num
       FROM Bills b
       WHERE Account = 'abcd'
    ) tbl
    WHERE num = 1
    

提交回复
热议问题