DISTINCT clause in SQLite

前端 未结 2 1790
轻奢々
轻奢々 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)
    
    0 讨论(0)
  • 2021-01-02 17:18

    Use:

      SELECT MIN(t.a) AS A,
             t.b
        FROM TABLE t
    GROUP BY t.b
    
    0 讨论(0)
提交回复
热议问题