开发者

In mysql how do I find rows repeating with respect to all fields?

开发者 https://www.devze.com 2022-12-16 19:34 出处:网络
+------------+------------+ student| department | +------------+------------+ 1234567890 | CS| 1234567890 | ME|
+------------+------------+
| student    | department |
+------------+------------+
| 1234567890 | CS         | 
| 1234567890 | ME         | 
| 1234567890 | CS         | 
| 000000001  | ME         | 
+------------+------------+

How can I get ro开发者_如何学Pythonws that are repeating with respect to both fields?

Thanks in advance.


It should be something like

SELECT  student,
    department      
FROM    Table
GROUP BY student, department
HAVING COUNT(*) > 1


SELECT student, department, count(*) as 'count' 
FROM students
GROUP BY student, department
HAVING count > 1
+------------+------------+-------+
| student    | department | count |
+------------+------------+-------+
| 1234567890 | CS         | 2     |
+------------+------------+-------+


SELECT * 
FROM mytable
GROUP BY student, department
HAVING COUNT( * ) > 1;
0

精彩评论

暂无评论...
验证码 换一张
取 消