Reputation: 525
I have a table called enrollment. Student A has 3 records, with two of them have the same start_date.
I would like to find all the students with the same start date for the year 2013 in postgres.
Enrollment :
StudentID Start_Date Syear school_id
1 2013-06-21 2013 10
1 2013-06-21 2013 11
1 2014-02-21 2014 10
Thanks in advance.
Upvotes: 1
Views: 198
Reputation: 2173
SELECT StudentID, Start_Date
FROM
(
SELECT StudentID, Start_date, COUNT(*) OVER (PARTITION BY start_date) count
FROM Student
)
WHERE count > 1
or
SELECT StudentID, Start_Date
FROM Student S1
WHERE EXISTS (
SELECT *
FROM Student S2
WHERE S1.Start_Date = S2.Start_Date AND S1.StudentID <> S2.StudentID
)
Upvotes: 1