0

我有一张桌子mytable

id | name| location
---|-----|----------
1  | fff |  www
2  | bbb |  xxx
3  | aaa |  www
4  | eee |  xxx
5  | ddd |  yyy
6  | ccc |  xxx

如何选择它以使名称按其位置按升序排列?

我期望输出为:

 name| location
-----|----------
 aaa |  www
 fff |  www
 bbb |  xxx
 ccc |  xxx
 eee |  xxx
 ddd |  yyy

sql:

SELECT name, location
FROM mytable
GROUP BY location
ORDER BY location, name ASC

给出:

 name| location
-----|----------
 bbb |  xxx
 ddd |  yyy
 fff |  www
4

1 回答 1

0

在这种情况下,您不需要使用 GROUP BY ,只需:

   SELECT name, location
     FROM mytable
 ORDER BY location asc, name asc

它会给你预期的结果

于 2013-01-26T07:29:30.243 回答