talendguy talendguy - 5 months ago 26
SQL Question

SQL query last transactions

enter image description here

You can't see on the image but I have many till_id numbers. (1,2,3,4,5).

What I want to do is just showing the last "trans_num" without repeating the till_id.

For example:

till_id trans_num
1 14211
2 14333
3 14555


A typical way to do this is:

select t.*
from t
where t.trans_date = (select max(t2.trans_date)
                      from t t2 
                      where t2.till_id = t.till_id