What I want here is to retrieve pid's that have these criteria:
pid
count is atleast 3 and sid
should atleast contain two numbers that are in sequence. For example sid should 1 & 2, 2 & 3, 3 & 4, and so on.
Table sem_attendance
attendance_id sid pid
1 1 3
6 1 12
8 2 12
9 4 12
10 1 23
11 3 23
12 1 29
13 3 27
14 2 24
15 3 21
16 2 21
17 1 27
18 2 27
19 5 23
My query:
SELECT attendance_id, sid, sem_attendance.pid
FROM sem_attendance
INNER JOIN (
SELECT pid
FROM sem_attendance
GROUP BY pid HAVING COUNT( pid ) =3)
temp ON sem_attendance.pid = temp.pid
ORDER BY temp.pid, sem_attendance.sid
attendance_id sid pid
6 1 12
8 2 12
9 4 12
10 1 23
11 3 23
19 5 23
17 1 27
18 2 27
13 3 27
Desired output should only be pid's 12 and 27 because the sid's 1, 3 and 5 are not in sequence. Is it possible to do this on mysql? If not, how about on php coding? Help me please.