C#Linq在Datatable中查找类似的行 [英] C# Linq Finding Similar Rows in Datatable

查看:494
本文介绍了C#Linq在Datatable中查找类似的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有一个数据表,其中包括3个结论行(C)和1个决策行(D)。我希望使用LINQ找到具有相似结论值但不同决策值的行。我怎样才能做到这一点?感谢您的帮助。

例如:

 SetName:C1-C2-C3-D 
Set1:1-2 -2-3
Set2:2-1-1-2
Set3:1-2-2-2



.....

这里的结果是Set1和Set3。

解决方案

你可以用计算机理解的术语来定义相似。我不知道你将如何做到这一点,并且为了使事情复杂化,它将取决于你如何将这些数据存储在数据库中。如果数据库必须操纵(更改)每条记录上的数据,以确定您将破坏查询性能。


我认为这解决了我的问题。

SELECT C1,C2,C3 FROM

(选择C1,C2,C3,D FROM< datatable> GROUP BY C1,C2,C3,D)AS A

GROUP BY C1,C2,C3

有计数(C1)> 1

Hello all, I have a datatable which includes 3 conclusion rows (C) and 1 decision row (D). I want to find rows with similar conclusion values but different decision value using LINQ. How can I achieve this? Thanks for the help.
For example:

SetName :C1-C2-C3-D
Set1    :1-2-2-3
Set2    :2-1-1-2
Set3    :1-2-2-2


.....
Here the result is Set1 and Set3.

解决方案

You hvae to define "similar" in terms that the computer will understand. I have no idea how you're going to do that and, to complicate things, it's going to depend on how you store this data in the database. If the database has to manipulate (change) the data on every record to make a determination you're going to kill the query performance.


I think this solves my problem.
SELECT C1,C2,C3 FROM
(SELECT C1,C2,C3,D FROM <datatable> GROUP BY C1,C2,C3,D ) AS A
GROUP BY C1,C2,C3
HAVING COUNT(C1)> 1


这篇关于C#Linq在Datatable中查找类似的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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