zoosql--Using Null 解答

这篇博客主要介绍了SQL中如何处理和查询Null值的情况。内容包括列出没有部门的教师,解释为什么不能直接使用dept=NULL进行判断,并通过不同类型的JOIN操作确保所有教师或部门都被列出。此外,还讲解了如何利用COALESCE函数显示手机号码,以及用COUNT和GROUP BY统计每个部门的教师数量。CASE语句被用来根据教师所在的部门显示'Sci'、'Art'或'None'的标签。
摘要由CSDN通过智能技术生成

Using Null

Using Null - SQLZOO

  1. List the teachers who have NULL for their department.

    Why we cannot use =

    You might think that the phrase dept=NULL would work here but it doesn't - you can use the phrase dept IS NULL

    That's not a proper explanation.

    select name from teacher
    where dept is null
  2. Note the INNER JOIN misses the teachers with no department and the departments with no teacher.

    SELECT teacher.name, dept.name
     FROM teacher INNER JOIN dept
               ON (teacher.dept=dept.id)
  3. Use a different JOIN so that all teachers are listed.

    select teacher.name , dept.name from teacher 
    left join dept on teacher.de
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值