(四)mysql数据库语法学习

#isnull()函数
select ISNULL(a.commission_pct),commission_pct from employees a; --判断结果时候为空,为空的话就显示1,类似于true,不为空的话就显示0,类似于false

 

 

#这样写导致查询出来的结果都是不规则的,所以会报错
select distinct department_id,distinct salary from employees;

报错信息:1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'distinct salary from employees' at line 1
#这样写是对的,但是department_id会显示重复的数据
select distinct department_id, salary from employees;--原因:因为每个部门的每个员工工资是不同的,所以department_id会显示重复。也就是说,这个时候distinct就失效了。

 

posted @ 2020-02-12 17:58  ~码铃薯~  阅读(147)  评论(0编辑  收藏  举报