我编写了以下脚本:
SELECT vil.account_id ,
vil.imp_id,
vil.owner ,
vil.start_date,
CASE
WHEN ac.status = 4
THEN status_date
ELSE NULL
END AS Live_date,
cs.country_code
FROM ACCOUNT ac
INNER JOIN vu_imp_list vil
ON vil.account_id = ac.account_id
INNER JOIN entity e
ON ac.entity_id = e.entity_id
INNER JOIN country_specifics cs
ON e.country_id = cs.country_id
WHERE ac.account_id IN
('000206789', '000207464', '000207696', '000207746')
AND
(vil.start_date =
(SELECT MIN(vils.start_date)
FROM vu_imp_list vils
WHERE vil.account_id = vils.account_id)
这将为imp_id
每个account_id
. 但是,它将忽略那些没有imp_id
. 因为有些account_ids
人没有imp_id
在餐桌上vu_imp_list
;WHERE's second condition
只会提取那些有对应start_date
和的记录imp_id
。简而言之,如果在 table 中找不到相应的记录,如何忽略此条件vu_imp_list
。我发现这篇文章与 MySQL 相关,但似乎有问题,因为我不断收到错误missing SELECT keyword
SELECT vil.account_id ,
vil.imp_id,
vil.owner ,
vil.start_date,
CASE
WHEN ac.status = 4
THEN status_date
ELSE NULL
END AS Live_date,
cs.country_code
FROM ACCOUNT ac
INNER JOIN vu_imp_list vil
ON vil.account_id = ac.account_id
INNER JOIN entity e
ON ac.entity_id = e.entity_id
INNER JOIN country_specifics cs
ON e.country_id = cs.country_id
WHERE ac.account_id IN
('000206789', '000207464', '000207696', '000207746')
AND
((vil.start_date =
(SELECT MIN(vils.start_date)
FROM vu_imp_list vils
WHERE vil.account_id = vils.account_id))
OR
NOT EXISTS
(vil.start_date = (SELECT MIN(vils.start_date)
FROM obi.vu_implementation_list vils
WHERE vil.ob10_account_id = vils.ob10_account_id)