美文网首页
【SQL】13.SQLZOO练习8--Using Null

【SQL】13.SQLZOO练习8--Using Null

作者: 一曈 | 来源:发表于2017-06-05 15:45 被阅读32次

    题目链接:https://sqlzoo.net/wiki/Using_Null

    题目 1
    select name from teacher 
    where dept is null;
    
    2
    select a.name,b.name from teacher a
    inner join dept b on a.dept=b.id;
    
    3
    select a.name,b.name from teacher a
    left join dept b on a.dept=b.id;
    
    4
    select a.name,b.name from teacher a
    right join dept b on a.dept=b.id;
    
    5
    select name,coalesce(mobile,'07986 444 2266') from teacher
    
    6
    select a.name,coalesce(b.name,'None') from teacher a
    left join dept b on a.dept = b.id;
    
    7
    select count(name),count(mobile) from teacher;
    
    8
    select b.name,count(a.name) from teacher a
    right join dept b on b.id=a.dept
    group by b.name;
    
    9
    select a.name,case 
    when b.id=1 then 'Sci'
    when b.id=2 then 'Sci'
    else 'Art' end
    from teacher a left join dept b
    on a.dept=b.id;
    
    10
    select a.name,case 
    when b.id=1 then 'Sci'
    when b.id=2 then 'Sci'
    when b.id=3 then 'Art'
    else 'None' end
    from teacher a left join dept b
    on a.dept=b.id;
    

    相关文章

      网友评论

          本文标题: 【SQL】13.SQLZOO练习8--Using Null

          本文链接:https://www.haomeiwen.com/subject/eqgifxtx.html