Hi I have a table with the following fields:
- Customerid
- Customerpaydate
- Amount
I need help in retrieving most recent transaction but no repetition in of customer ID.
I would appreciate your help
Hi I have a table with the following fields:
I need help in retrieving most recent transaction but no repetition in of customer ID.
I would appreciate your help
To pull out the most recent transaction par customer, a correlated subquery should get the job done:
select t.*
from mytable t
where customerpaydate = (
select max(Customerpaydate) from mytable t1 where t1.customerid = t.customerid
)
This will give you the max paydate
SELECT MAX(customerpaydate) as d
FROM table
This will give you the max paydate by customer
SELECT customerid, max(customerpaydate) as d
FROM table
GROUP BY customerid
The will give you the most recent transaction
SELECT *
FROM TABLE
where customerpaydate = (SELECT MAX(customerpaydate) as d FROM table)
This will give you the most recent transaction of each customer
SELECT *
FROM TABLE
JOIN (
SELECT customerid, max(customerpaydate) as d
FROM TABLE
GROUP BY customerid
) AS S ON S.customerid = TABLE.customerid and S.d = TABLE.customerpaydate