数据库sql文件提取链接:https://pan.baidu.com/s/1wYa5N9tffL43EKWcg1dE7A?pwd=1010
提取码:1010
1. 列的别名
as:全称:alias(别名),可以省略
列的别名可以使用一对""引起来,不要使用''。
SELECT employee_id emp_id,last_name AS lname,department_id "部门id",salary * 12 AS "annual sal"FROM employees;
2. 去除重复行
#查询员工表中一共有哪些部门id呢?
SELECT DISTINCT department_idFROM employees;SELECT COUNT(DISTINCT department_id)FROM employees;
3. 空值参与运算
1. 空值:null
2. null不等同于0,'','null'
SELECT * FROM employees;
#空值参与运算:结果一定也为空。
SELECT employee_id,salary "月工资",salary * (1 + commission_pct) * 12 "年工资",commission_pctFROM employees;
#实际问题的解决方案:引入IFNULL
SELECT employee_id,salary "月工资",salary * (1 + IFNULL(commission_pct,0)) * 12 "年工资",commission_pctFROM `employees`;
4. 查询常数
SELECT '尚硅谷',123,employee_id,last_nameFROM employees;
5.显示表结构
DESCRIBE employees; DESC employees;DESC departments;
6.过滤数据
#练习:查询90号部门的员工信息
SELECT * FROM employees WHERE department_id=90;
#练习:查询last_name为'King'的员工信息
SELECT * FROM employees WHERE last_name='King';