日期:2014-05-18  浏览次数:20417 次

where。条件如何假case when
select * from a where 加判断。如果成立。id=1不成立 查询id=2的。该如何写

------解决方案--------------------
--1
select * from a where (如果成立 and id=1) or (不成立 and id = 2)

--2
if 如果成立
select * from a where id = 1
else
select * from a where id = 2

------解决方案--------------------
探讨
select * from a where 加判断。如果成立。id=1不成立 查询id=2的。该如何写

------解决方案--------------------
探讨

--1
select * from a where (如果成立 and id=1) or (不成立 and id = 2)

--2
if 如果成立
select * from a where id = 1
else
select * from a where id = 2