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

  • SEARCH
  • Home
  • 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 6590111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:15:33+00:00 2026-05-25T17:15:33+00:00

Can someone help me here with some hints. Basically I would like to apply

  • 0

Can someone help me here with some hints. Basically I would like to apply different aggregate functions (Count, Sum, Min) on different fields to the entire set (not really groupping), and return the results as fields in an anonymous type.
Something like:

var employees = new[] {
    new { Name = "John Smith", Gender="M", DateOfHiring=new DateTime(2004, 10, 22), Salary=60000 },
    new { Name = "Jane Smith", Gender="F", DateOfHiring=new DateTime(2008, 5, 22), Salary=55000 },
    new { Name = "Kathleen Smith", Gender="F", DateOfHiring=new DateTime(2006, 10, 22), Salary=75000 },
    new { Name = "David Smith", Gender="M", DateOfHiring=new DateTime(2002, 7, 12), Salary=85000 },
    new { Name = "Mary Smith", Gender="F", DateOfHiring=new DateTime(2009, 6, 15), Salary=55000 }
};

var query = from e in employees
             select new {
                NumberOfMaleEmployees = /* Count Where Gender = 'M' */,
                NumberOfFemaleEmployees = /* Count Where Gender = 'F' */,
                TotalSalaries = /* Sum All */,
                AverageSalary = /* Avg All */,
                LatestEmployee = /* Employee with Min DateOfHiring */
             };

Is it possible to achieve this in one query?
Thanks in advance
Iulian

  • 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-05-25T17:15:34+00:00Added an answer on May 25, 2026 at 5:15 pm

    You don’t want to be iterating over the array to start with by the looks of it – you just want:

    var query = new {
        NumberOfMaleEmployees = employees.Count(x => x.Gender == "M"),
        NumberOfFemaleEmployees = employees.Count(x => x.Gender == "F"),
        TotalSalaries = employees.Sum(x => x.Salary),
        AverageSalary = employees.Average(x => x.Average),
    };
    

    The “latest employee” bit is slightly tricky – you basically want MaxBy from MoreLINQ, which would let you write:

    LatestEmployee = employees.MaxBy(x => x.DateOfHiring)
    

    (which you can include in the above query, of course).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone help me create an index/count button for a UITableView, like this one?
can someone help me with some traversing and some logic here please. the logic
I hope someone can help here, we're having an incredibly annoying time with Visual
An odd error here, perhaps someone can help track down source as it's attempting
I am out of ideas here, so I'm hoping someone can help. Here is
I would like some help in understanding a particular behaviour of java Filters: I
I need some help here. I have a mysql table called dictionary like this:
Can someone help me out here as I can't get my awk command to
Can someone help me identify what the purpose of this unidentified syntax is. It
Can someone help me figure out the following make file? BINS=file1 file2 file3 all:

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.