Count max(date)

Posted on 2009-07-16
Last Modified: 2013-11-11
Need help with a linq query

                var bpa = from ga in dbg.Stats
                          where ga.UId == usr
                            && ga.Date >= dBegin && ga.Date < dEnd
                          group ga by new { ga.Date.Day } into gr
                          select new
                              name = gr.Key.Day,
                              value = gr.Max(z => z.Date)

But "value" gets a date, the "value" should contain the total count of hits with that date.

Thank's in advanced
Question by:dingir
  • 3

Author Comment

ID: 24867801
Rising pooints because it's important.
LVL 12

Expert Comment

ID: 24867811
try changing the max to count

Author Comment

ID: 24867922
Thank's but i need to take the latest date for each result.

the table looks like
Date               UId
2009-01-01    10
2009-01-05    10
2009-01-04    10
2009-01-01    8
2009-01-01    10
2009-01-04    7
2009-01-02    4
2009-01-03    9

I need a query that takes all 2009-01-05 and count those results.
Which means result:
topdate count
2009-01-01 3
2009-01-02 1
2009-01-03 1
2009-01-04 2
2009-01-05 1


Author Comment

ID: 24868243
Whatever and however I describe it. I need a query like this (this is a new another school sample taken from web)

   var categories =
      from p in products
      group p by p.Category into g
      select new {
           Category = g.Key,
           MostExpensivePrice = g.Max(p => p.UnitPrice)

...that returns the count of existing "g.Max(p => p.UnitPrice)". Not the latest date itself.
LVL 15

Accepted Solution

jinal earned 450 total points
ID: 24870147

var bpa = from ga in dbg.Stats
                          where ga.UId == usr
                            && ga.Date >= dBegin && ga.Date < dEnd
                          group ga by new { ga.Date.Day } into gr
                          select new
                              name = gr.Key.Day,
                              value = gr.Count()

Open in new window


Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Needing an event fired when a row is added on a datagridview 4 45
VB.Net How to Exit Sub - Exit Form??? 5 57
Replace &lt; with < 14 59
Need a starter for ETL protocol? 4 55
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Sending a Secure fax is easy with eFax Corporate ( First, just open a new email message. In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now