Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有多个 SELECT 查询联合。复合主键可以防止重复,这就是我想要的。每当阻止从联合查询之一插入重复行时,是否有办法增加某个字段?
您可以使用UNION ALL保留重复项,然后将结果与外部查询分组:
UNION ALL
SELECT a, b, c, COUNT(*) FROM ( SELECT a, b, c FROM ... UNION ALL SELECT a, b, c FROM ... ) AS t GROUP BY a, b, c