Sql重复记录查询

时间:2014-01-21 03:21:41

标签: c# mysql sql linq

我有两张桌子。

  1. MasterStudent(student_number,姓名,地址,dob)
  2. 登机点(boardingID,student_number,部门数量)
  3. 我想在生日那天得到重复的学生,但我不知道如何获得重复的记录。我是sql的新手。我试过这个问题:

    SELECT T.GivenName + ' ' + T.SurName AS Name,
      T.StreetNumber + ' ' + T.StreetName + ' ' + T.Suburb + ' ' + T.PostCode + ' ' + T.State + ' ' + T.Country AS Address,
      T.Sex, 
      T.DateOfBirth,
      T.yearlevel AS Year,
      z.dupCount,
      T.StudentNumber
    FROM tblMasterStudent AS T
    INNER JOIN (SELECT DateOfBirth, COUNT(*) AS dupCount
                FROM tblMasterStudent
                GROUP BY DateOfBirth
                HAVING (COUNT(*) > 1)) AS z ON z.DateOfBirth = T.DateOfBirth
                ORDER BY z.dupCount DESC
    

    它是从MasterStudent表中获取生日的重复记录,但我想从masterStudent + BoardingPoint获取记录

1 个答案:

答案 0 :(得分:0)

您可以按生日分组并查看多次出现的所有生日:

SELECT count(1) as frequency, dob
FROM students
GROUP BY dob
HAVING frequency > 1;