我有个问题。我想安排列的降序。iphone4,iphone5,iphone6。例如:
Name |iphone4 |iphone5|iphone6
john | 6 | 7 | 8
Smith| 6 | 9 | 8
Louis| 6 | 7 | 10
Nick | 7 | 7 | 8
john | 2 | 7 | 4
Smith| 7 | 7 | 5这是我的mysql
Select Name, SUM(iphone4) ,SUM(iphone5),SUM(iphone6) from orders group by Name order by iphone4 DESC, iphone5 DESC, iphone6 DESC但它只是一个工作列iphone4和iphone5。剩下的,iphone6,这不管用谁能帮我?
发布于 2016-08-27 01:12:00
如果将值存储为字符串而不是数字,则顺序似乎不起作用。
如果是这种情况,那么将它们转换为数字可以解决这个问题:
Select m.*
from mark m
order by (mathematics + 0) DESC, (physics + 0) DESC, (chemistry + 0) DESC;此外,此查询似乎不需要任何GROUP BY。
编辑:
对于编辑后的版本,您需要order by和select中的聚合。明确地说,我会把它们写成:
Select Name, SUM(iphone4+0), SUM(iphone5+0), SUM(iphone6+0)
from orders
group by Name
order by SUM(iphone4+0) desc, SUM(iphone5+0) desc, SUM(iphone6+0) desc;发布于 2016-08-27 01:47:56
如Cast Functions and Operators:中所述
结果的类型可以是下列值之一:
因此,您的查询将如下所示
Select m.*
from mark m
order by CAST(mathematics AS UNSIGNED) DESC, CAST(physics AS UNSIGNED) DESC, CAST(chemistry AS UNSIGNED) DESC;https://stackoverflow.com/questions/39171423
复制相似问题