table J |
|
|
|
id |
name |
money |
class |
A |
김아무개 |
0 |
a1 |
B |
김나라 |
100 |
a1 |
C |
김우주 |
200 |
a1 |
A |
김아무개 |
100 |
b1 |
B |
김나라 |
-50 |
c1 |
아래 ↓처럼 나오길 바라는데 어떻게 처리 해야 하는지????
class a1 |
class b1 |
class c1 |
200 |
100 |
-50 |
SELECT sum(a1), sum(b1), sum(c1) AS A
FROM
(SELECT MAX(money) AS a1,
null AS b1,
null AS c1
FROM j WHERE class = a1
UNION
SELECT MAX(money) AS b1,
null AS a1,
null AS c1,
FROM j WHERE class = b1
SELECT MAX(money) AS c1,
null AS a1,
null AS b1,
FROM j WHERE class = c1)
|