Jump to content

Grouping


vvalter

Recommended Posts

i have result like:

q_id|q_name|q_money

0 | JAMES | 500

1 | JAMES | 500

2 | JAKE | 100

3 | JOHN | 1000

4 | JOHN | 2000

 

and i want this result to be like this,

grouped my names and money is summed.

q_id|q_name|q_money

? | JAMES | 1000

? | JAKE | 100

? | JOHN | 3000

 

( ? -- not sure what the ID should be)

 

I take data from two different tables, and my query looks like:

SELECT q_id, q_name, q_money

FROM (SELECT aa_id q_id, aa_name q_name, aa_money q_money FROM table_aa) as aa

UNION SELECT q_id, q_name, q_money

FROM (SELECT bb_id q_id, bb_name q_name, bb_money q_money FROM table_bb) as bb

 

Table_aa columns are: aa_id, aa_name, aa_money

Table_bb columns are: bb_id, bb_name, bb_money

 

 

How my query should look like, to get the "grouped and summed" result?

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.