gpt4 book ai didi

php - 如何选择产品并按折扣 DESC 排序(PHP、Mysql)

转载 作者:行者123 更新时间:2023-11-29 01:23:34 26 4
gpt4 key购买 nike

使用PHP和Mysql。
我的表(产品)中的字段是 idfull_pricesell_price

我如何选择产品 ORDER BY discount DESC,其中 discount = (full_price-sell_price) * 100/full_price?我尝试使用它,但它不起作用:

  SELECT *
FROM product
WHERE full_price > 0
ORDER BY (discount = (full_price - sell_price) * 100 / full_price)
LIMIT 10

最佳答案

如果您希望折扣也成为结果集中的一列,请这样做:

SELECT *, (full_price - sell_price) * 100 / full_price AS discount
FROM product
WHERE full_price > 0
ORDER BY discount DESC

关于php - 如何选择产品并按折扣 DESC 排序(PHP、Mysql),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9985592/

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