gpt4 book ai didi

mysql - SQL:最后一次出现的年份?

转载 作者:行者123 更新时间:2023-11-29 06:36:06 25 4
gpt4 key购买 nike

我怎样才能找到最后一次发生的日期和年份组合。所以,我有很长的日期列表,我需要输出最后发生的年份。

例如,假设 2018 年没有发生 31/12/2018,所以我想要 31/12/2017 作为输出?

Table:
Dates
01/03/2013
01/09/2012
01/03/2013
01/06/2011
03/03/2009
11/07/2011
01/03/2023
01/05/2021

Output:
01/03/2018
01/09/2018
01/03/2018
01/06/2018
03/03/2018
11/07/2018
01/03/2017
01/05/2017

最佳答案

这会对您有所帮助:

select t2.*,
(case when month(col) < month(current_date) or
(month(col) < month(current_date) and day(col) <= day(current_date))
then year(current_date)
else 1 + year(current_date)
end)
from table2 t2;

关于mysql - SQL:最后一次出现的年份?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53795637/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com