gpt4 book ai didi

php mysql 按多列选择顺序

转载 作者:行者123 更新时间:2023-11-29 20:28:26 27 4
gpt4 key购买 nike

我有一个问题。我想排列列的顺序减少。 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不行谁能帮助我?

最佳答案

Cast Functions and Operators: 中所述

The type for the result can be one of the following values:

  • BINARY[(N)]
  • CHAR[(N)]
  • DATE
  • DATETIME
  • DECIMAL[(M[,D])]
  • SIGNED [INTEGER]
  • TIME
  • UNSIGNED [INTEGER]

所以你的查询将是这样的

Select m.*
from mark m
order by CAST(mathematics AS UNSIGNED) DESC, CAST(physics AS UNSIGNED) DESC, CAST(chemistry AS UNSIGNED) DESC;

关于php mysql 按多列选择顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39171423/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com