sql 交集、并集

-- 并集
SELECT member_uuid FROM (
SELECT
    mm.member_uuid
FROM
    `merchant_member` mm
    INNER JOIN merchant_member_tag_has_member mmthm ON mmthm.member_uuid = mm.member_uuid AND mmthm.merchant_member_tag_uuid IN ("1","2")
WHERE
    mm.merchant_uuid = "qt-001"
UNION
SELECT
    mm.member_uuid
FROM
    `merchant_member` mm
    INNER JOIN merchant_member_group_has_member mmthm ON mmthm.member_uuid = mm.member_uuid AND mmthm.merchant_member_group_uuid IN ("470d66695535e2f0172f06194fa1ed34","a5b8b7cad6ecb06aa1c6830d6210483b")
WHERE
    mm.merchant_uuid = "qt-001"
) a limit 1

-- 交集
SELECT member_uuid FROM (
SELECT
    mm.member_uuid
FROM
    `merchant_member` mm
    INNER JOIN merchant_member_tag_has_member mmthm ON mmthm.member_uuid = mm.member_uuid AND mmthm.merchant_member_tag_uuid in ("1","2")
WHERE
    mm.merchant_uuid = "qt-001"
UNION ALL
SELECT
    mm.member_uuid
FROM
    `merchant_member` mm
    INNER JOIN merchant_member_group_has_member mmthm ON mmthm.member_uuid = mm.member_uuid AND mmthm.merchant_member_group_uuid in ("470d66695535e2f0172f06194fa1ed34","a5b8b7cad6ecb06aa1c6830d6210483b")
WHERE
    mm.merchant_uuid = "qt-001"
) a GROUP BY member_uuid HAVING COUNT(member_uuid) >=4 limit 1