非常好奇的問題。當我放棄'國家'似乎解決了這個問題。
SELECT DISTINCT PostalCode, City, Region
總共128個,查詢花費0.0066秒
SELECT DISTINCT PostalCode, City, Region, Country
209總計,查詢花費0.0002秒
此外,行爲似乎隻影響ImportCustomers
和ImportOrders
:
SELECT postalcode, city, region, country
FROM
(SELECT postalcode, city, region, country FROM importcustomers
UNION
SELECT shippostalcode, shipcity, shipregion, shipcountry FROM importorders) t
172總計,查詢花費0.0053秒
SELECT postalcode
FROM
(SELECT postalcode FROM importcustomers
UNION
SELECT shippostalcode FROM importorders) t
91總計,查詢花費0.0050秒
我然後它縮小到country
列上importcusotmers
和importorders
SELECT TRIM(country) AS country FROM importcustomers
UNION
SELECT TRIM(shipcountry) AS country FROM importorders
Argentina
Argentina
Austria
Austria
Belgium
Belgium
...
Someth荷蘭國際集團有趣的事,當我投的列BINARY
SELECT BINARY country AS country FROM importcustomers
UNION
SELECT BINARY shipcountry AS country FROM importorders
Argentina
417267656e74696e610d
Austria
417573747269610d
Belgium
42656c6769756d0d
...
表ImportOrders
導致了重複。
SELECT BINARY shipcountry AS country FROM importorders
4765726d616e790d
5553410d
5553410d
4765726d616e790d
...
看着你提供的轉儲,不存在附加到該國的最後一個額外的\r
(由0d
中的值表示)。
--
-- Dumping data for table `importorders`
--
INSERT INTO `importorders` VALUES
...'Germany\r'),
...'USA\r'),
...'USA\r'),
...'Germany\r'),
...'Mexico\r'),
凡importcustomers
的country
看起來不錯:
--
-- Dumping data for table `importcustomers`
--
INSERT INTO `importcustomers` VALUES
...'Germany', ... ,
...'Mexico', ... ,
...'Mexico', ... ,
...'UK', ... ,
...'Sweden', ... ,
您可以通過運行該查詢刪除這些\r
的(回車):
UPDATE importorders SET ShipCountry = REPLACE(ShipCountry, '\r', '')
然後,您將得到如果您運行原始查詢,則需要的結果集。僅供參考,如果您使用UNION
,則不需要DISTINCT
。
SELECT PostalCode, City, Region, Country
FROM
(SELECT postalcode, city, region, country FROM importemployees
UNION
SELECT postalcode, city, region, country FROM importcustomers
UNION
SELECT postalcode, city, region, country FROM importproducts
UNION
SELECT shippostalcode as postalcode, shipcity as city,
shipregion as region, shipcountry as country FROM importorders) T
你是什麼意思重複?列或整行? –
區分大小寫? –
我的意思是重複的行。值在相同的行中看起來完全相同。可以前。表中的不同字符集/排序規則(或從csv導入時)會觸發此操作? –