我有以下表格
**Order**
- Id (int)
- OrderDate (datetime)
- OrderNumber (nvarchar)
- CustomerId (int)
- TotalAmount (decimal)
**OrderItem**
- Id (int)
- OrderId (int)
- ProductId (int)
- UnitPrice (decimal)
- Quantity (int)
**Product**
- Id (int)
- ProductName (nvarchar)
- SupplierId (int)
- UnitPrice (decimal)
- Package (nvarchar)
- IsDiscontinued (bit)
**Supplier**
- Id (int)
- CompanyName (nvarchar)
- ContactName (nvarchar)
- ContactTitle (nvarchar)
- City (nvarchar)
- Country (nvarchar)
- Phone (nvarchar)
- Fax (nvarchar)
我需要找出包含从单个国家/地区提供的产品的所有订单。任何帮助赞赏。
答案 0 :(得分:0)
请尝试这个可能会有所帮助
select * from (
select * from (
select ROW_NUMBER() over(partition by s.Country order by s.Country) RowNo,o.* from [order] as o
inner join OrderItem as oi on o.Id = oi.OrderId
inner join Product as p on ProductId = p.Id
inner join Supplier as s on p.SupplierId = s.Id
) as t
where RowNo > 1
) as t
right join [order] as o on t.Id = o.Id
where t.Id is null