mysql 查询中别名 temp 返回 null
问题:在 mysql 查询中,使用以下语句查询别名为 temp 的列时,却返回了 null:
select str_to_date(plan_start_time, '%h:%i:%s') as temp,plan_start_time from base_stop_calendar
背景信息:
解答:
在提供的 sql 语句中,格式化字符 "%h" 用于表示小时(12 小时制)。然而,plan_start_time 列中存储的是 24 小时制的时间,因此使用 "%h" 会导致格式化失败,从而返回 null。
解决方案:
要正确地格式化计划开始时间,应该使用大写字母 "h" 来表示 24 小时制的时间。以下是修改后的 sql 语句:
select str_to_date(plan_start_time, '%h:%i:%s') as temp,plan_start_time from base_stop_calendar
使用此语句后,别名 temp 将返回格式正确的日期和时间。
以上就是MySQL 查询中别名 temp 为何返回 NULL?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号