【问题标题】:Mysql: Using str_to_date on a select query returns nothingMysql:在选择查询上使用 str_to_date 不会返回任何内容
【发布时间】:2018-02-28 12:31:57
【问题描述】:

我正在关注 Mysql 查询:

select str_to_date((select distinct cast(substr(tb2.sub1,1,4) AS CHAR) as year from (
SELECT SUBSTRING_INDEX(file_name,'_',-1) as sub1 from table2) as tb2) , '%Y')

这是正确的,因为 mysqlworkbench 返回绿旗但没有输出。

你能帮帮我吗?

【问题讨论】:

  • 看不到源数据,很难判断
  • 没有输出?没有行?表示您的 SELECT ... from table2 没有得到任何结果。

标签: mysql str-to-date


【解决方案1】:

表达式

        select str_to_date('2007', '%Y')

返回2007-00-00。一些 MySQL 服务器设置为不允许 invalid dates。尝试使用

        select makedate('2007', 1) 

相反。这将为您提供2007-01-01 的有效日期。

我将由您来编辑您的查询以进行更改。

【讨论】:

    猜你喜欢
    • 2013-09-10
    • 1970-01-01
    • 1970-01-01
    • 2022-01-09
    • 2017-10-20
    • 2012-03-14
    • 1970-01-01
    • 1970-01-01
    • 2017-01-23
    相关资源
    最近更新 更多