I need to retrieve the rows based on last recent year.
I’ve attached the table structure, I need to retrieve records from most recent year for each customer_website
Here in the table, amazon.com is repeating 3 times where, 2 records are in 2019 and 1 record is in 2020. So I need retrieve only 2020 record
For the given table output must be (10, 2, 3, 4, 5, 7, 8)
TIA!
>Solution :
The below query returns the customer_website , customer_name from table which is the most recent year.
SELECT customer_website, customer_name
FROM table
WHERE (customer_website, YEAR(date)) IN (
SELECT customer_website, MAX(YEAR(created_date))
FROM your_table
GROUP BY customer_website
);