vvalter Posted December 6, 2011 Share Posted December 6, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/252559-grouping/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.