1、嵌套子查询.sql

来自「本代码简单明了」· SQL 代码 · 共 102 行

SQL
102
字号
--嵌套子查询


简单子查询的的例子
select (select 3) from jobs


功能实现:查找包含从伦敦供应的产品的订单价格明细信息
	从[伦敦]供应的[产品]的[订单价格明细信息]


入手点-->伦敦


第一步:找伦敦的供应商
第二步:查出产品编号
第三步:获得产品的明细信息


计算机实现:
第一步:
select supplierid from suppliers 
where city='London'

select productid from products 
where supplierid = 

select * from [order details]
where productid in 




然后组合

USE nothwind
GO
select * from [order details]
where productid 
in
(select productid from products 
where supplierid=
(select supplierid from suppliers 
where city='London')
)















--测试

--功能:查找员工Robert.King的客户的全部信息


select * from employees










--三个步骤:

select employeeID from employees 
where firstname = 'Robert' and lastname = 'King'

select customerid from orders where employeeid = 7 

select * from customers 
where customerid in ()



--整合
select * from customers 
where customerid in 
(
    select customerid from orders 
    where employeeid = 
    (
	select employeeID from employees 
	where firstname = 'Robert' and lastname = 'King'
    )
)


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?