gpt4 book ai didi

mysql - 如何根据字段 `time`中的值添加新列

转载 作者:太空宇宙 更新时间:2023-11-03 10:49:13 25 4
gpt4 key购买 nike

我有 table :

+--------+--------------+-----------+   
| person |.....DAY......| ....hours |
| Name1 ....2014-01-08... 03:53:23 |
| Name2 ....2014-01-08... 05:30:54 |
+--------|--------------|-----------+

如何根据时间字段中的值添加新列 label?如果时间从 05:00:00 到 11:00:00,则该值为 '1',否则为 '0'。它应该看起来像这样:

+---------+--------------+-----------+---------+  
| person |.....DAY......| ..hours | label |
| Name1 ....2014-01-08... 03:53:23 | 0 ......|
| Name2 ....2014-01-08... 05:30:54 | 1.......|
+---------+--------------+----------+----------+

最佳答案

你可以用这样的东西

update table set label = case when hour(hours) between 5 and 10 then 0 else 1 end;

关于mysql - 如何根据字段 `time`中的值添加新列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26781453/

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