如何在SQL Server表中找到重复值? [英] How type find duplicate value in SQL server table ?

查看:101
本文介绍了如何在SQL Server表中找到重复值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表格中找不到重复值



我尝试过:



SELECT(StudentFName +''+ StudentMName +''+ StudentLName)作为名称,FatherName,CONVERT(varchar(20),DOB,103)AS DOB,COUNT(*)TotalCount

FROM tblStudentAdmission_basic

GROUP BY StudentFName,StudentMName,StudentLName,FatherName,DOB

HAVING COUNT(*)< 1

ORDER BY COUNT(*)DESC

i can not find duplicate value in a table

What I have tried:

SELECT (StudentFName+' '+StudentMName+' '+StudentLName)as Name,FatherName,CONVERT(varchar(20),DOB,103)AS DOB,COUNT(*) TotalCount
FROM tblStudentAdmission_basic
GROUP BY StudentFName,StudentMName,StudentLName,FatherName,DOB
HAVING COUNT(*) < 1
ORDER BY COUNT(*) DESC

推荐答案

我看到的第一个问题是你数不到1;重复意味着大于1.



其次,由于这是家庭作业,我只会指出你正确的方向。下面的查询基于您的查询并检查重复的名称。



The first problem I see is you are counting less than 1; duplicates mean greater than 1.

Secondly, since this is homework, I'll only point you in the right direction. The query below is based off of yours and checks for duplicate names.

SELECT (StudentFName + ' ' + StudentMName + ' ' + StudentLName) AS Name, 
	COUNT((StudentFName + ' ' + StudentMName + ' ' + StudentLName)) AS NumberOfNames
FROM tblStudentAdmission_basic
GROUP BY StudentFName, StudentMName, StudentLName
HAVING (COUNT((StudentFName + ' ' + StudentMName + ' ' + StudentLName)) > 1)


这篇关于如何在SQL Server表中找到重复值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆