SELECT * FROM A X WHERE NOT EXISTS(SELECT * FROM A Z WHERE EXISTS
( SELECT 账号,户名,开户行 FROM A WHERE 账号=Z.账号 AND 户名=Z.户名 AND 开户行=Z.开户行 GROUP BY 账号,户名,开户行 HAVING COUNT(*)>1)
AND 是否公有='公有' AND 账号=X.账号 AND 户名=X.户名 AND 开户行=X.开户行 AND 是否公有=X.是否公有)
SELECT 账号,户名,开户行,是否公有,用户ID
FROM A
WHERE A.ID IN ('000001','000002',...) -- ID参数条件
AND A.是否公有='私有'
UNION -- 与UNION ALL不同的是UNION 会自动去重复
SELECT 账号,户名,开户行,是否公有,用户ID
FROM A
WHERE A.ID IN ('000001','000002',...) -- ID参数条件
AND A.是否公有='公有'
AND A.ID NOT IN (SELECT ID FROM A WHERE A.是否公有='私有')