题目
employees表的字段
1.查询员工12个月工资总和,并起别名为ANNUAL SALARY
1)只考虑基本工资,不考虑奖金
select employee_id,last_name,salary*12 'ANNUAL SALARY' from employees;
2)考虑奖金
由于奖金不是每个人都有的,对于某些记录奖金字段为空,在sql语句中需要判断是否为空
select employee_id,last_name,salary*12*(1+ ifnull(commission_pct, 0)) 'ANNUAL SALARY' from employees;
这里的ifnull()函数,会判断第一个参数的值是否为空,如果为空则返回第二个参数,不为空返回第一个参数
2.返回查询employees表中去除重复job_id以后的数据
select DISTINCT job_id from employees;
3.查询工资大于12000的员工姓名和工资
select salary, last_name from employees where salary > 12000;
4.查询员工号为176的员工的姓名和部门号
select last_name, department_id from employees where employee_id = 176;
5.显示表departments结构,并查询其中的全部数据
DESC departments;
select * from departments;