我试图从以下查询中获取仅具有 max(id) 的 max(effdt) 的 sum(comprate),
SELECT id, employee_code, effdt, comprate
FROM dbo.employees_compensation
WHERE (employee_code = '000321514')
ORDER BY effdt desc, id desc
上述查询结果如下,
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
我尝试了很多查询,但没有得到预期的结果。我想要的是上面结果中的前两个值,即
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
然后从上面的结果中得到 sum(comprate) 即,
sum(comprate)
184000
你能帮我得到预期的结果吗?提前致谢。