What about:
SELECT pid, COUNT(DISTINCT fl) AS count, GROUP_CONCAT(DISTINCT fl) list
FROM test_set
GROUP BY pid HAVING count > 1;
?
Output:
+------+-----------+------------------+
| pid | count | list |
+------+-----------+------------------+
| 1 | 3 | 30,31,35 |
| 2 | 2 | 39,40 |
+------+-----------+------------------+
Given two fl
values:
SELECT pid, COUNT(DISTINCT fl) AS count
FROM test_set
WHERE fl IN (30, 35)
GROUP BY pid HAVING count = 2;
Output:
+------+-------+
| pid | count |
+------+-------+
| 1 | 2 |
+------+-------+
Given three fl
values:
SELECT pid, COUNT(DISTINCT fl) AS count
FROM test_set
WHERE fl IN (30, 31, 35)
GROUP BY pid HAVING count = 3;
Output:
+------+-------+
| pid | count |
+------+-------+
| 1 | 3 |
+------+-------+
It's good to have indexes on pid
and fl
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…