$query = "SELECT * FROM price
ORDER BY CAST(price AS DECIMAL(10,2))
DESC LIMIT $from, $max_results";

这个查询显示的结果是这样的
Example
________________________
Product      | Price
________________________
Shoes         | 94,200
________________________
Shirts        |66,900
________________________
Socks         |59,900
________________________
T-shirt       |49,700
________________________
Shirt Cloth   |Coming Soon
________________________
Shirt pant    |Coming Soon
________________________
Shirt jacket  |Coming Soon
________________________

我想要那样
Example
________________________
Product      | Price
________________________
Shirt Cloth   |Coming Soon
________________________
Shirt pant    |Coming Soon
________________________
Shirt jacket  |Coming Soon
________________________
Shoes         | 94,200
________________________
Shirts        |66,900
________________________
Socks         |59,900
________________________
T-shirt       |49,700
________________________

我该怎么做请帮我解决这个问题
谢谢

最佳答案

order by可以有任意表达式:

ORDER BY (price = 'Coming Soon') DESC, CAST(price AS decimal(10,2))

如果price是Coming Soon,则price = 'Coming Soon'将计算为布尔值TRUE。如果不相等,则为布尔值false。使用DESC排序时,先是真值,然后是假值。在这些真/假块中,CAST(...)将进一步排序实际价格。

09-26 07:26