Mysql 逐个显示带有重复StudentId的验证消息
我想检查sql server中的重复Id验证,即验证网格显示 来自sql server的行号、验证消息和重复ID 我不明白我该怎么做 帮助真的很感激 创建表Mysql 逐个显示带有重复StudentId的验证消息,mysql,sql,Mysql,Sql,我想检查sql server中的重复Id验证,即验证网格显示 来自sql server的行号、验证消息和重复ID 我不明白我该怎么做 帮助真的很感激 创建表 CREATE TEMPORARY TABLE IF NOT EXISTS Tbl_Student (RowID INT PRIMARY KEY auto_increment, StudentID BIGINT); 插入记录 Insert into Tbl_Student(RowID,StudentID) values (1
CREATE TEMPORARY TABLE IF NOT EXISTS Tbl_Student
(RowID INT PRIMARY KEY auto_increment, StudentID BIGINT);
插入记录
Insert into Tbl_Student(RowID,StudentID) values (1,101)
Insert into Tbl_Student(RowID,StudentID) values (2,102)
Insert into Tbl_Student(RowID,StudentID) values (3,101)
Insert into Tbl_Student(RowID,StudentID) values (4,102)
Insert into Tbl_Student(RowID,StudentID) values (5,103)
如果有任何解决方案,请与我们分享
谢谢这是T-SQL代码,您可能需要将其转换为MySql格式:
Select * from(
Select RowId, Count(*) Over(Partition By StudentId Order By RowId) as Cnt From [YourTable]
) as K
Where Cnt>1
您也可以使用行数
或计数
聚合函数来实现相同的结果
以下是大量解决此问题的MySql解决方案:
要显示副本,我将执行以下操作:
select
RowID,
concat('Student ', StudentID, ' is duplicate') as StudentID
from Tbl_Student where StudentID in (
select StudentID from Tbl_Student group by StudentID having count(*) > 1
)
请尝试以下查询
SELECT RowID, CONCAT('StudentID ',StudentID, ' is Duplicate) AS Error FROM Tbl_Student WHERE StudentID IN (SELECT StudentID FROM Tbl_Student GROUP BY StudentID HAVING COUNT(*) > 1)
您可以在suquery上使用一个连接,使strundet id的计数大于1
select id, student_id, concat('Stundent id' , student_id, ' is duplicated')
from my_table m
inner join (
select student_id
from my_table
group by student_id
having count(*) > 1
) t on t.student_id = m.student_id
它是mysqlsyntex@GordonLinoff如果有任何可用的解决方案,您可以共享sql server代码syntaxNo prevention不适用于此处,我必须仅为学生显示验证消息。在您的示例101中没有重复。。expalin更好的可能的副本