Is there a [straightforward] way to order results *first*, *then* group by another column, with SQL?

前端 未结 5 910
遥遥无期
遥遥无期 2021-01-12 19:07

I see that in SQL, the GROUP BY has to precede ORDER BY expression. Does this imply that ordering is done after grouping discards identical rows/columns?

Because I s

5条回答
  •  有刺的猬
    2021-01-12 19:46

    SELECT DISTINCT a,b
    FROM tbl t
    WHERE b = (SELECT MAX(b) FROM tbl WHERE tbl.a = t.a);
    

提交回复
热议问题