I have a dataframe like this
Value. | Date |
---|---|
A | 08/08/2009 |
A | 09/12/2021 |
A | 05/10/2022 |
A | 06/09/2022 |
A | 07/08/2022 |
I need output like
VALUE | DATE |
---|---|
A | 05/10/2022 |
A | 06/09/2022 |
A | 07/08/2022 |
We have to print a latest year with all month data present in the date column .please refer output table.
i used SQL query like
Select Top 10 * from table where
Order by (Date) DESC;
The max() select only one date so that didn’t help me
But didn’t get expected answer.
Can please someone help me with the query ?
2
Answers
You can just use
MAX
in a subquery, this will produce the intended outcome you have shown in your question:The latest year is 2022, so
MAX
in the subquery will find this year and the whole query will select all dates in 2022.To improve this query you’d have an index by
datecolumn
(or where this column is an expression prefix).