top N per employee

G

geebee

hi,

i have a table with lots of rows. I'm trying to pull out the top 10 records
by dollar amount by employee. i tried the following:

SELECT [employee], [amount]
FROM YourTable
WHERE amount=
(SELECT Top 10 amount
FROM YourTable as Temp
WHERE Temp.[employee] = YourTable.[employee]
ORDER BY amount DESC)

am i on the right track? what i want to retrieve is every employee, and the
top 10 amounts per employee.

thanks in advance,
geebee
 
R

raskew via AccessMonster.com

Try this -
**********************************************
SELECT DISTINCT
t.Employee
, YourTable.Amount
FROM
YourTable AS t
LEFT JOIN
YourTable
ON
t.Employee = YourTable.Employee
WHERE
(((YourTable.Amount) In (
SELECT
Top 10 [Amount]
FROM
YourTable
WHERE
[Employee]= t.[Employee]
ORDER BY
[Amount])))
ORDER BY
t.Employee
, YourTable.Amount DESC;
**********************************************
HTH - Bob
hi,

i have a table with lots of rows. I'm trying to pull out the top 10 records
by dollar amount by employee. i tried the following:

SELECT [employee], [amount]
FROM YourTable
WHERE amount=
(SELECT Top 10 amount
FROM YourTable as Temp
WHERE Temp.[employee] = YourTable.[employee]
ORDER BY amount DESC)

am i on the right track? what i want to retrieve is every employee, and the
top 10 amounts per employee.

thanks in advance,
geebee
 
K

Klatuu

Try:
SELECT [employee], [amount]
FROM YourTable
WHERE amount IN
((SELECT Top 10 amount
FROM YourTable as Temp
WHERE Temp.[employee] = YourTable.[employee]
ORDER BY amount DESC));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top