I am trying to get the sum(comprate) for only max(effdt) having max(id) from the following query,
SELECT id, employee_code, effdt, comprate
FROM dbo.employees_compensation
WHERE (employee_code = '000321514')
ORDER BY effdt desc, id desc
Result of above query is as follows,
id employee_code effdt comprate
1473433 000321514 2010-09-02 00:00:00.000 46000
1473432 000321514 2010-09-02 00:00:00.000 138000
1453627 000321514 2010-09-02 00:00:00.000 46000
1453626 000321514 2010-09-02 00:00:00.000 138000
1447165 000321514 2010-09-02 00:00:00.000 46000
1447164 000321514 2010-09-02 00:00:00.000 138000
1424948 000321514 2010-09-02 00:00:00.000 46000
1424947 000321514 2010-09-02 00:00:00.000 138000
1405789 000321514 2010-09-02 00:00:00.000 46000
1405788 000321514 2010-09-02 00:00:00.000 138000
I tried many queries but I am not getting the expected result. What I want is the top first two values from above result i.e,
id employee_code effdt comprate
1473433 000321514 2010-09-02 00:00:00.000 46000
1473432 000321514 2010-09-02 00:00:00.000 138000
and then get the sum(comprate) from the above result i.e,
sum(comprate)
184000
Could you help me in getting the expected result? Thanks in Advance.