判断null值使用 is null
= 和 <>无法判断null值
<=>安全等于号 (可读性低,不建议使用)
既可以判断null值,又可以判断普通类型
查询员工号为100的员工的姓名和年薪
#commition字段有可能为null,当commition为null时返回0
select last_name,salary*12*(1+IFNULL(commition,0));
经典面试题:
#1
select * from userinfo
#2
select * from userinfo where user_name like '%%' and user_id like '2'
#3
select * from userinfo where user_name like '%%' or user_id like '2'
存在null值情况:
1和3的效果是一样的
1和2的结果是不一样的
group by :排序
#若不写则默认为ASC升序,DESC标明为降序
select * from userinfo where age=18 group by username DESC
#此外,group by 支持单字段,多字段,表达式,函数,别名
#位置位于倒数第二 ,limit是最后一个位置
查询邮箱中包含e的员工的信息,并先按邮箱的字节数降序,再按部门号升序
select * from userinfo where email like '%e%' group by Length(email) DESC,departmentid ASC;
2038

被折叠的 条评论
为什么被折叠?



