SQL语法体系学习笔记
SQL语法之基础查询(进阶1)and条件查询(进阶2)
SQL语法之排序查询(进阶3)and常见函数(进阶4)
SQL语法之分组函数,分组查询(进阶5)and连接查询(sql92语法进阶6)
文章目录
- SQL语法体系学习笔记
- 分组函数
- 分组查询
- 连接查询
- 章节测试题
- 1.显示所有员工的姓名,部门号和部门名称
- 2.查询90号部门员工的job_id和90号部门的location_id
- 3.选择所有有奖金的员工的last_name,department_name,location_id,city
- 4.选择city在Toronto工作的员工的last_name,job_id,department_id,department_name
- 5.查询每个工种,每个部门的部门名,工种号和最低工资
- 6.查询每个国家下的部门个数大于2的国家籍号
- 7.选择指定员工的姓名,员工号,以及它的管理者的姓名和员工号,结果类似于下面的格式:
- boys 和girls 表创建代码
- jobs 表创建代码
- locations 表创建代码
- job_grades 表创建代码
分组函数
功能
用作统计使用,又称为聚合函数或统计函数或组函数
分类
sum 求和 avg 平均值 max最大值 min 最小值 count 计算个数
函数特点:
- sum ,avg 一般用于处理数值型;max ,min , count可以处理任何类型
- 以上分组函数都忽略null值
- 可以和distinct搭配实现去重的运算
- count函数的单独介绍,一般使用count(*)用作统计行数
- 和分组函数一同查询的字段要求是group by 后面的字段
分组函数的使用
1.简单使用
select sum(salary) from employees;
select min(salary) from employees;
select avg(salary) from employees;
select count(salary) from employees;
SELECT SUM(salary) 和 ,AVG(salary) 平均 , MAX(salary) 最高 , MIN(salary) 最低 ,COUNT(salary) 个数 FROM employees;
SELECT SUM(salary) 和 ,ROUND(AVG(salary),2) 平均 , MAX(salary) 最高 , MIN(salary) 最低 ,COUNT(salary) 个数 FROM employees;
2.参数支持哪些类型
select sum(last_name) ,avg(last_name) from employees;
注意,此时得出数据已经没意义了,即使没报错,拿到这些数据无意义的话,也就认为不能当做参数。
select sum(hiredate) ,avg(hiredate) from employees;
select max(last_name) ,min(last_name) from employees;
select max(hiredate) ,min(hiredate) from employees;
select count(commission_pct) from employees;
select count(last_name) from employees;
3.是否忽略null
select sum(commission_pct),avg(commission_pct),sum(commission_pct)/35,sum(commission_pct)/107 from employees;
select max(commission_pct) ,min(commission_pct) from employees;
(count函数本身就是计算非空值的个数)
select count(commission_pct) from employees;
4.和distinct搭配
(去重之后求和):
select sum(distinct salary), sum(salary) from employees;
(去重之后求个数):
select count(distinct salary),count(salary) from employees;
5.count函数的详细介绍
select count(salary) from employees;
(统计总行数):
select count(*) from employees;
举个例子:总行数有107行,如果我们统计salary(select count(salary) from employees;)
的时候,其中有一个为空,那么所得就是106行。提示:虽然salary为空,但salary所在行不一定全为null,这个时候总行数用salary去统计就不正确了。
用select count(*) from employees;
统计总行数的话,只要一行之中有一个不为null
(任何字段不为null),那么这行就可以被算上。
select count(1) from employees;
这个也可以用来统计行数,也就是说在每行的前面加了一个1,然后再来计算1的个数,最后有几行就有几个1喽),也可以在括号里写2,3,4,5,6…………写啥常量值(字符常量,或者数字常量)都行
效率
MYISAM
存储引擎下,count(* )
的效率高(因为这个存储引擎内部有个计数器,直接返回个数)
默认存储引擎:INNODB
存储引擎下,count(*)
和count(1)
的效率差不多,比count(字段)
要高一些(加字段的话,得先判断这个字段是否为null
)
6.和分组函数一同查询的字段有限制
select avg(salary), employee_id from employees;
直接报错,原因如下:
即使出来了,这里的employee_id也没有任何意义
总结测试:
1.查询公司员工工资的最大值,最小值,平均值,总和
select max(salary) mx_sal, min(salary) mi_sal, round(avg(salary),2) ag_sal , sum(salary) sm_sal from employees;
2.查询员工表中的最大入职时间和最小入职时间的相差天数(DIFFERENCE)
select datediff(max(hiredate),min(hiredate)) DIFFRENCE from employees;
举例:datediff用法
select datediff(now(),'2002-5-8');
select datediff('2020-10-1','2002-5-8');
3.查询部门编号为90的员工个数
select count(*) 个数 from employees where department_id=90;
分组查询
语法:
select 分组函数,列(要求出现在group by的后面)
from 表
[where 筛选条件]
group by 分组的列表
[order by 子句]
注意:
查询列表必须特殊,要求是分组函数和group by后出现的字段
特点:
- 分组查询中的筛选条件分为两类:
分组前筛选:
数据源 | 位置 | 关键字 |
---|---|---|
原始表 | group by子句的前面 | where |
分组后筛选:
数据源 | 位置 | 关键字 |
---|---|---|
分组后 | group by子句的后面 | having |
-
group by子句支持单个字段分组,多个字段分组(多个字段之间用逗号隔开没有顺序要求),表达式或函数(用得较少)
-
也可以添加排序(排序放在整个分组查询的最后)
注意点:
- 一般来说,分组函数做条件肯定是放在having子句中(因为分组函数在原始表中没有)
- 能用分组前筛选的,就优先考虑分组前筛选
引入:
查询每个部门的平均工资:
分组数据 group by 子句语法
可以使用 group by 子句将表中的数据分成若干组:
select column ,group_function(column) from table [where condition]
[group by group_by_expression] [order by column];
明确:where一定放在from后面
简单的分组查询
案例1: 查询每个工种的最高工资
select max(salary) ,job_id from employees group by job_id;
案例1: 查询每个工种的最高工资
select max(salary) ,job_id from employees group by job_id
案例2:查询每个工种的最高工资
select count(*),location_id from departments group by location_id;
筛选:
1.添加筛选条件(添加分组前的筛选)
注意:这里的where子句中的筛选条件是包含在where子句前面的from后表中
案例1:查询邮箱中包含a字符的,每个部分的平均工资
select avg(salary),department_id from employees where email like '%a%' group by department_id;
(根据语法:where子句放在from后面,group by前面)
案例2:查询有奖金的每个领导手下员工的最高工资
select max(salary),manager_id from employees where commission_pct is not null group by manager_id;
2.添加复杂的筛选条件(添加分组后的筛选)
案例1:查询哪个部门的员工个数>2
- 根据每个部门的员工个数
select count(*),department_id from employees group by department_id;
- 根据1的结果进行筛选,查询哪个部门的员工个数>2
错误示范:
select count(*),department_id from employees group by department_id where count(*)>2???????
这样可以吗?where加在最后面?肯定不行呀,根据语法规则,where子句放在from后面,group by前面
所以的话需要使用新的关键字having
select count(*),department_id from employees group by department_id having count(*)>2;
案例2:查询每个工种有奖金的员工的最高工资>12000 的工种编号和最高工资
- 查询每个工种有奖金的员工的最高工资
select max(salary), job_id from employees where commission_pct is not null group by job_id;
- 根据1结果继续筛选,最高工资>12000
select max(salary), job_id from employees where commission_pct is not null group by job_id having max(salary)>12000;
案例3:查询领导编号>102的每个领导手下的最低工资>5000的领导编号是哪个,以及最低工资
- 查询每个领导手下的员工固定最低工资
select min(salary),manager_id
from employees group by manager_id;
- 添加筛选条件:编号>102
select min(salary),manager_id from employees where manager_id>102 group by manager_id;
- 添加筛选工资:最低工资>5000
select min(salary),manager_id from employees where manager_id>102 group by manager_id having min(salary) >5000;
按表达式或函数进行分组:
案例:
按员工姓名的长度分组,查询每一组的员工个数,筛选员工个数>5的有哪些
- 查询每个长度的员工个数
select count(*),length(last_name) len_name from employees group by length(last_name);
- 添加筛选条件
select count(*),length(last_name) len_name from employees group by length(last_name) having count(*)>5;
使用别名:
select count(*) c ,length(last_name) len_name from employees group by len_name having c>5;
注意
(MySQL中group by 和having后面皆可放别名,但是where后面不能放别名;Oracle中group by 和having后面不可以放别名)
按多个字段进行分组:
案例:查询每个部门每个工种的员工的平均工资
select avg(salary),department_id,job_id from employees group by department_id,job_id;
在这里呢,group by后面所加的department_id,job_id可以互换位置
select avg(salary),department_id,job_id from employees group by job_id,department_id;
添加排序:
案例:
查询每个部门每个工种的员工的平均工资,并且按平均工资的高低显示:
select avg(salary),department_id,job_id from employees group by department_id,job_id order by avg(salary) desc;
然后添加id不为空,平均薪资大于10000才显示:
select avg(salary) a,department_id,job_id from employees where department_id is not null group by department_id,job_id having a>10000 order by avg(salary) desc;
检测习题
1.查询各job_id的员工工资的最大值,最小值,平均值,总和,并按job_id升序
select max(salary),min(salary),avg(salary),sum(salary),job_id from employees group by job_id order by job_id;
2.查询员工最高工资和最低工资之间的差距(DIFFERENCE)
select max(salary)-min(salary) DIFFERENCE from employees;
3.查询各个管理者手下员工的最低工资,其中最低工资不能低于6000,没有管理者的员工不计算在内
select min(salary),manager_id from employees where manager_id is not null group by manager_id having min(salary)<6000;
4.查询所有部门的编号,员工数量和工资平均值,并按平均工资降序
SELECT department_id,COUNT(*),AVG(salary) a
FROM employees
GROUP BY department_id
ORDER BY a DESC;
5.选择具有各个job_id的员工人数
select count(*) 个数 ,job_id from employees group by job_id;
department表的创建代码
CREATE TABLE `departments` (
`department_id` INT(4) ,
`department_name` VARCHAR(3) ,
`manager_id` INT(6) ,
`location_id` INT(4)
) ;
INSERT INTO `departments` VALUES (10, 'Adm', 200, 1700);
INSERT INTO `departments` VALUES (20, 'Mar', 201, 1800);
INSERT INTO `departments` VALUES (30, 'Pur', 114, 1700);
INSERT INTO `departments` VALUES (40, 'Hum', 203, 2400);
INSERT INTO `departments` VALUES (50, 'Shi', 121, 1500);
INSERT INTO `departments` VALUES (60, 'IT', 103, 1400);
INSERT INTO `departments` VALUES (70, 'Pub', 204, 2700);
INSERT INTO `departments` VALUES (80, 'Sal', 145, 2500);
INSERT INTO `departments` VALUES (90, 'Exe', 100, 1700);
INSERT INTO `departments` VALUES (100, 'Fin', 108, 1700);
INSERT INTO `departments` VALUES (110, 'Acc', 205, 1700);
INSERT INTO `departments` VALUES (120, 'Tre', NULL, 1700);
INSERT INTO `departments` VALUES (130, 'Cor', NULL, 1700);
INSERT INTO `departments` VALUES (140, 'Con', NULL, 1700);
INSERT INTO `departments` VALUES (150, 'Sha', NULL, 1700);
INSERT INTO `departments` VALUES (160, 'Ben', NULL, 1700);
INSERT INTO `departments` VALUES (170, 'Man', NULL, 1700);
INSERT INTO `departments` VALUES (180, 'Con', NULL, 1700);
INSERT INTO `departments` VALUES (190, 'Con', NULL, 1700);
INSERT INTO `departments` VALUES (200, 'Ope', NULL, 1700);
INSERT INTO `departments` VALUES (210, 'IT ', NULL, 1700);
INSERT INTO `departments` VALUES (220, 'NOC', NULL, 1700);
INSERT INTO `departments` VALUES (230, 'IT ', NULL, 1700);
INSERT INTO `departments` VALUES (240, 'Gov', NULL, 1700);
INSERT INTO `departments` VALUES (250, 'Ret', NULL, 1700);
INSERT INTO `departments` VALUES (260, 'Rec', NULL, 1700);
INSERT INTO `departments` VALUES (270, 'Pay', NULL, 1700);
连接查询
含义
又称多表查询,当查询的字段来自于多个表时,就会用到连接查询
笛卡尔乘积现象
表1 有m行,表2有n行,结果=m*n行
发生原因:没有有效的连接条件
如何避免:添加有效的连接条件
分类:
按年代分类:
sql92
标准(MySQL:仅仅支持内连接)sql99
标准[标准]:(在mysql中:支持内连接 +外连接(左外和右外)+交叉连接)
按功能分类:
内连接:
- 等值连接
- 非等值连接
- 自连接
外连接:
- 左外连接
- 右外连接
- 全外连接
交叉连接
引入
select name,boyname from boys,beauty ;
select name,boyname from boys,beauty where beauty.boyfriend_id=boys.id;
sql92标准
1.等值连接
特点
- 多表等值连接的结果为多表的交集部分
- n表连接,至少需要n-1个连接条件
- 多表的顺序没有要求
- 一般需要为表起别名
- 可以搭配前面介绍的所有子句使用,比如排序,分组,筛选
案例1:查询女神名和对应的男神名
select name,boyname from boys,beauty where beauty.boyfriend_id=boys.id;
案例2:查询员工名和对应的部门名
select last_name ,department_name from employees,departments where employees.department_id=departments.department_id;
2.为表起别名
好处:
- 提高语句的简洁度
- 区分多个重名的字段
注意:
如果为表起了别名,则查询的字段就不能用原来的表名去限定
查询员工名,工种号,工种名
SELECT e.last_name,e.job_id ,j.job_title FROM employees e ,jobs j WHERE e.job_id=j.job_id;
3.两个表的顺序是否可以调换
查询员工名,工种号,工种名
SELECT e.last_name,e.job_id , j.job_title FROM jobs j ,employees e WHERE e.job_id=j.job_id;
4.可以加筛选?
案例:查询有奖金的员工名,部门名
select last_name,department_name ,commission_pct from employees e,departments d where e.department_id=d.department_id and e.commission_pct is not null;
案例2:查询城市名中第二个字符为o的部门名和城市名
select department_name,city from departments d,locations l where d.location_id=l.location_id and city like '_o%';
5.可以加分组?
案例1:查询每个城市的部门个数
SELECT COUNT(*) 个数,city FROM departments d,locations l WHERE d.location_id=l.location_id GROUP BY city;
案例2:查询有奖金的每个部门的部门名和部门领导编号和该部门的最低工资
SELECT department_name,d.manager_id,MIN(salary) FROM departments d,employees e WHERE d.department_id=e.department_id AND commission_pct IS NOT NULL GROUP BY department_name,d.manager_id;
6.可以添加排序
案例:查询每个工种的工种名和员工的数量,并且按员工个数降序
SELECT job_title , COUNT(*) FROM employees e,jobs j WHERE e.job_id=j.job_id GROUP BY job_title ORDER BY COUNT(*) DESC;
7.可以实现三表连接?
案例:查询员工名,部门名和所在的城市
select last_name,department_name,city from employees e,departments d, locations l where e.department_id=d.department_id and d.location_id=l.location_id;
SELECT last_name,department_name,city FROM employees e,departments d, locations l WHERE e.department_id=d.department_id AND d.location_id=l.location_id AND city LIKE 's%';
SELECT last_name,department_name,city FROM employees e,departments d, locations l WHERE e.department_id=d.department_id AND d.location_id=l.location_id AND city LIKE 's%' ORDER BY department_name DESC;
非等值连接
案例1:查询员工的工资和工资级别
select salary,grade_level from employees e,job_grades g where salary between g.lowest_sal and g.highest_sal;
select salary,grade_level from employees e,job_grades g where salary between g.lowest_sal and g.highest_sal and g.grade_level='A';
自连接
查询员工名和上级的名称
select employee_id,last_name,manager_id from employees;
select e.employee_id,e.last_name,m.employee_id,m.last_name from employees e,employees m where e.manager_id=m.employee_id;
测试题
1.显示员工表的最大工资,工资平均值
select max(salary),avg(salary)from employees;
2.查询员工表的employee_id,job_id,last_name,按department_id降序,salary升序
select employee_id,job_id,last_name from employees order by department_id desc,salary asc;
3.查询员工表的job_id中包含 a 和 e的,并且a在e 的前面
select job_id from employees where job_id like '%a%e%';
4.已知表student 里面有id(学号),name,gardeID(年级编号);已知表grade里面有id(年级编号),name(年级名);已知表result 里面有id,score,studentNo(学号)
select s.name,g.name,r.score from student s,grade g,result r where s.id=r.studentNo and g.id=s.gradeid;
5.显示当前日期,以及去前后空格,截取子字符串的函数
select now();
select trim(字符 from '');
select substr(str,startIndex);
select substr(str,startIndex,length);
章节测试题
1.显示所有员工的姓名,部门号和部门名称
select last_name,d.department_id,department_name from employees e,departments d where e.department_id=d.department_id;
2.查询90号部门员工的job_id和90号部门的location_id
SELECT job_id,location_id FROM employees e ,departments d WHERE e.department_id=d.department_id AND e.department_id=90;
3.选择所有有奖金的员工的last_name,department_name,location_id,city
SELECT last_name ,department_name,l.location_id,city FROM employees e,departments d,locations l WHERE e.department_id=d.department_id AND d.location_id=l.location_id AND e.commission_pct IS NOT NULL;
4.选择city在Toronto工作的员工的last_name,job_id,department_id,department_name
SELECT last_name,job_id,d.department_id,department_name FROM employees e, departments d,locations l WHERE e.department_id=d.department_id AND d.location_id=l.location_id AND city='Toronto';
5.查询每个工种,每个部门的部门名,工种号和最低工资
SELECT department_name,job_title,MIN(salary) 最低工资 FROM employees e,departments d,jobs j WHERE e.department_id=d.department_id AND e.job_id=j.job_id GROUP BY department_name,job_title;
6.查询每个国家下的部门个数大于2的国家籍号
SELECT * FROM departments d,locations l WHERE d.location_id=l.location_id;
select country_id,count(*) 部门个数 from departments d,locations l where d.location_id=l.location_id group by country_id having 部门个数>2;
7.选择指定员工的姓名,员工号,以及它的管理者的姓名和员工号,结果类似于下面的格式:
employees Emp# manager Mgr#
kochhar101 king 100
SELECT e.last_name employees ,e.employee_id 'Emp#' ,m.last_name manager ,m.employee_id 'Mgr#' FROM employees e,employees m WHERE e.manager_id=m.employee_id;
SELECT e.last_name employees ,e.employee_id "Emp#" ,m.last_name manager ,m.employee_id "Mgr#" FROM employees e,employees m WHERE e.manager_id=m.employee_id AND e.last_name='Kochhar';
boys 和girls 表创建代码
CREATE TABLE `boys` (
`id` INT(11) ,
`boyName` VARCHAR(20) ,
`userCP` INT(11)
) ;
INSERT INTO `boys` VALUES (1, '张无忌', 100);
INSERT INTO `boys` VALUES (2, '鹿晗', 800);
INSERT INTO `boys` VALUES (3, '黄晓', 50);
INSERT INTO `boys` VALUES (4, '段誉', 300);
CREATE TABLE `beauty` (
`id` INT(11) ,
`name` VARCHAR(50) ,
`sex` CHAR(1) ,
`borndate` DATETIME ,
`phone` VARCHAR(11) ,
`photo` BLOB ,
`boyfriend_id` INT(11)
) ;
INSERT INTO `beauty` VALUES (1, '柳岩', '女', '1988-02-03 00:00:00', '18209876577', NULL, 8);
INSERT INTO `beauty` VALUES (2, '苍老师', '女', '1987-12-30 00:00:00', '18219876577', NULL, 9);
INSERT INTO `beauty` VALUES (3, 'Angelababy', '女', '1989-02-03 00:00:00', '18209876567', NULL, 3);
INSERT INTO `beauty` VALUES (4, '热巴', '女', '1993-02-03 00:00:00', '18209876579', NULL, 2);
INSERT INTO `beauty` VALUES (5, '周冬雨', '女', '1992-02-03 00:00:00', '18209179577', NULL, 9);
INSERT INTO `beauty` VALUES (6, '周芷若', '女', '1988-02-03 00:00:00', '18209876577', NULL, 1);
INSERT INTO `beauty` VALUES (7, '岳灵珊', '女', '1987-12-30 00:00:00', '18219876577', NULL, 9);
INSERT INTO `beauty` VALUES (8, '小昭', '女', '1989-02-03 00:00:00', '18209876567', NULL, 1);
INSERT INTO `beauty` VALUES (9, '双儿', '女', '1993-02-03 00:00:00', '18209876579', NULL, 9);
INSERT INTO `beauty` VALUES (10, '王语嫣', '女', '1992-02-03 00:00:00', '18209179577', NULL, 4);
INSERT INTO `beauty` VALUES (11, '夏雪', '女', '1993-02-03 00:00:00', '18209876579', NULL, 9);
INSERT INTO `beauty` VALUES (12, '赵敏', '女', '1992-02-03 00:00:00', '18209179577', NULL, 1);
jobs 表创建代码
CREATE TABLE `jobs` (
`job_id` VARCHAR(10) ,
`job_title` VARCHAR(35) ,
`min_salary` INT(6) ,
`max_salary` INT(6)
) ;
INSERT INTO `jobs` VALUES ('AC_ACCOUNT', 'Public Accountant', 4200, 9000);
INSERT INTO `jobs` VALUES ('AC_MGR', 'Accounting Manager', 8200, 16000);
INSERT INTO `jobs` VALUES ('AD_ASST', 'Administration Assistant', 3000, 6000);
INSERT INTO `jobs` VALUES ('AD_PRES', 'President', 20000, 40000);
INSERT INTO `jobs` VALUES ('AD_VP', 'Administration Vice President', 15000, 30000);
INSERT INTO `jobs` VALUES ('FI_ACCOUNT', 'Accountant', 4200, 9000);
INSERT INTO `jobs` VALUES ('FI_MGR', 'Finance Manager', 8200, 16000);
INSERT INTO `jobs` VALUES ('HR_REP', 'Human Resources Representative', 4000, 9000);
INSERT INTO `jobs` VALUES ('IT_PROG', 'Programmer', 4000, 10000);
INSERT INTO `jobs` VALUES ('MK_MAN', 'Marketing Manager', 9000, 15000);
INSERT INTO `jobs` VALUES ('MK_REP', 'Marketing Representative', 4000, 9000);
INSERT INTO `jobs` VALUES ('PR_REP', 'Public Relations Representative', 4500, 10500);
INSERT INTO `jobs` VALUES ('PU_CLERK', 'Purchasing Clerk', 2500, 5500);
INSERT INTO `jobs` VALUES ('PU_MAN', 'Purchasing Manager', 8000, 15000);
INSERT INTO `jobs` VALUES ('SA_MAN', 'Sales Manager', 10000, 20000);
INSERT INTO `jobs` VALUES ('SA_REP', 'Sales Representative', 6000, 12000);
INSERT INTO `jobs` VALUES ('SH_CLERK', 'Shipping Clerk', 2500, 5500);
INSERT INTO `jobs` VALUES ('ST_CLERK', 'Stock Clerk', 2000, 5000);
INSERT INTO `jobs` VALUES ('ST_MAN', 'Stock Manager', 5500, 8500);
locations 表创建代码
CREATE TABLE `locations` (
`location_id` INT(11) ,
`street_address` VARCHAR(40) ,
`postal_code` VARCHAR(12) ,
`city` VARCHAR(30) ,
`state_province` VARCHAR(25) ,
`country_id` VARCHAR(2)
) ;
INSERT INTO `locations` VALUES (1000, '1297 Via Cola di Rie', '00989', 'Roma', NULL, 'IT');
INSERT INTO `locations` VALUES (1100, '93091 Calle della Testa', '10934', 'Venice', NULL, 'IT');
INSERT INTO `locations` VALUES (1200, '2017 Shinjuku-ku', '1689', 'Tokyo', 'Tokyo Prefecture', 'JP');
INSERT INTO `locations` VALUES (1300, '9450 Kamiya-cho', '6823', 'Hiroshima', NULL, 'JP');
INSERT INTO `locations` VALUES (1400, '2014 Jabberwocky Rd', '26192', 'Southlake', 'Texas', 'US');
INSERT INTO `locations` VALUES (1500, '2011 Interiors Blvd', '99236', 'South San Francisco', 'California', 'US');
INSERT INTO `locations` VALUES (1600, '2007 Zagora St', '50090', 'South Brunswick', 'New Jersey', 'US');
INSERT INTO `locations` VALUES (1700, '2004 Charade Rd', '98199', 'Seattle', 'Washington', 'US');
INSERT INTO `locations` VALUES (1800, '147 Spadina Ave', 'M5V 2L7', 'Toronto', 'Ontario', 'CA');
INSERT INTO `locations` VALUES (1900, '6092 Boxwood St', 'YSW 9T2', 'Whitehorse', 'Yukon', 'CA');
INSERT INTO `locations` VALUES (2000, '40-5-12 Laogianggen', '190518', 'Beijing', NULL, 'CN');
INSERT INTO `locations` VALUES (2100, '1298 Vileparle (E)', '490231', 'Bombay', 'Maharashtra', 'IN');
INSERT INTO `locations` VALUES (2200, '12-98 Victoria Street', '2901', 'Sydney', 'New South Wales', 'AU');
INSERT INTO `locations` VALUES (2300, '198 Clementi North', '540198', 'Singapore', NULL, 'SG');
INSERT INTO `locations` VALUES (2400, '8204 Arthur St', NULL, 'London', NULL, 'UK');
INSERT INTO `locations` VALUES (2500, 'Magdalen Centre, The Oxford Science Park', 'OX9 9ZB', 'Oxford', 'Oxford', 'UK');
INSERT INTO `locations` VALUES (2600, '9702 Chester Road', '09629850293', 'Stretford', 'Manchester', 'UK');
INSERT INTO `locations` VALUES (2700, 'Schwanthalerstr. 7031', '80925', 'Munich', 'Bavaria', 'DE');
INSERT INTO `locations` VALUES (2800, 'Rua Frei Caneca 1360 ', '01307-002', 'Sao Paulo', 'Sao Paulo', 'BR');
INSERT INTO `locations` VALUES (2900, '20 Rue des Corps-Saints', '1730', 'Geneva', 'Geneve', 'CH');
INSERT INTO `locations` VALUES (3000, 'Murtenstrasse 921', '3095', 'Bern', 'BE', 'CH');
INSERT INTO `locations` VALUES (3100, 'Pieter Breughelstraat 837', '3029SK', 'Utrecht', 'Utrecht', 'NL');
INSERT INTO `locations` VALUES (3200, 'Mariano Escobedo 9991', '11932', 'Mexico City', 'Distrito Federal,', 'MX');
job_grades 表创建代码
CREATE TABLE job_grades(
grade_level VARCHAR(3),
lowest_sal INT,
highest_sal INT
);
INSERT INTO job_grades
VALUES ('A', 1000, 2999);
INSERT INTO job_grades
VALUES ('B', 3000, 5999);
INSERT INTO job_grades
VALUES('C', 6000, 9999);
INSERT INTO job_grades
VALUES('D', 10000, 14999);
INSERT INTO job_grades
VALUES('E', 15000, 24999);
INSERT INTO job_grades
VALUES('F', 25000, 40000);