在Memsql中执行以下查询时,收到以下消息:
“ MemSQL Distributed不支持功能'带有未在下推查询中分片的子选择的联合'。”
SELECT *
FROM customer_campaigns t45 LEFT OUTER JOIN (SELECT
t164.source_entity_id AS source_entity_id,
t164.destination_entity_id AS destination_entity_id,
t164.status AS STATUS
FROM campaign_mirror_references t164 INNER JOIN
mirror_configurations t160
ON ((t164.mirror_config_id = t160.id) AND
(t160.is_sync = 1))
INNER JOIN customer_campaigns t45
ON (t45.campaign_id = t160.source_campaign_id)
WHERE (t45.cust_profile_id = 416)
UNION DISTINCT SELECT
t164.source_entity_id AS source_entity_id,
t164.destination_entity_id AS destination_entity_id,
t164.status AS STATUS
FROM
campaign_mirror_references t164 INNER JOIN
mirror_configurations t160 ON (
(t164.mirror_config_id = t160.id) AND
(t160.is_sync = 1) AND
(t160.dest_profile_id = 416))) AS SOURCE
ON ((t45.campaign_id = SOURCE.source_entity_id) AND (SOURCE.status <> 2))
答案 0 :(得分:0)
是否要求将其编写为单个查询?为了提高可读性并简化嵌套,您可以尝试制作一个临时表然后从中进行选择吗?这样应该会获得与上面相同的效果,但是更容易理解:
DROP TABLE IF EXISTS tmpCampaignMirrorRefs;
CREATE TEMPORARY TABLE tmpCampaignMirrorRefs AS
SELECT t164.source_entity_id AS source_entity_id
, t164.destination_entity_id AS destination_entity_id
, t164.status AS STATUS
FROM campaign_mirror_references t164
INNER JOIN mirror_configurations t160 ON t164.mirror_config_id = t160.id
AND t160.is_sync = 1
WHERE t45.cust_profile_id = 416
UNION
SELECT t164.source_entity_id AS source_entity_id
, t164.destination_entity_id AS destination_entity_id
, t164.status AS STATUS
FROM campaign_mirror_references t164
INNER JOIN mirror_configurations t160 ON t164.mirror_config_id = t160.id
AND t160.is_sync = 1
AND t160.dest_profile_id = 416
;
SELECT *
FROM customer_campaigns t45
LEFT OUTER JOIN tmpCampaignMirrorRefs SOURCE ON t45.campaign_id = SOURCE.source_entity_id
AND SOURCE.status <> 2
;
让我知道是否还有其他问题-希望有帮助!
也是FWIW,在MemSQL中为UNION
== UNION DISTINCT