此查询在 where 子句中给出错误 unknown column company。我发现 where 子句首先运行,然后 select 运行。这可能是这里的错误。但我不知道如何纠正这一点,以便让公司进入结果集。
SELECT trnsdriverid,
name,
(SELECT transcompany.name
FROM transcompany,
transcompdriver
WHERE transcompany.trnscompid = transcompdriver.trnscompid) AS 'company',
address,
dob,
license,
telephone
FROM transcompdriver
WHERE ? LIKE 'All'
OR name LIKE '%"+keyword+"%'
OR company LIKE '%"+keyword+"%'
OR trnsdriverid LIKE '%"+keyword+"%'