太在意别人的看法,最后会有两种结局:要么自己累死,要么让别人整死
create database scort
use scort
create table emp
(
empno int primary key,
ename nvarchar(10),
sal int,
deptno int
)
insert into emp values (7369,'smith',3000,20);
insert into emp values (7499,'allen',1500,50);
insert into emp values (7566,'jones',2000,30);
insert into emp values (7654,'martin',5000,10);
insert into emp values (7698,'blake',1800,30);
create table dept
(
deptno int primary key,
dname nvarchar(10),
loc nvarchar(10)
)
insert into dept values (10,'accounting','new york');
insert into dept values (20,'research','dallas');
insert into dept values (30,'sales','chicago');
insert into dept values (40,'operations','boston');
create table salgrade
(
grade int primary key,
lostl int,
hisal int
)
insert into salgrade values (1,700,1200);
insert into salgrade values (2,1201,1400);
insert into salgrade values (3,1401,2000);
insert into salgrade values (4,2001,3000);
insert into salgrade values (5,3001,6000);
解释:
除了在FROM子句中使用逗号间隔连接的表外,SQL还支持另一种被称为交叉连接的操作,它们都返回被连接的两个表所有数据行的笛卡尔积,返回到的数据行数等于第一个表中符合查询条件的数据行数乘以第二个表中符合查询条件的数据行数。惟一的不同在于,交叉连接分开列名时,使用CROSS JOIN关键字而不是逗号。
两张表连接:
select * from emp,dept
where emp.deptno=dept.deptno
--等价于
select * from emp cross join dept
where emp.deptno=dept.deptno
三张表连接:
select * from emp,dept,salgrade
where emp.deptno=dept.deptno and
(emp.sal>salgrade.lostl and emp.sal"S".lostl and "E".sal<"S".hisal)
本篇博客来自于郝斌老师视频教程的总结以及笔记的整理,仅供学习交流,切勿用于商业用途,如有侵权,请联系博主删除,博主QQ:194760901