有一个数据库表格,包含了roleA, roleB两个字段,写了一个SQL,相同的roleA,但是roleB不一样,同时roleb不一样的数量要大于2 ;
SELECT roleA
FROM your_table_name
GROUP BY roleA
HAVING COUNT(DISTINCT roleB) > 2;
SELECT roleA, roleB
FROM your_table_name
WHERE roleA IN (
SELECT roleA
FROM your_table_name
GROUP BY roleA
HAVING COUNT(DISTINCT roleB) > 2
);