我有一个包含 4 个 varchar 字段的表,我需要根据列是否为空来排序。
所以我的表结构是:
start_price reserve_price buy_now_price current_bid_amount
---------------------------------------------------------------------
50.00 50.00 empty (not null) (Null)
190 190 empty (not null) (Null)
150 150 empty (not null) (Null)
20 150 empty (not null) (Null)
550 600 empty (not null) (Null)
我在下面有一个订单条款,但似乎没有正确订购。目前,结果按 190、150、50、20、550 排序。
ORDER BY COALESCE(CAST(
al
.current_bid_amount
AS SIGNED), CAST(al
.buy_now_price
AS SIGNED), CAST(al
.start_price
AS SIGNED), CAST(al
.reserve_price
AS SIGNED)) ASC
基本上我需要根据 current_bid_amount、buy_now_price、start_price、reserve_price 按最低价排序。因此,如果 current_bid_amount AND buy_now_price 为空,则使用 start_price。如果 current_bid_amount 为空但 buy_now_price 不是,则使用 buy_now_price。如果 current_bid_amount 中有一个值,请使用该值进行订购。
非常感谢。