我只想选择name='David'
存在的行,如果没有这样的行
我要select * rows
。以下是我的无效声明:
SELECT * FROM table A
Where name='David'
else
SELECT * from table A
答案 0 :(得分:1)
在下面的查询中使用它将有效
select m1.name from
(
select m1.*, case when m1.name ='David' then 1 else 0 end as cnt from tableA m1 ) m1
inner join
(
select max(Cnt) as Cnt from
(
select t1.*, case when name ='David' then 1 else 0 end as Cnt
from tableA t1
) as t2
)as n
on m1.cnt=n.Cnt