Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Cross-tab queries in SQL

Re: Cross-tab queries in SQL

From: <scjonson_at_fyiowa.infi.net>
Date: Tue, 09 Jun 1998 17:02:47 GMT
Message-ID: <6ljprn$3nv$1@nnrp1.dejanews.com>


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
group by month
order by to_date(month,'MONTH');

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

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US