れ螻 螳 蟆曙 .
use tempdb
go
select * into test_details from Northwind..[Order Details]
Go
create index idx_test
on test_details(ProductID, UnitPrice)
Go
select * into test from Northwind..Products
Go
create index idx_test
on test(ProductID)
go
--蟆郁骸
ProductID Max_UnitPrice
----------- ---------------------
1 18.0000
2 19.0000
3 10.0000
4 22.0000
5 21.3500
6 25.0000
7 30.0000
8 40.0000
9 97.0000
10 31.0000
朱朱 覿覿 れ 螳 蟆曙 螳 SQL 襦 譯朱 燕. 讌襷 願 80%企. Index襯 豕 伎 朱 Hash Match/Cache 一一 伎覃 譟一語 襯 譴 .
--貎朱Μ2
select
a.ProductID
, Max(b.UnitPrice) Max_UnitPrice
from test a inner join test_details b
on a.ProductID = b.ProductID
where a.ProductID <= 10
group by a.ProductID
Go
--'test_details' 企. れ 10, 朱Μ 所鍵 20, 覓朱Μ 所鍵 0, 覩碁Μ 所鍵 0.
--'test' 企. れ 1, 朱Μ 所鍵 1, 覓朱Μ 所鍵 0, 覩碁Μ 所鍵 0.