Shweta
Well-known Member
- Joined
- Jun 5, 2011
- Messages
- 514
Hi All,
Below is the query I used to combine all records from UK_Sale and US_Sale Tables.
I got below table as a result of the above query:
<colgroup><col><col></colgroup><tbody>
</tbody>
Now from the above result I want to find out the fourth highest Sale along with employee name i.e. G with 2290. For this, I am thinking to use DISTINCT TOP 4 to get the top four records (as data is sorted) and then I will use MIN function to get the 4th record. but I am not sure how to apply this logic.
Kindly help.
Thanks in advance!
Regards,
Shweta Jain
Below is the query I used to combine all records from UK_Sale and US_Sale Tables.
Code:
select Emp_Name, sum(sales)as TotalSales
from uk_sale
group by emp_name
union all
select Emp_Name, sum(sales)as TotalSales
from us_sale
group by emp_name
order by TotalSales desc
I got below table as a result of the above query:
Emp_Name | TotalSales |
F | 4000 |
H | 3950 |
A | 2500 |
G | 2290 |
E | 1950 |
B | 500 |
C | 250 |
D | 200 |
<colgroup><col><col></colgroup><tbody>
</tbody>
Now from the above result I want to find out the fourth highest Sale along with employee name i.e. G with 2290. For this, I am thinking to use DISTINCT TOP 4 to get the top four records (as data is sorted) and then I will use MIN function to get the 4th record. but I am not sure how to apply this logic.
Kindly help.
Thanks in advance!
Regards,
Shweta Jain