dbTalk Databases Forums  

Query

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Query in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mtek
 
Posts: n/a

Default Query - 09-15-2008 , 08:31 AM







Hi,

I was wondering if I can display data like this:

Original Data
01-JUN-08 Type1 Add 4308
01-JUN-08 Type1 Delete 4687
01-OCT-08 Type2 Delete 5545
01-OCT-08 Type2 Add 11801

New Data
01-JUN-08 Type1 Add 4308 Delete 4687
01-OCT-08 Type2 Add 11801 Delete 5545

I want all related records on the same line......

Much thanks

Reply With Quote
  #2  
Old   
Carlos
 
Posts: n/a

Default Re: Query - 09-15-2008 , 08:41 AM






On 15 sep, 15:31, Mtek <m... (AT) mtekusa (DOT) com> wrote:
Quote:
Hi,

I was wondering if I can display data like this:

Original Data
01-JUN-08 Type1 Add 4308
01-JUN-08 Type1 Delete 4687
01-OCT-08 Type2 Delete 5545
01-OCT-08 Type2 Add 11801

New Data
01-JUN-08 Type1 Add 4308 Delete 4687
01-OCT-08 Type2 Add 11801 Delete 5545

I want all related records on the same line......

Much thanks
Google for 'PIVOT TABLE'

HTH

Cheers.

Carlos.


Reply With Quote
  #3  
Old   
Carlos
 
Posts: n/a

Default Re: Query - 09-15-2008 , 08:41 AM



On 15 sep, 15:31, Mtek <m... (AT) mtekusa (DOT) com> wrote:
Quote:
Hi,

I was wondering if I can display data like this:

Original Data
01-JUN-08 Type1 Add 4308
01-JUN-08 Type1 Delete 4687
01-OCT-08 Type2 Delete 5545
01-OCT-08 Type2 Add 11801

New Data
01-JUN-08 Type1 Add 4308 Delete 4687
01-OCT-08 Type2 Add 11801 Delete 5545

I want all related records on the same line......

Much thanks
Google for 'PIVOT TABLE'

HTH

Cheers.

Carlos.


Reply With Quote
  #4  
Old   
Carlos
 
Posts: n/a

Default Re: Query - 09-15-2008 , 08:41 AM



On 15 sep, 15:31, Mtek <m... (AT) mtekusa (DOT) com> wrote:
Quote:
Hi,

I was wondering if I can display data like this:

Original Data
01-JUN-08 Type1 Add 4308
01-JUN-08 Type1 Delete 4687
01-OCT-08 Type2 Delete 5545
01-OCT-08 Type2 Add 11801

New Data
01-JUN-08 Type1 Add 4308 Delete 4687
01-OCT-08 Type2 Add 11801 Delete 5545

I want all related records on the same line......

Much thanks
Google for 'PIVOT TABLE'

HTH

Cheers.

Carlos.


Reply With Quote
  #5  
Old   
Carlos
 
Posts: n/a

Default Re: Query - 09-15-2008 , 08:41 AM



On 15 sep, 15:31, Mtek <m... (AT) mtekusa (DOT) com> wrote:
Quote:
Hi,

I was wondering if I can display data like this:

Original Data
01-JUN-08 Type1 Add 4308
01-JUN-08 Type1 Delete 4687
01-OCT-08 Type2 Delete 5545
01-OCT-08 Type2 Add 11801

New Data
01-JUN-08 Type1 Add 4308 Delete 4687
01-OCT-08 Type2 Add 11801 Delete 5545

I want all related records on the same line......

Much thanks
Google for 'PIVOT TABLE'

HTH

Cheers.

Carlos.


Reply With Quote
  #6  
Old   
Mtek
 
Posts: n/a

Default Re: Query - 09-15-2008 , 09:18 AM



On Sep 15, 8:41*am, Carlos <miotromailcar... (AT) netscape (DOT) net> wrote:
Quote:
On 15 sep, 15:31, Mtek <m... (AT) mtekusa (DOT) com> wrote:





Hi,

I was wondering if I can display data like this:

Original Data
01-JUN-08 Type1 * * * * * Add * * * * * 4308
01-JUN-08 Type1 * * * * * Delete * * * *4687
01-OCT-08 Type2 * * * * * Delete * * * *5545
01-OCT-08 Type2 * * * * * Add * * * * *11801

New Data
01-JUN-08 Type1 * * *Add * *4308 * Delete * * 4687
01-OCT-08 Type2 * * *Add * 11801 * Delete * * 5545

I want all related records on the same line......

Much thanks

Google for 'PIVOT TABLE'

HTH

Cheers.

Carlos.- Hide quoted text -

- Show quoted text -
Pretty good Carlos. Do I need to code each value in the case
statements? What if I do not know every value?



Reply With Quote
  #7  
Old   
Mtek
 
Posts: n/a

Default Re: Query - 09-15-2008 , 09:18 AM



On Sep 15, 8:41*am, Carlos <miotromailcar... (AT) netscape (DOT) net> wrote:
Quote:
On 15 sep, 15:31, Mtek <m... (AT) mtekusa (DOT) com> wrote:





Hi,

I was wondering if I can display data like this:

Original Data
01-JUN-08 Type1 * * * * * Add * * * * * 4308
01-JUN-08 Type1 * * * * * Delete * * * *4687
01-OCT-08 Type2 * * * * * Delete * * * *5545
01-OCT-08 Type2 * * * * * Add * * * * *11801

New Data
01-JUN-08 Type1 * * *Add * *4308 * Delete * * 4687
01-OCT-08 Type2 * * *Add * 11801 * Delete * * 5545

I want all related records on the same line......

Much thanks

Google for 'PIVOT TABLE'

HTH

Cheers.

Carlos.- Hide quoted text -

- Show quoted text -
Pretty good Carlos. Do I need to code each value in the case
statements? What if I do not know every value?



Reply With Quote
  #8  
Old   
Mtek
 
Posts: n/a

Default Re: Query - 09-15-2008 , 09:18 AM



On Sep 15, 8:41*am, Carlos <miotromailcar... (AT) netscape (DOT) net> wrote:
Quote:
On 15 sep, 15:31, Mtek <m... (AT) mtekusa (DOT) com> wrote:





Hi,

I was wondering if I can display data like this:

Original Data
01-JUN-08 Type1 * * * * * Add * * * * * 4308
01-JUN-08 Type1 * * * * * Delete * * * *4687
01-OCT-08 Type2 * * * * * Delete * * * *5545
01-OCT-08 Type2 * * * * * Add * * * * *11801

New Data
01-JUN-08 Type1 * * *Add * *4308 * Delete * * 4687
01-OCT-08 Type2 * * *Add * 11801 * Delete * * 5545

I want all related records on the same line......

Much thanks

Google for 'PIVOT TABLE'

HTH

Cheers.

Carlos.- Hide quoted text -

- Show quoted text -
Pretty good Carlos. Do I need to code each value in the case
statements? What if I do not know every value?



Reply With Quote
  #9  
Old   
Mtek
 
Posts: n/a

Default Re: Query - 09-15-2008 , 09:18 AM



On Sep 15, 8:41*am, Carlos <miotromailcar... (AT) netscape (DOT) net> wrote:
Quote:
On 15 sep, 15:31, Mtek <m... (AT) mtekusa (DOT) com> wrote:





Hi,

I was wondering if I can display data like this:

Original Data
01-JUN-08 Type1 * * * * * Add * * * * * 4308
01-JUN-08 Type1 * * * * * Delete * * * *4687
01-OCT-08 Type2 * * * * * Delete * * * *5545
01-OCT-08 Type2 * * * * * Add * * * * *11801

New Data
01-JUN-08 Type1 * * *Add * *4308 * Delete * * 4687
01-OCT-08 Type2 * * *Add * 11801 * Delete * * 5545

I want all related records on the same line......

Much thanks

Google for 'PIVOT TABLE'

HTH

Cheers.

Carlos.- Hide quoted text -

- Show quoted text -
Pretty good Carlos. Do I need to code each value in the case
statements? What if I do not know every value?



Reply With Quote
  #10  
Old   
Mtek
 
Posts: n/a

Default Re: Query - 09-15-2008 , 10:23 AM



On Sep 15, 8:41*am, Carlos <miotromailcar... (AT) netscape (DOT) net> wrote:
Quote:
On 15 sep, 15:31, Mtek <m... (AT) mtekusa (DOT) com> wrote:





Hi,

I was wondering if I can display data like this:

Original Data
01-JUN-08 Type1 * * * * * Add * * * * * 4308
01-JUN-08 Type1 * * * * * Delete * * * *4687
01-OCT-08 Type2 * * * * * Delete * * * *5545
01-OCT-08 Type2 * * * * * Add * * * * *11801

New Data
01-JUN-08 Type1 * * *Add * *4308 * Delete * * 4687
01-OCT-08 Type2 * * *Add * 11801 * Delete * * 5545

I want all related records on the same line......

Much thanks

Google for 'PIVOT TABLE'

HTH

Cheers.

Carlos.- Hide quoted text -

- Show quoted text -
Ok, I find this example on Tom Kyte's page:

select job,
max( decode( deptno, 10, cnt, null ) ) dept_10,
max( decode( deptno, 20, cnt, null ) ) dept_20,
max( decode( deptno, 30, cnt, null ) ) dept_30,
max( decode( deptno, 40, cnt, null ) ) dept_40
from ( select job, deptno, count(*) cnt
from emp
group by job, deptno )
group by job;

Mine is almost identical, but I get an error:

select TRUNC(action_date,'MM'),
max( decode( email_product_id, 'PPM', cnt, null ) ) 'Product1',
max( decode( email_product_id, 'HL', cnt, null ) ) 'Product2',
max( decode( email_product_id, 'ZI', cnt, null ) ) 'Product3',
max( decode( email_product_id, 'PP', cnt, null ) ) 'Product4',
max( decode( email_product_id, 'PP1', cnt, null ) ) 'Product5'
from ( select TRUNC(action_date,'MM'), email_product_id, count(*) cnt
from email_product_hist
group by email_product_id )
group by email_product_id;

ERROR at line 2:
ORA-00923: FROM keyword not found where expected

I cannot get this one......


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.