Reputation: 50
Using mysql on ubuntu
the following command is not ordering in descending order
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)
Upvotes: 1
Views: 74
Reputation: 311163
MySQL allows string literals with double quotes. So when you order by "maxCount", you're in fact ordering by a string literal, which is just meaningless. Remove the quotes and it should work just fine:
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)
Upvotes: 3