上一章 说了下 子查询的意义是 把一条查询语句当做值来使用 select *from car //查询汽车的信息 假设我知道一个汽车的编号是 c021 但是我要查询 比这个汽车价格高的汽车信息 先找到汽车编号是c021的 select *from car where code='c021' 在找这个汽车的价格 select price from car where code='c021' //返回的是价格这个值 这个值是 31.75 那么我要找比这个价格高的汽车信息…
一.SQL子查询语句 1.单行子查询 select ename,deptno,sal from emp where deptno=(select deptno from dept where loc='NEW YORK'): 2.多行子查询 SELECT ename,job,sal FROM EMP WHERE deptno in ( SELECT deptno FROM dept WHERE dnam…
1.独立子查询:顾名思义:就是子查询和外层查询不存在任何联系,是独立于外层查询的: 下面就看一个例子: 有一张订单表 Sales.Order 和一张 客户表 Sales.Customer 下面的sql 语句是为了查询出Sales.Customer里 custid(用户id)不在 Sales.Order 的custid select custid from [Sales.Customers] where custid not in ( select custid from [Sales.Order…
sql调优方法: (1)not in子查询优化 尽量避免子查询select * from a where id not in(select id from b); select * from a where not exists(select id from b WHERE id ='100') 建议使用表连接: select * from a left join b on a.id=b.id WHERE b.id='100'…