我有一张叫做登记的桌子。学生A有3条记录,其中两条记录具有相同的start_date。
我想在postgres中找到所有具有相同2013年开学日期的学生。
报名:
StudentID Start_Date Syear school_id
1 2013-06-21 2013 10
1 2013-06-21 2013 11
1 2014-02-21 2014 10
提前致谢。
答案 0 :(得分:1)
SELECT StudentID, Start_Date
FROM
(
SELECT StudentID, Start_date, COUNT(*) OVER (PARTITION BY start_date) count
FROM Student
)
WHERE count > 1
或
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
)