SQL求 交集 并集 差集
故事是这样的…..
故事情节: 表 tb_test 有两列, colA , colB; 求 colA , colB 的并交差集…
-- 计算并集 SELECT DISTINCT colB FROM tb_test UNION SELECT DISTINCT colA FROM tb_test
-- 计算交集 SELECT DISTINCT colB FROM tb_test INTERSECT SELECT DISTINCT colA FROM tb_test
-- 计算差集 SELECT DISTINCT colB FROM tb_test EXCEPT SELECT DISTINCT colA FROM tb_test