开发者

linq group by with count

Im trying to write query in linq

Select UserId, UserNumber 
FROM User
where UserNumber in
(Select UserNumber
        FROM User
        group开发者_Python百科 by UserNumber
        having Count(UserId) = 1)

Aby hints ?


var query = from u in User
            group u by u.UserNumber into usergroup
            where usergroup.Count() == 1
            from item in usergroup
            select new { item.UserId,item.UserNumber };


If subqueries are your thing, you could do it this way.

var subquery =
  from u in User
  group u by u.UserNumber into g
  where g.Count() = 1
  select g.Key;

var query =
  from u in User
  where subquery.Any(num => num == u.UserNumber)
  select u;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜