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: Sql Query Help -- Aggregating Rows

Re: Sql Query Help -- Aggregating Rows

From: <lord.zoltar_at_gmail.com>
Date: Wed, 24 Oct 2007 19:52:02 -0000
Message-ID: <1193255522.016232.11260@q3g2000prf.googlegroups.com>


On Oct 24, 11:13 am, linux.hac..._at_gmail.com wrote:
> I'm having trouble figure out how to do this and thought that if I
> just asked people could show me some best practices and hopefully
> point me to some additional reading material. I've done a bit of sql
> but oracle is new to me (we are using oracle 9.? in case it matters)
>
> Anyways, after joining some tables and ignoring columns I don't care
> about I have a table that looks like:
> PurchaseDate PurchaserID PurchasersCatagory
>
> What they want to do is look at purchases in a three week span this
> year and last year and get a count by purchasers category for 2006
> (excluding those who also bought in 2007), 2007 (excluding...), both
> years
>
> For example:
>
> PurchaseDate PurchaserID PurchaseCatagory
> 2006 1 x
> 2007 1 x
> 2006 2 x
> 2006 3 y
> 2007 4 y
> 2007 5 z
>
> Then they want
> PurchaseCatagory 2006 2007 Both
> x 1 0 1
> y 1 1 0
> z 0 1 0
>
> Thanks,
> Bill

Oooooh... Looks like you might want a pivot query (google it). I've seen it done in Oracle (and done well), but the syntax was a bit messy and I'm terrible at them :(
It's definitely possible, though. ;) Received on Wed Oct 24 2007 - 14:52:02 CDT

Original text of this message

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