嗨,我想展示拥有最多博物馆的国家(德语)。
我的桌子看起来像:
+-----------+----------------------+-------------------+--------------------------+---------------+
| MuseumsNR | Name | Stadt | Land | Hauptstadt |
+-----------+----------------------+-------------------+--------------------------+---------------+
| 1 | Museum of Modern Art | New York | United States of America | Washington DC |
| 2 | Kunstmuseum | Bern | Schweiz | Bern |
| 3 | Musée Picasso | Paris | Frankreich | Paris |
| 4 | Städel | Frankfurt am Main | Deutschland | Berlin |
| 5 | Museum Ludwig | Köln | Deutschland | Berlin |
+-----------+----------------------+-------------------+--------------------------+---------------+
所以我想要的输出应该是:
+--------------------------+------+
| Land |Anzahl|
+--------------------------+------+
| Deutschland | 2 |
+--------------------------+------+
这是我尝试过的:
SELECT Land, COUNT(Name) Name from Museum order by Name desc;
输出:
+--------------------------+------+
| Land | Name |
+--------------------------+------+
| United States of America | 5 |
+--------------------------+------+
在此先感谢您的帮助!
最佳答案
SELECT Land, count(*) as Anzahl
FROM yourTable
GROUP BY Land
ORDER BY Anzahl
DESC LIMIT 1;`
仅在PostgreSQL中进行了测试,但在MySQL中应足够接近。
关于mysql - 显示条目最多的对象,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24455714/