Top N query never finishes processing.

Status
Not open for further replies.

PaulCL

New Member
Joined
Jul 9, 2014
Messages
43
I have a table(Orders) with 5 million records that also contains 250 unique groups(Markets). I am trying to apply a Top N query to retrieve the top 3 records(FirmNames), based on TotalVolume, from each unique group. My current query never finishes running. Is there a more efficient way to retrieve these top 3 records? Thanks

SELECT Orders.Market, Orders.TotalVolume, Orders.FirmName INTO [Top 3 Luxury Market Final]
FROM Orders
WHERE (((Orders.TotalVolume) In (SELECT TOP 3 TotalVolume
FROM Orders AS Dupe
WHERE Dupe.Market = Orders.Market
ORDER BY Dupe.TotalVolume DESC, Dupe.FirmName DESC)))
ORDER BY Orders.Market, Orders.TotalVolume DESC , Orders.FirmName;
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Status
Not open for further replies.

Forum statistics

Threads
1,221,841
Messages
6,162,331
Members
451,759
Latest member
damav78

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top