1
CREATE TABLE `schedule` (
  `id` smallint(6) NOT NULL AUTO_INCREMENT,
  `aircraftType` varchar(50) DEFAULT NULL,
//...other fields
  PRIMARY KEY (`id`),
) ENGINE=MyISAM AUTO_INCREMENT=5611 DEFAULT CHARSET=latin1;

CREATE TABLE `aircrafts` (
  `id` smallint(6) NOT NULL AUTO_INCREMENT,
  `aircraftType` varchar(50) DEFAULT NULL,
//...other fields
  PRIMARY KEY (`id`),
) ENGINE=MyISAM AUTO_INCREMENT=5611 DEFAULT CHARSET=latin1;

数据库表的示例内容:

表“时间表”

aircraftType = "320"

表“飞机”

aircraftType = "A320"
aircraftType = "A330"

询问:

SELECT *
FROM Schedule F, Aircrafts A
WHERE F.aircraftType = A.aircraftType;

如何更新此查询,以使 aircratf 类型“320”和“A320”在 WHERE 子句中被视为相似?

4

2 回答 2

1
 SELECT *
FROM Schedule F, Aircrafts A
WHERE F.aircraftType = A.aircraftType LIKE CONCAT('%', F.aircraftType, '%')

或者

LIKE CONCAT('\"','%', F.aircraftType, '%','\"')-added double quotes.
于 2013-08-29T13:56:38.450 回答
0

尝试使用SUBSTRING()切割第一个字符:

SELECT *
FROM Schedule F, Aircrafts A
WHERE F.aircraftType = SUBSTRING(A.aircraftType, 2)

或者像@Mihai 建议的那样,只需放置%其中没有的字段A

SELECT *
FROM Schedule F, Aircrafts A
WHERE CONCAT('%', F.aircraftType) LIKE A.aircraftType

但最好的解决方案是更新相同关系字符串的数据。

于 2013-09-07T09:36:57.860 回答