我有这些记录:
Order
----------
id amount
1 10
2 NULL
3 20
如果不存在,我想设置amount
为-1
,下一步与-1
.
我写这个:
SELECT
id,
COALESCE(o.amount, -1) AS amount2
FROM Order o
WHERE amount2 = -1
但返回此错误:
#1054 - Unknown column 'amount2' in 'where clause'
我喜欢返回这个:
Order
----------
id amount2
2 -1