diff --git "a/20 \351\203\221\345\274\230\346\231\226/20230322 \344\275\234\344\270\232.md" "b/20 \351\203\221\345\274\230\346\231\226/20230322 \344\275\234\344\270\232.md" index 9f5fc9b9097b3d1193e7472107a5688a77af0c0a..0263e77eb7b580630f6c89b28a5942b525a03748 100644 --- "a/20 \351\203\221\345\274\230\346\231\226/20230322 \344\275\234\344\270\232.md" +++ "b/20 \351\203\221\345\274\230\346\231\226/20230322 \344\275\234\344\270\232.md" @@ -51,6 +51,7 @@ select b.id,a.price from price a join fruit b on a.id=b.price_id where name='苹 -- 3.3左外连接 -- 练习:查询所有水果信息和对应价格信息 +select * from fruit a left join price b on a.price_id=b.id; -- fruit f 位于left左边,称为左表,左外连接以左表为主 -- price p 位于left右边,称为右表 -- f.* :获取fruit水果表中的所有数据 @@ -64,6 +65,8 @@ select a.`name`,price from fruit a left join price b on a.price_id=b.id where pr -- 3.4右外连接 -- 练习:使用右外连接查询所有价格对应的水果名称和价格信息, +select * from fruit a right join price b on a.price_id=b.id; + -- right join 表示右连接 -- price p 称为右表 右外连接会查询右表即price表的全部数据以及和左表fruit f的交集 @@ -366,16 +369,15 @@ select b.id,b.ename,b.salary,a.jname,a.description,c.dname,c.loc from job a inne -- 2.确定连接查询的条件 :emp.job_id = job.id and emp.dept_id=dept.id -- 其他条件:e.salary between salarygrade.losalary and salarygrade.hisalary -- 3.确定要查询的结果字段 - SELECT b.id,b.ename,b.salary,a.jname,a.description,c.dname,c.loc,salarygrade.grade from - (select * from - job a - inner join - emp_b b on a.id=b.job_id - inner join - dept_b c on b.d_id=c.id) - UNION - (select * from salarygrade) - where salarygrade.grade in (select * from emp_b where (salary+bonus) between salarygrade.losalary and salarygrade.hisalary); +select emp_b.ename,emp_b.salary,job.jname,job.description,dept_b.dname,dept_b.loc,salarygrade.grade +from +emp_b,job,dept_b,salarygrade +where emp_b.job_id=job.id +and emp_b.d_id=dept_b.id +and emp_b.salary +between salarygrade.losalary +and salarygrade.hisalary; +