I only want all the list_id
and item
from max of purchase_date.
Based on the sample data above, I want to get the below records only.
I tried
select distinct
customer_id,
category_id,
max(purchase_date) as max_date,
list_id,
item
from A
group by customer_id, category_id, list_id, item
and
select distinct
A.customer_id,
A.category_id,
B.max_date,
A.list_id,
A.item
from A
join (
select distinct
customer_id,
category_id,
max(purchase_date) as max_date
from A
group by customer_id, category_id
) B on A.customer_id = B.customer_id
and A.category_id = B.category_id
and A.purchase_date = B.max_date
they both don't work.