DISTINCT clause in SQLite

前端 未结 2 1791
轻奢々
轻奢々 2021-01-02 16:54

Recently i found that SQLite don\'t support DISTINCT ON() clause that seems postgresql-specific. For exeample, if i have table t with columns

2条回答
  •  孤城傲影
    2021-01-02 17:16

    sqlite> SELECT * FROM t GROUP BY b;
    2|5
    4|6
    (for each b: one (unpredictable) value of a)
    
    sqlite> SELECT * FROM (SELECT * FROM t ORDER BY a DESC) GROUP BY b;
    1|5
    3|6
    (for each b: the row with min a)
    
    sqlite> SELECT * FROM (SELECT * FROM t ORDER BY a ASC) GROUP BY b;
    2|5
    4|6
    (for each b: the row with max a)
    

提交回复
热议问题