mysql - 如何使用 MySQL 按折扣列排序?

标签 mysql sql sql-order-by

我有 MySQL 列 pricediscountPrice,我需要能够按 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/

相关文章:

mysql - 按字符串的某些部分排序

Mysql - 按 2 级排序

php - MongoDb order by 为计算值

mysql - Entity Framework 核心 : Update() method INSERTs instead of UPDATEs on dependent entity

PHP查询打印特定的列选择

java - 不带时区的 PostgreSQL 时间戳与带时区的 java.util.Date 的比较

c# - 将一个表的所有行复制到另一个表

PHP 和 XML : Dlvr. 它不起作用

MySQL、utf8_general_ci 和西里尔字符

sql - 串联 - T-SQL