I need to get 1 row back with sum of some values by max date. But these 2 rows were updated by different persons, but only need to show the latest updated by person id.
My query is:
select v.code, sum(v.a_lines), sum(v.b_lines),
v.updated_by, f.period, max(v.updated_on)
from f_values v, f_file f where
v.file_id = f.id
and v.code= '100002'
and
to_char(f.period,'MM/DD/YYYY') = '03/31/2011'
group by v.code, v.updated_by, f.period
This returns 2 rows:
102 30 100 xxx 31-MAR-11 10-AUG-11
102 50 200 yyy 31-MAR-11 07-OCT-11
Now we need to return only 1 row. Something like this:
102 80 3000 yyy 31-Mar-11 07-Oct-11
I know that this can be achieved by removing “updated_by” from the column, but I need to have it populated, but it only needs to be the most recent updated_by row (‘yyy’). Hope my question is clear
Please let know if this is possible. Thanks in advance
Harish
Got it to work by using
But this query does not work on HQL, so had to change to SQL query. If anyone can help on the HQL equivalent, that would be awesome.
Thanks