在 db2 中的 table 中显示当前数据的所有 1 年回溯
display all the 1year back from current data in the table in db2
cid name dob(timstamp dtype)
101 x 11-02-2019
301 y 12-12-2019
901 z 21-07-2018
111 a 02-07-2020
这是我的table。我想从当前日期提取过去 1 年的记录。所以我的输出应该是
cid name dob
101 x 11-02-2019
301 y 12-12-2019
111 a 02-07-2020
在WHERE
子句中设置条件dob
大于当前日期减去1年:
select *
from tablename
where dob >= current_date - 1 year
如果你想要当前和上一年的所有行:
select *
from tablename
where year(current_date) - year(dob) in (0, 1)
参见demo。
您可以通过减去当前年份来获取记录。
select cid, from t1 where year(dob) = year(getdate())-1
cid name dob(timstamp dtype)
101 x 11-02-2019
301 y 12-12-2019
901 z 21-07-2018
111 a 02-07-2020
这是我的table。我想从当前日期提取过去 1 年的记录。所以我的输出应该是
cid name dob
101 x 11-02-2019
301 y 12-12-2019
111 a 02-07-2020
在WHERE
子句中设置条件dob
大于当前日期减去1年:
select *
from tablename
where dob >= current_date - 1 year
如果你想要当前和上一年的所有行:
select *
from tablename
where year(current_date) - year(dob) in (0, 1)
参见demo。
您可以通过减去当前年份来获取记录。
select cid, from t1 where year(dob) = year(getdate())-1