在ubuntu上使用mysql
下面的命令不是降序
mysql> select spo_id, count(spo_id) as "maxCount" from order_details GROUP BY spo_id ORDER BY "maxCount" DESC;
+--------+----------+
| spo_id | maxCount |
+--------+----------+
| 1 | 1 |
| 2 | 3 |
| 3 | 1 |
+--------+----------+
3 rows in set (0.00 sec)
最佳答案
MySQL 允许带双引号的字符串文字。因此,当您按“maxCount”排序时,您实际上是按字符串文字排序,这是毫无意义的。删除引号,它应该可以正常工作:
MariaDB [db]> select spo_id, count(spo_id) as maxCount from order_details GROUP BY spo_id ORDER BY maxCount DESC;
+--------+----------+
| spo_id | maxCount |
+--------+----------+
| 2 | 3 |
| 3 | 1 |
| 1 | 1 |
+--------+----------+
3 rows in set (0.00 sec)
关于mysql 不使用 Order by using DESC 进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44441778/