Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8078637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:51:30+00:00 2026-06-05T15:51:30+00:00

My user activity log looks something like this: Id, Username, Date I need to

  • 0

My user activity log looks something like this:

Id, Username, Date

I need to calculate the total number of entries per day, and most active user of that day for the last 10 days.

//pseudo code
from entry in data.UserLogs
group by entry.Date == each day
select username of most active user, count(Id)

Im new to LINQ and SQL can someone help me complete this query?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:51:32+00:00Added an answer on June 5, 2026 at 3:51 pm

    I think this is what you are after. Just drop it into LINQPad to see it in action

    void Main()
    {
        var logs = new List<UserLog>
            {
                new UserLog { Id= 1, Date = new DateTime(2012,1,1), Username = "cburgdorf"},
                new UserLog { Id= 2, Date = new DateTime(2012,1,1), Username = "cburgdorf"},
                new UserLog { Id= 3, Date = new DateTime(2012,1,1), Username = "cburgdorf"},
                new UserLog { Id= 4, Date = new DateTime(2012,1,1), Username = "Mister Foo"},
                new UserLog { Id= 5, Date = new DateTime(2012,1,1), Username = "Mister Foo"},
                new UserLog { Id= 6, Date = new DateTime(2012,1,2), Username = "Mister Bar"},
                new UserLog { Id= 7, Date = new DateTime(2012,1,2), Username = "Mister Bar"},
                new UserLog { Id= 8, Date = new DateTime(2012,1,2), Username = "cburgdorf"},
                new UserLog { Id= 9, Date = new DateTime(2012,1,2), Username = "Mister Foo"},
                new UserLog { Id= 10, Date = new DateTime(2012,1,2), Username = "Mister Foo"},
                new UserLog { Id= 11, Date = new DateTime(2012,1,2), Username = "Mister Foo"},
                new UserLog { Id= 12, Date = new DateTime(2012,1,2), Username = "Mister Bar"}
            };
    
        logs
            .OrderByDescending (l => l.Date)
            .GroupBy (log => log.Date)      
            .Select (log => log
                            .GroupBy (l => l.Username)
                            .Select (l => new 
                            {
                                Count = l.Count (),
                                Value = l.FirstOrDefault (),
                            })
                            .OrderBy (l => l.Count).Last ())
            .Select (log => new 
            {
                Date = log.Value.Date,
                Count = log.Count,
                Username = log.Value.Username
            })
            .Take(10)
            .Dump();
    
            //In LINQPad use Dump() to see the results:
            /*
                logs
                    .OrderByDescending (l => l.Date)
                    .GroupBy (log => log.Date)      
                    .Select (log => log
                                    .GroupBy (l => l.Username)
                                    .Select (l => new 
                                    {
                                        Count = l.Count (),
                                        Value = l.FirstOrDefault (),
                                    })
                                    .OrderBy (l => l.Count).Last ())
                    .Select (log => new 
                    {
                        Date = log.Value.Date,
                        Count = log.Count,
                        Username = log.Value.Username
                    })
                    .Take(10)
                    .Dump();
            */
    
    
    }
    
    class UserLog
    {
        public int Id {get;set;}
        public DateTime Date {get;set;}
        public string Username {get;set;}
    }
    
    
    The result is:
    
        02.01.2012 00:00:00 | 3 | Mister Foo 
        01.01.2012 00:00:00 | 3 | cburgdorf 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying create a log specifically for logging user account activity. I created this
To provide an activity log in my SQLAlchemy-based app, I have a model like
Is there A good strategy to Log the User activity on an ASP MVC
I am looking for a way to log user activity on my site. I've
I have a couple of tables which are used to log user activity for
My application crashes on customer's machine. It leaves entries in Windows event log like
I have one main Activity with layout wrapped into ScrollView like this: <ScrollView android:layout_height=wrap_content
I'm adding activity log to a busy website, which should show user the last
For tracking user activity, I am using a Windows Hook for the main application
To track user activity history on a web application, I am attempting to save

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.