2013-08-29 53 views
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; 

樣本內容:如何更新WHERE子句以選擇相同的數據? DB表

表 「附表」

aircraftType = "320" 

表 「飛機」

aircraftType = "A320" 
aircraftType = "A330" 

查詢:

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

如何以這種方式更新此查詢,以便在WHERE子句中將aircratf類型「320」和「A320」視爲相似?

+0

Shoudnt你更新相同的數據列? – Mihai

+0

@Mihai不,我只需要選擇相同的數據,無需進一步更新。 –

回答

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

OR

LIKE CONCAT('\"','%', F.aircraftType, '%','\"')-added double quotes. 
+0

它說截斷不正確的DOUBLE值:'%' –

+0

現在試一下,剛編輯。 – Mihai

+0

嗯0行填充 –

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 

但最好的解決辦法是更新相同關係字符串的數據。