例如,我有以下查询(请参见How to produce a result set based on the comparison of values between two fields?):
select id,
case nickname when '' then full_name else nickname end as new_name
from your_table
添加最后一行时出现语法错误
select id,
case nickname when '' then full_name else nickname end as new_name
from your_table
where new_name = 'Jen'
我能用
WHERE
语句筛选出结果集吗? 最佳答案
您需要使用子查询:
select t.id, t.new_name from
(select id,
case nickname when '' then full_name else nickname end as new_name
from your_table) t
where t.new_name = 'Jen'
关于mysql - 是否可以在同一查询中对使用AS关键字形成的字段执行WHERE?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9147611/