oracle - Cross Pivot Table PL SQL -


can me build query? have create cross table between products. guess best if can show you.

here source table (cartesian product of customer , product table);

year     month     product     customer     sold 2013         1                      1        1 2013         1                      2        0 2013         1                      3        1 2013         1                      4        0 2013         1           b            1        0 2013         1           b            2        1 2013         1           b            3        1 2013         1           b            4        1 2013         2                      1        1 2013         2                      2        0 2013         2           b            1        1 

this final pivot table want reproduce 2013-01;

prodduct            b             2       1        b      1       3 

numbers customer count. table represents how many bought customers bought b.

here ddl table

create table yourtable (year varchar2(4)      , month number      , product varchar2(1)      ,customer varchar2(1) , sold number );  

and here sample data:

insert yourtable values ('2013', 1, 'a', '1', 1);  insert yourtable values ('2013', 1, 'a', '2', 0);  insert yourtable values ('2013', 1, 'a', '3', 1);  insert yourtable values ('2013', 1, 'a', '4', 0);  insert yourtable values ('2013', 1, 'b', '1', 0);  insert yourtable values ('2013', 1, 'b', '2', 1);  insert yourtable values ('2013', 1, 'b', '3', 1);  insert yourtable values ('2013', 1, 'b', '4', 1);  insert yourtable values ('2013', 2, 'a', '1', 1);  insert yourtable values ('2013', 2, 'a', '2', 0);  


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -