【发布时间】:2018-07-04 16:07:34
【问题描述】:
我有一个数据表 (DT),我必须在指定列中选择重复值,并且在其他列上具有多个条件,并获取该行的 Id。 不幸的是,我是这方面的初学者。
我的数据表包含以下列:
Id, PartNo, Group
我在下面找到了这段代码,如果我想在一列中获取多个值,但我无法展开它。
Dim duplicates = From row In DT.AsEnumerable() _
.GroupBy(Function(i) i.Field(Of String)("PartNo")) _
.Where(Function(g) g.Count() > 1) _
.Select(Function(g) g.Key)
For Each dup In duplicates
Debug.Print(dup)
Next
所以我想
- get the "Id" values on those rows
- where ["Group"] LIKE "Assembly" OR ["Group"] LIKE "Part"
AND
- "PartNo" value can found more than once
示例: 在此表中,我想获得“Id”值:1、3、5、6、8
+----+--------+----------+
| Id | PartNo | Group |
+----+--------+----------+
| 1 | 1111 | Assembly |
| 2 | 1111 | Common |
| 3 | 2222 | Part |
| 4 | 2222 | Common |
| 5 | 2222 | Part |
| 6 | 1111 | Part |
| 7 | 3333 | Assembly |
| 8 | 2222 | Assembly |
+----+--------+----------+
谢谢
【问题讨论】:
标签: mysql vb.net linq datatable