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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:05:14+00:00 2026-06-01T17:05:14+00:00

i have a table like this ID NAME Amount 1 cal 100 2 cal

  • 0

i have a table like this

ID  NAME    Amount
1   cal     100
2   cal     200
3   cal     300
4   cal     400
1   ser     500
2   ser     600
5   ser     700

i want to write a select query so that i wil get the resul like this

ID  NAME            Amount
1   cal and ser     600
2   cal and ser     800
3   cal             300
4   cal             400
5   ser             700

here i need to group by id and sum of amount and concat the string name with same id and differnet name

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

    this will work with sql-server 2008

    SELECT p1.ID,
           ( SELECT NAME + ' and ' 
               FROM YourTable  p2
              WHERE p2.ID = p1.ID
              ORDER BY NAME
                FOR XML PATH('') ) AS Name,
            sum(Amount)
          FROM YourTable p1
          GROUP BY ID ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table like this: Name State Amount ------------------------------ Pump 1 Present 339
I have a table like this: name code group john 12 smith 15 how
Let's say I have a table like this: name | score_a | score_b -----+---------+--------
Let's say I have a table like this: name |order_id ======================= first_record | 0
I have a table in mysql like this Name Result T1_09_03_2010 fail T2_09_03_2010 pass
I have a table that looks like this: Name Job Year ImpFile ImpDate ------------------------------------------------
i have a table like this one: -------------------------------- id | name -------------------------------- 1 |
I have a table like this (simplified): ID | Name | Parent --------------------------------- 1
If I have a table like this: CREATE TABLE sizes ( name ENUM('small', 'medium',
I have a table that looks something like this: Name Year Value A 2000

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.