Hello guys,
I have a table with 5 fields: aa, a, b, c and d. I would like to get a query where it will list the results in 3 columns i.e.
Column 1: values of a
Column 2: sum of the values of b where c<2006
Column 3: sum of the values of b where c=2006
I can get the results doing 2 queries:
Query 1: SELECT a,c, SUM(b) FROM table1 GROUP BY a HAVING c<'2006'
Query 2: SELECT a,c, SUM(b) FROM table1 GROUP BY a HAVING c='2006'
but I will have to enter the first query then use a for-loop to get the results of the second query. I'm trying to avoid the for-loop style and do it in just one query.
Example:
table1
------------------------------
aa | a | b | c | d |
------------------------------
1 | 1 | 10 | 2005 | 1 |
------------------------------
2 | 1 | 20 | 2005 | 2 |
------------------------------
3 | 1 | 10 | 2006 | 2 |
-----------------
-- This message may have been cut off and the rest will only be shown to members. To become a member, click here --