SQL CASE语句
表A,B,C中都有字段:Name,学号
问题:当A中Name不为空时,取A中的Name
当B中Name不为空时,取B中Name
其他情况去C中Name
Name优先度:A>B>C
请教大侠这个SQL怎么写 ????谢谢!
[解决办法]
select isnull(isnull(a.name,b,name),c.name) as name ,a.学号from a left join b on a.学号 = b.学号left join c on a.学号 = c.学号
[解决办法]
select COALESCE(a.Name,b.Name,c.Name) as NameCOALESCE(a.学号,b.学号,c.学号) as 学号from a full join b on a.Name=b.Namefull join c on c.Name=a.Name
[解决办法]
case when
[解决办法]
select case when a.name is not null then a.name else case when b.name is not null then b.name else c.name end endfrom tb
[解决办法]
select name=COALESCE(a.Name,b.Name,c.Name),a.学号from a left join b on a.学号 = b.学号left join c on a.学号 = c.学号