我正在尝试选择某个名称是否已存在于我的客户表中。
这就是我想做的,但我收到错误“子选择不支持案例构造。感谢您的帮助。
select id, if(description not in (select name from customer where type in ('A', 'B','C')), 'NOT A CUSTOMER', description) from names
问题是,你的 sql 引擎告诉你的...尝试以下方法之一:
使用两个选择和联合。一项选择“仅限客户”,另一项不选择,
尝试在子查询中使用exists,
连接表并具有可能为空值的列并在客户端处理它。
union(
select id,
c.description
if(description not in (select name from customer where ,
from names n
left join customer c ON (c.id == n.customer_id)
where n.type in ('A', 'B','C')
,
select id,
'NOT A CUSTOMER'
from names n
left join customer c ON (c.id == n.customer_id)
where n.type not in ('A', 'B','C')
)
PS:在发布之前格式化你的sql,包括野兽答案的逻辑模型并提及,你正在使用什么数据库。