MySQL Forums
Forum List  »  Newbie

generate columns out of data
Posted by: Janosh Thurni
Date: March 14, 2006 07:48AM


I use the following query:

SELECT category, SUM(amount) AS amount FROM table GROUP BY category;

so I get the following table:

| cateogory | amount |
| A | 10 |
| B | 5 |
| C | 16 |

but I actually would like to have a table like this:

| A | B | C |
| 10 | 5 | 16 |

the problem is, i don't know all the existing categories. (if i would know it i could use IF(...='A')).

how can I do this?

thanks for any help


Options: ReplyQuote

Written By
generate columns out of data
March 14, 2006 07:48AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.