如何仅显示数据网格中的所有重复行 [英] How to show all duplication row in data grid only

查看:76
本文介绍了如何仅显示数据网格中的所有重复行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的:

好​​友



请你好好问问题



i有一个表(id,Civilidd,名称,地址),并且在Civilidd上有重复我想让datagridview向我显示重复记录的所有行,我将选择我要删除的内容。 />


i使用sql server和C#



我尝试过:



i尝试用这个代码做这个回合它给了我一个行号我不想要那个,我想看第一行和第二行



Dear:
friends

please im not good in asking questions

i have one table (id , Civilidd , name , address ), and have duplication on it with Civilidd i want to make the datagridview to show me all rows of the duplicate records and i will choose what i want to deleted.

i use sql server and C#

What I have tried:

i try to do that with this code bout it gave me a row number i don't want that, i want to see the first and the second rows

<pre> with tablctc as
(
select * , ROW_NUMBER() over (partition by CIVILIDD order by CIVILIDD ) as RowNumber
from tabl1
)
select * from tablctc where RowNumber>1 AND (CIVILIDD IS NOT NULL)







热情的问候




warm regards

推荐答案

这是一个基于格里推荐的例子。我根据发布的内容猜测它。首先,找出哪个行有重复然后捕获Id。之后,使用Row_Number查询包含重复ID的原始表。希望有所帮助。



Here is an example based on Gerry recommendation. I'm guessing it based on what posted here. First, find out which row has duplicate then capture the Id. After that, query the original table which contain the duplicate id with Row_Number. Hope that help.

DECLARE @temp1 TABLE (
	Civilidd INT , 
	[Name]	VARCHAR(50) , 
	[Address]	 VARCHAR(50)
)

INSERT INTO @temp1
	SELECT 1, 'a1', 'address 1' UNION
	SELECT 1, 'a1 x 2', 'address 1 x 2' UNION
	SELECT 1, 'a1 x 3', 'address 1 x 3' UNION
	SELECT 2, 'a2', 'address 1' UNION
	SELECT 3, 'a2', 'address 1' UNION
	SELECT 3, 'a2 x 2', 'address 3 x 2' UNION
	SELECT 4, 'a4', 'address 4'

;WITH cteCount AS (
	SELECT Civilidd FROM @temp1
	GROUP BY Civilidd
	HAVING COUNT(Civilidd) > 1
) SELECT t.* , ROW_NUMBER() over (partition by t.CIVILIDD order by t.CIVILIDD ) as RowNumber
	FROM @temp1 t JOIN cteCount cc ON t.Civilidd = cc.Civilidd



输出


Output:

Civilidd	Name	Address	        RowNumber
1	         a1	address 1	1
1	         a1 x 2	address 1 x 2	2
1	         a1 x 3	address 1 x 3	3
3	         a2	address 1	1
3	         a2 x 2	address 3 x 2	2


在CivilId上只有COUNT。



如果COUNT> 1,你有一个或多个副本。
Just COUNT on CivilId.

If the COUNT > 1, you have one or more duplicates.


这篇关于如何仅显示数据网格中的所有重复行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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