Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Cross-tab queries in SQL
You can create crosstab queries in SQL but only the column down the left can
truly be variable. The one across the top has to be hard coded.
EX:
SELECT month,
sum(decode(product_id,1,revenue,0)) 1, sum(decode(product_id,2,revenue,0)) 2, sum(decode(product_id,3,revenue,0)) 3, sum(decode(product_id,4,revenue,0)) 4,FROM test
Hope this helps
Steve
In article <357D044E.5A74_at_openix.com>,
tansel_at_openix.com wrote:
>
> Hello all,
>
> Is there any way to write cross-tab type queries in SQL?
> Such that the columns are variable?
>
> For example:
>
> crate table test (
> month varchar2(20),
> product_id number,
> revenue number);
>
> Sum of Revenue
> Product Id
> Month 1 2 3 4
> January 140 320 300 340
> February .. .. .. ..
> March
>
> Thanks..
>
> Tansel
>
-----== Posted via Deja News, The Leader in Internet Discussion ==----- http://www.dejanews.com/ Now offering spam-free web-based newsreading Received on Tue Jun 09 1998 - 12:02:47 CDT