我有一个查询如下:
select q.question, e.filename
from question q
join actions a on a.FK_QId = q.PK_Id
join action_params ap on ap.FK_AId = a.PK_Id
join envfile e on e.FK_Qid = ap.value
where e.EnvType = 0
问题是where is varchar and is integer的JOIN ON
子句。我知道我必须做点什么,但我尝试过的失败:e.FK_Qid = ap.value
value
FK_QId
CAST
CONVERT
select q.`question`, e.filename
from question q
join actions a on a.FK_QId = q.PK_Id
join action_params ap on ap.FK_AId = a.PK_Id
join envfile e on CAST(e.FK_Qid as nvarchar(3)) = ap.value
where e.EnvType = 0
基本上,该value
字段将包含“1”、“2”等字符串。因此,如果我可以进行字符串到字符串的比较或 int 到 int 的转换,那就没问题了。底线是"1" = 1
等等"2" = 2
。
编辑:CAST(e.FK_Qid as char3) = ap.value
工作得很好..