I have a table A with 3 columns-
date | type | value
_________________________
2012-01-01 | 1 | 100
2012-01-01 | 2 | 200
2012-01-02 | 1 | 200
2012-01-02 | 2 | 300
2012-01-03 | 1 | 500
2012-01-03 | 2 | 10
Is it possible to get the result of a query, for this data in a format like this-
date | type-1 | type-2
_____________________________________
2012-01-01 100 200
2012-01-02 200 300
It looks like a crosstab problem. Not sure though.
any ideas how to write an SQL for that?
You can use an aggregate function with a
CASEexpression to get the result:See SQL Fiddle with Demo
You can also join on your table multiple times:
See SQL Fiddle with Demo