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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:35:11+00:00 2026-05-30T03:35:11+00:00

I have a joined table from which I want to sum the attribute amounts

  • 0

I have a joined table from which I want to sum the attribute amounts and also group by name.

joined_tb
name        attr        amount
billy       'attr1'     2
billy       'attr2'     4
billy       'attr1'     7
billy       'attr3'     8
jean        'attr2'     6
jean        'attr1'     1
jean        'attr2'     11

This table is a result of a join between these two tables using id

t1                  t2
id  name            id    attr      amount
1   billy           1     'attr1'   2
2   jean            1     'attr2'   4
                    1     'attr1'   7
                    1     'attr3'   8
                    2     'attr2'   6
                    2     'attr1'   1
                    2     'attr2'   11

I want to end up with this table:

result_tb
name        attr        amount
billy       'attr1'     9
billy       'attr2'     4
billy       'attr3'     8
jean        'attr1'     1
jean        'attr2'     17

I am able to sum by attr, but it ignores name. How can I get result_tb from t1 and t2?

  • 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-30T03:35:13+00:00Added an answer on May 30, 2026 at 3:35 am

    Try this:

    select t1.name, t2.attr, sum(t2.amount) from t1
    join t2 on t1.id = t2.id
    group by t1.name, t2.attr
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the models User and Group, and the join table Membership which uses
I used the mapping solution from this question to have a joined component. But
I have a table of orders. the status is on the soilorders which is
I am trying to pull multiple columns from 3 joined tables, but I want
I want to select values from three tables. Each table has an buyer_entity_id column.
I have a table which has three fields (item_id, source, and price). (item_id, source,
I have many tables in my database which are interrelated. I have a table
I have a Crystal report with a table as a datasource and I want
I have a few tables which I have joined together and would like to
I have joined multiple tables with INNER JOIN and got the output which resembles

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.