Window functions in SQLite3

后端 未结 2 716
南笙
南笙 2021-01-26 19:06

The following Oracle SQL select allows me to select all the rows of a table that are duplicated according to some fields, eg, they have the same COLUMN_1,

2条回答
  •  花落未央
    2021-01-26 19:45

    The following query can get you close to what you want:

    SELECT t1.*
    FROM MY_TABLE t1
    LEFT JOIN
    (
        SELECT COLUMN_2, COLUMN_3, MIN(COLUMN_1) AS MIN_COLUMN_1
        FROM MY_TABLE
        GROUP BY COLUMN_2, COLUMN_3
    ) t2
        ON t1.COLUMN_2 = t2.COLUMN_2 AND
           t1.COLUMN_3 = t2.COLUMN_3 AND
           t1.COLUMN_1 = t2.MIN_COLUMN_1
    WHERE
        t2.COLUMN_2 IS NULL;
    

    This query works by filtering off records having the minimum COLUMN_1 value for each COLUMN_2, COLUMN_3 group. Actually, this corresponds to the rank rather than the row number, but maybe this is acceptable to you.

提交回复
热议问题