GROUP By and Having count in LinQ

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

Hi

How can i do this:

SELECT Name, COUNT(*) AS Num
FROM Table1
GROUP BY Name
HAVING COUNT(*)>1

What would be the equivalent:
var lst=from cust in datacontext.customer ....

Any idea?

Thanks
 
Hi

How can i do this:

SELECT Name, COUNT(*) AS Num
FROM Table1
GROUP BY Name
HAVING COUNT(*)>1

What would be the equivalent:
var lst=from cust in datacontext.customer ....

Any idea?


Don't have the code, but subset the count(*) > 1 and join it to your
main query to filter that way. Grouping is fairly easy.

group x by x into y

for example. This link hits the grouping:
http://msdn.microsoft.com/en-us/vcsharp/aa336754.aspx#simple1

I saw a good workaround for having (to subset) yesterday, but I cannot
find it in my history today ... at least not yet. If I find it, I will
post. I know I found it through a google search, however.

Peace and Grace,


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

My vacation and childhood cancer awareness site:
http://www.crazycancertour.com

*******************************************
| Think outside the box! |
*******************************************
 
Back
Top