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
Post a Comment