I'm using Databricks and I have a table with a list of event from various years. I want to return the event most recent to today's date from each year. For example,
Today's date is 6th May and my table is thus:
|Year (int)|Date (date)|Event (str)|
|----------|-----------|-----------|
|2021 |2021-08-04|Ate apple|
|2021 |2021-04-16|Flew plane|
|2020 |2020-10-11|Swam 100 miles|
|2020 |2020-03-07|Did backflip|
|2020 |2020-01-01|Tidied room|
|2019 |2019-09-30|Found 10 pence|
|2018 |2018-02-22|Lost 10 pence|
So I would want to return:
**On this day in history your most recent achievements were:**
|Year|Date|Event|
|----|----|-----|
|2021|2021-04-16|Flew plane|
|2020|2020-03-07|Did backflip|
|2018|2018-02-22|Lost 10 pence|
Is there a neat way of doing this?...and by neat I mean, without creating extra columns or tables i.e. by comparing CURRENT_DATE to my Date field.
Asked by ben_al
(1 rep)
May 6, 2022, 12:01 PM
Last activity: May 6, 2022, 03:00 PM
Last activity: May 6, 2022, 03:00 PM