我有 MySQL 列 price
和 discountPrice
,我需要能够按 price
对产品进行排序,并且:
IF discountPrice is NOT empty AND is NOT NULL AND is LESS THAN price
order product by discountPrice
这有可能吗?
最佳答案
您可以将此类逻辑放在order by
中。假设 discountPrice
是数字,则简化为:
order by (case when discountPrice < price then discountPrice else Price end)
关于mysql - 如何使用 MySQL 按折扣列排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36848742/