我试图在多个列中找到数据库中的重复行。
以下SQL查询为我提供了247行的结果
select Lastname, EmailAddress, count(*)
from leads where EmailAddress IS NOT null and isDeleted <> 'True'
group by lastname, emailaddress having count(*) > 1
我认为vb.net中的以下内容应返回相同数量的行,但我得到201个结果。
Dim duplicates = db.Leads.Where(Function(p) p.EmailAddress <> Nothing
And p.isDeleted <> True)
.GroupBy(Function(i) New With {i.EmailAddress, i.LastName})
.Where(Function(g) g.Count() > 1)
.[Select](Function(g) g.Key)
它们不能同时返回相同的行数吗?
答案 0 :(得分:1)
试试这个语法:
Dim duplicates = From p In db.leads Where
p.EmailAddress <> Nothing And
p.isDeleted <> True Group By
p.EmailAddress, p.LastName Into
grp = Group Where (grp.Count() > 1)