fork download
  1. CREATE TABLE sem_attendance
  2. (`attendance_id` int, `sid` int, `pid` int)
  3. ;
  4.  
  5. INSERT INTO sem_attendance
  6. (`attendance_id`, `sid`, `pid`)
  7. VALUES
  8. (1, 1, 3),
  9. (6, 1, 12),
  10. (8, 2, 12),
  11. (9, 4, 12),
  12. (10, 1, 23),
  13. (11, 3, 23),
  14. (12, 1, 29),
  15. (13, 3, 27),
  16. (14, 2, 24),
  17. (15, 3, 21),
  18. (16, 2, 21),
  19. (17, 1, 27),
  20. (18, 2, 27),
  21. (19, 5, 23)
  22. ;
  23.  
  24. SELECT * FROM sem_attendance
  25. WHERE pid IN (
  26. SELECT pid
  27. FROM sem_attendance
  28. GROUP BY pid
  29. HAVING COUNT(1) >= 3
  30. )
  31. AND pid IN (
  32. SELECT a.pid FROM sem_attendance a
  33. JOIN sem_attendance b
  34. ON a.pid = b.pid
  35. AND a.sid = b.sid + 1
  36. );
  37.  
Success #stdin #stdout 0s 3444KB
stdin
Standard input is empty
stdout
6|1|12
8|2|12
9|4|12
13|3|27
17|1|27
18|2|27