我試圖添加一個條目,這取決於MySQL中另一個表中的現有條目:但「解決方案」(我從之前詢問的另一個問題得到)不是我的數據正確地工作,我不知道爲什麼......根據MYSQL第二部分中另一個表中的現有條目添加一個條目
下面是我從解決問題:
Add an entry depending on existing entry in another table with MYSQL
這裏是我的查詢,我創建必要的表和導入數據:
CREATE TABLE `EMailImport` (user_id VARCHAR(20), `E-Mail` VARCHAR(150));
LOAD DATA LOCAL INFILE 'C:/Users/xyz/Desktop/X/export.csv'
INTO TABLE `EMailImport`
FIELDS TERMINATED BY ';'
LINES TERMINATED BY '\n';
DELETE FROM `EMailImport` LIMIT 1;
CREATE INDEX X ON `EMailImport` (`E-Mail`);
CREATE TABLE ABC AS SELECT customerID, ordernumber, `customersEmail`
FROM orders GROUP BY `customersEmail`;
CREATE INDEX Y ON ABC (`customersEmail`);
這裏有2個查詢我想(我曾經在溶液):兩者都是工作
SELECT ABC.*, CASE WHEN `customersEmail` IN (SELECT `E-Mail` FROM EMailImport) THEN 'Yes' ELSE 'No' end AS `Did the customer ordered already?` FROM ABC;
SELECT ABC.*,CASE WHEN EXISTS (SELECT * FROM EMailImport WHERE EMailImport.`E-Mail` = ABC.`customersEmail`) then 'yes' else 'no' end as `Did the customer ordered already?` from ABC;
,但他們告訴我「沒有」爲每個條目(什麼是不正確的):哪裏是錯誤/問題?
Info
:表ABC中列的數據類型爲:customerID = int(10); ordernumber = varchar(50),customersEmail = varchar(255);
ABC是否包含有效數據? –
是的,約300.00條目/行 – AbsoluteBeginner