0

I have a table which is some thing like below..

Date             ID

 2009-07-01            1
 2009-07-01            2
 2009-07-01            3
 2009-08-01            4
 2009-08-01            5
 2009-08-01            6
 2009-09-01            7
 2009-09-01            8
 2009-10-01            9
 2009-10-01            10
 2009-11-01            11

....

Now I need to write a query which will show a output like below.

Date               Start            End
2009-07              1               3
2009-08              4               6
2009-09              7               8

...

How can I do this.. Any help would be highly appreciated Thanking In Advance Johnny

0

3 Answers 3

3
    tableData.GroupBy(i => i.Date).Select(i => new
          {
              DateTime = i.Key,
              Start = i.Min(j => j.ID),
              End = i.Max(j => j.ID)
          });
Sign up to request clarification or add additional context in comments.

1 Comment

I'd consider changing the projection lambda variable to something other than i to avoid confusion. 'g' for example.
0

This might be what you're looking for:

var a = from myObj in db.MyObjs
        group myObj by myObj.Date.ToString("yyyy-mm")
            into ymGroup
            select new { Date = ymGroup.Key, Start = ymGroup.Min(c => c.ID), End = ymGroup.Max(c => c.ID) };

Comments

0

i am not an expert in this but you can try the following code

var yourRows = _entities.YourTable.Where(colid => ((colid.Id == 3) || (colid.Id == 6) || (colid.Id == 8)));
return View(yourRows);

hope it works for you!!

take care

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.