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 SaurabhRank #1,193 · 1.5K reputationPosted Nov 15, 2012, 10:42 PM EST
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.
venkata kumarRank #5,034 · 314 reputationPosted Nov 13, 2012, 7:24 PM EST
fallow the fallowing query
Thanks & Regards
Ravi9
Turkalp Kucur47 reputationPosted Nov 14, 2012, 11:42 AM EST
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.
Suthish NairRank #92 · 22.8K reputationPosted Nov 15, 2012, 1:20 AM EST
Turkalp Kucur47 reputationPosted Nov 15, 2012, 4:42 PM EST
What I need is, I need to return the each person's best salary. The number of return value will be nine.
Turkalp Kucur47 reputationPosted Nov 17, 2012, 5:17 PM EST