如何在聚合列上使用ORDER BY

时间:2017-04-26 15:54:11

标签: mysql sql-order-by

这是我的mysql声明:

select distinct(prodname), 
       sum(qty) 
from tblordertrail 
group by prodname;

结果是:

+----------+------------+
| prodname |  sum(qty)  |
+----------+------------+
| product1 |  27        |
| product2 |  77        |
| product3 |  198       |
| product4 |  34        |
+----------+------------+

但我想要的结果是:

+----------+------------+
| prodname |  sum(qty)  |
+----------+------------+
| product3 |  198       |
| product2 |  77        |
| product4 |  34        |
| product1 |  27        |
+----------+------------+

先谢谢我的同事们。

0 个答案:

没有答案