Sql northwind中产品区域信息的选择

Sql northwind中产品区域信息的选择,sql,northwind,Sql,Northwind,我想在northwind数据库中执行以下操作: 显示客户在CA中放置的所有产品的产品名称 但我不知道如何将产品与客户联系起来 试试这个: Select o.pdt_name From orders o Where o.cust_no in (Select c.cust_no From customers c Where c.state = 'CA') order by o.pdt_name 试试这个: Select o.pdt_name From orders o Where o.cu

我想在northwind数据库中执行以下操作:

显示客户在CA中放置的所有产品的产品名称 但我不知道如何将产品客户联系起来

试试这个:

Select o.pdt_name From orders o 
Where o.cust_no in 
 (Select c.cust_no From customers c Where c.state = 'CA')
order by o.pdt_name
试试这个:

Select o.pdt_name From orders o 
Where o.cust_no in 
 (Select c.cust_no From customers c Where c.state = 'CA')
order by o.pdt_name

根据我的记忆,您需要将
产品
表加入到
订单
订单详情
客户
表中,以获得客户在
CA
中订购的产品列表:

select distinct p.ProductName
from customers c
inner join orders o
  on c.customerId = o.customerId
inner join orderDetails od
  on o.orderId = od.orderid
inner join products p
  on od.productid = p.productid
where c.Region = 'CA'
或者您可以使用
EXISTS

select p.ProductName
from products p
where exists (select od.productid
              from customers c
              inner join orders o
                on c.customerId = o.customerId
              inner join orderDetails od
                on o.orderId = od.orderid 
              where c.Region = 'CA'
                and p.productid = od.productid)

请参阅这两个查询的列表。

根据我的记忆,您需要将
产品
表加入到
订单
订单详细信息
客户
表中,以获取客户在
CA
中订购的产品列表:

select distinct p.ProductName
from customers c
inner join orders o
  on c.customerId = o.customerId
inner join orderDetails od
  on o.orderId = od.orderid
inner join products p
  on od.productid = p.productid
where c.Region = 'CA'
或者您可以使用
EXISTS

select p.ProductName
from products p
where exists (select od.productid
              from customers c
              inner join orders o
                on c.customerId = o.customerId
              inner join orderDetails od
                on o.orderId = od.orderid 
              where c.Region = 'CA'
                and p.productid = od.productid)

请参阅这两个问题的答案。

以下内容为我完成了任务

Select distinct Products.ProductName From Products 
Where Products.ProductID in 
 (Select [Order Details].ProductID From [Order Details] Where [Order Details].OrderID in(select Orders.OrderID from Orders where Orders.CustomerID in(select Customers.CustomerID from Customers where Customers.Region='CA')))
 order by Products.ProductName;

我做了这项工作

Select distinct Products.ProductName From Products 
Where Products.ProductID in 
 (Select [Order Details].ProductID From [Order Details] Where [Order Details].OrderID in(select Orders.OrderID from Orders where Orders.CustomerID in(select Customers.CustomerID from Customers where Customers.Region='CA')))
 order by Products.ProductName;
要按产品名称升序列出结果,请将此项添加到末尾

ORDER BY PRD.PRODUCTNAME ASC 
要按产品名称升序列出结果,请将此项添加到末尾

ORDER BY PRD.PRODUCTNAME ASC 

回忆。。使用Northwinds
?@AarolamaBluenk yup,旧数据库:@不是真的,只是浪费时间!我们要在网上找到更好的事情做。回忆。。使用Northwinds
?@AarolamaBluenk yup,旧数据库:@不是真的,只是浪费时间!我们必须在互联网上找到更好的事情做。