gpt4 book ai didi

mysql - 在mysql中将日期表转换为年份

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

嗨,我有表curriculum_vitae,其字段名为

    id int pk
user_id int
education_from date
education_to date.

它具有日期类型,现在我想将其更改为年份,并且只需将其移至新表(例如education_from_year和education_to_year)即可将其更改为year类型。我怎样才能做到这一点?

最佳答案

您可以避免转换。

对于 MySql 中的有效日期列,您可以使用 Year() 从日期获取年份值

 select  year(education_from) , year(education_to )
from your_table

如果您确实需要同一行上的冗余值,您可以使用

update your_table
set my_year_col_education_from = year(education_from),
my_year_col_education_to = year(education_to)

关于mysql - 在mysql中将日期表转换为年份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56815552/

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