gpt4 book ai didi

c# - SQL重复记录查询

转载 作者:行者123 更新时间:2023-11-30 00:47:25 25 4
gpt4 key购买 nike

我有两张 table 。

  1. MasterStudent(学号、姓名、地址、出生日期)
  2. 登机点(boardingID、student_number、区间数)

我想在生日之前获取重复的学生,但我不知道如何获取重复的记录。我是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 获取记录

最佳答案

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

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

关于c# - SQL重复记录查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21248501/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com