首页 > 解决方案 > LIKE 与 SUBSTR 一起使用时不返回任何记录

问题描述

我有两张桌子:

教练生涯

coach_id | start      | end 
  483368   2017-01-01   NULL

比赛季节

coach_id     | name 
   483368      2017/2018

我写了查询:

 SELECT * FROM coach_career cr
          INNER JOIN competition_seasons s
          ON SUBSTR(cr.start, 1, 4) = s.name
          WHERE cr.id = 483368

本质上,我需要返回以可用字段start年份作为值的教练,我曾经只提取年份,问题是该查询不返回任何记录。namecompetition_seasonSUBSTR

标签: mysqlsql

解决方案


如果两者都是字符串值,

SUBSTR(cr.start, 1, 4) 等于“2017”。

s.name = "2017/2018"。

2 个值不相等。


推荐阅读