我使用下面的查询根据case语句中指定的条件获取多个列值,并遇到以下错误操作数应该只包含1列mysql查询。我只是不知道存在什么问题-- is.Is对此进行了简单的修复,还是用另一种方式编写查询?
SELECT id,
CASE
WHEN id='' THEN (select * where name='abc')
ELSE (select * from sample)
END
FROM sample WHERE name='abc' and status='xyz'发布于 2017-03-29 06:33:28
您可以使用组合了三个不同查询的联合查询:
select * from samples
where name='abc' and status='xyz'
union all
select * from samples
where
name='abc' and not exists (
select * from samples
where name='abc' and status='xyz'
)
union all
select * from samples
where
not exists (
select * from samples
where name='abc'
)(这三个查询可以与OR一起使用,但是联合查询更容易阅读和更清晰)
https://stackoverflow.com/questions/43085807
复制相似问题