Welcome Guest, Not a member yet? Register   Sign In
Group By Problem
#5

[eluser]rochellecanale[/eluser]
I have an idea but i dont know how to combine the two queries in one simple query, like a subquery statement.
Here's my idea. First i run this query.

Code:
//First for earned type
mysql> select sum(amount) as total,fkmember from points_ledger where type = 'EARNED' group by fkmember;

//It results to

+-------+----------+
| total | fkmember |
+-------+----------+
|    30 |        1 |
|     5 |       37 |
|     5 |       47 |
|     5 |       53 |
+-------+----------+
4 rows in set (0.00 sec)

Code:
//Next is this for payout type

mysql> select sum(amount) as total,fkmember from points_ledger where type = 'PAYOUT' group by fkmember;

//results to
+-------+----------+
| total | fkmember |
+-------+----------+
|   -30 |        1 |
|    -5 |       37 |
|    -5 |       47 |
|    -5 |       53 |
+-------+----------+

Now how can i combine the two queries?


Messages In This Thread
Group By Problem - by El Forum - 10-21-2012, 07:54 PM
Group By Problem - by El Forum - 10-21-2012, 08:23 PM
Group By Problem - by El Forum - 10-21-2012, 08:35 PM
Group By Problem - by El Forum - 10-21-2012, 08:57 PM
Group By Problem - by El Forum - 10-21-2012, 09:09 PM
Group By Problem - by El Forum - 10-21-2012, 09:10 PM
Group By Problem - by El Forum - 10-22-2012, 01:06 AM



Theme © iAndrew 2016 - Forum software by © MyBB