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
https://forums.phpfreaks.com/topic/252559-grouping/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.