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 8797511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:52:22+00:00 2026-06-13T23:52:22+00:00

please consider this scenario: I have data like this : Id Group Value ———————————–

  • 0

please consider this scenario:

I have data like this :

 Id          Group            Value
 -----------------------------------
 1            1                100
 2            1                120
 3            1                100
 4            2                90
 5            2                105
 6            3                300
 7            4                123
 8            4                110
 9            5                100
 10           5                110

I want to do GroupBy on this data as 1,2,3 place in one group and 4,5 place in another group. How I can do this with LINQ?

thanks


Edit 1)

I want to place 1,2,3 in one group and 4,5 in another group and perform Count aggregation on them and I get 6 for first group and 4 for secnd group

  • 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-13T23:52:23+00:00Added an answer on June 13, 2026 at 11:52 pm

    How about this?

            int[] groupA = { 1, 2, 3 };
            int[] groupB = { 4, 5 };
    
            var result = data
                .GroupBy(a => groupA.Contains(a.Group) ? "A" : 
                              groupB.Contains(a.Group) ? "B" : 
                              "N/a")
                .Select(a => new
                {
                    KEY = a.Key,
                    VALUE = a.Count()
                });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

please consider this scenario: I have a table like this: ID City Status --------------------------------------
Please Consider this scenario: We have a base class called clsMain : class clsMain
please consider this image: I have a table like this: Age Active Men/Women -------------------------------------------------
please consider this scenario: we have two web page. a simple page that contains
please consider this scenario: I have a list of a class with about 50
Please consider this scenario: I have a web site that host behind IIS 7.0
i have trouble with building some projects. please consider this scenario: i have 2
please consider this table: PK_Id Number Year Month Value ------------------------------------------------------------------------- 1 1 2000 5
Please consider this scenario: An app knows which of a few routes the phone
Before I ask my question, please consider this scenario: a user on my website

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.