I am working on northwind database.
There are nine employees in the database.
Each employee has his&her sales.
My aim is to return the top most of the sales they have done. so there will be nine results.
below script returns all the sales they did, which I could not return the top most sales.
select e.firstname+' '+e.lastname as [Worker], p.productname as [Top most saled product], r.quantity*r.unitprice as [Price] from employees as e
inner join orders as o on e.employeeid=o.employeeid
inner join [order details] as r on r.orderid=o.orderid
inner join products as p on p.productid= r.productid
where o.shippeddate is null order by [Price] desc
go
help please.

Kumar SaurabhPosted Nov 16, 2012, 3:42 AM
If I have understood your question clearly - SQL Query - as per me would go as below-
Explanation- First Part of the Query gives me the Unique combination of Employees and their all sales based on Employee Name and Product Name.
Then,I have used CTE to retrieve the max amount for each of the Employee.
Let me know , if this was the desired out put.
Turkalp KucurPosted Nov 17, 2012, 10:17 PM
Turkalp KucurPosted Nov 15, 2012, 9:42 PM
What I need is, I need to return the each person's best salary. The number of return value will be nine.
Suthish NairPosted Nov 15, 2012, 6:20 AM
Turkalp KucurPosted Nov 14, 2012, 4:42 PM
it returns the only one record...
What I need is, I need to obtain each employee's best salary. There are nine employees in total. Thus, query must return nine top most record.
venkata kumarPosted Nov 14, 2012, 12:24 AM
fallow the fallowing query
Thanks & Regards
Ravi9