- テーブル
[Orders] : OrderID(Primary Key), CustomerID
- テーブル
[Order Details] : OrderID(Primary Key), ProductID(Primary Key), Discount
- テーブル
[Customers] : CustomerID[Primary Key]
productID
これら 3 つのテーブルを使用して、それぞれの割引が最も高いクエリを実行したいと考えていますCustomerID
。ProductID
、CustomerID
およびの列が必要Discount
です。どうすればこの問題を解決できますか? あらゆる種類の助けを本当に感謝しています。
私が試した次のスクリプト:
select ProductID, a.customerID,
(select MAX(discount)
from [Order Details]
where a.CustomerID=c.customerID
)
from Orders a
join [Order Details]
on a.OrderID=[Order Details].OrderID
join Customers c
on a.CustomerID=c.CustomerID
order by customerID