2

我对 mysql 查询的条件排序有疑问

  1. 我想给乘数降序优先级

  2. 在第二个优先级,我想按底池降序排列(但仅限于底池 > 80 时)

  3. 在第三个优先级我想按点排序

我的问题是如何按锅订购,但前提是锅 > 一定数量。

SELECT NAME, POINTS, POT, MULTIPLIER
FROM ITEMS 
ORDER BY MULTIPLIER DESC, 
(CASE WHEN (POT > 80) THEN 'POT DESC,POINTS DESC'
ELSE 'POINTS DESC' END)

这是我尝试过的,但是,如果它满足条件,那么它将停止按第三级优先级的点排序...我希望它始终按第三级优先级的点排序

我想要的示例订单:

multiplier(4),pot(20),points(144)
multiplier(2),pot(90),points(130)
multiplier(2),pot(90),points(13)
multiplier(1),pot(70),points(16783)
multiplier(1),pot(77),points(1653)
multiplier(1),pot(78),points(163)
4

2 回答 2

2

我想这就是你要找的:

SELECT NAME, POINTS, POT, MULTIPLIER
FROM ITEMS
ORDER BY
  multiplier DESC,
  pot <= 80,
  points DESC
于 2013-10-30T16:34:32.403 回答
0
ORDER BY multiplier DESC, (CASE WHEN pot > 80 THEN pot ELSE 80 END) DESC, points DESC
于 2013-10-30T16:24:11.927 回答