1
Reply

OVER SqlFunction with LINQ

ezequiel campos

ezequiel campos

Aug 23 2012 7:14 AM
1.7k
I have a list of items and I need to list it by the intervals.

This is the data:
number
1
2
3
9
10
15
18
19
20
21

I have this query:
SELECT MIN(number) AS range_start,
       MAX(number) AS range_end,
       COUNT(number)
FROM (
SELECT number,
       number - ROW_NUMBER() OVER(ORDER BY number) AS grp
FROM Table AS A
) AS T
GROUP BY grp;

which results this:
range_start  | range_end | count
        1                3             3
        9               10             2
        15             15             1   
        18             21             4

How can I do that with LINQ?

Answers (1)