Connecting Tech Pros Worldwide Forums | Help | Site Map

Pivoting

debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 7,511
#1   Sep 17 '07
Displaying Histogram-Horizontal
===========================
Expand|Select|Wrap|Line Numbers
  1. select deptno,lpad('*',count(*),'*') as cnt from emp group by deptno
Histogram-Vertical
===============
Expand|Select|Wrap|Line Numbers
  1. select row_number( )over(partition by deptno order by empno) rn,
  2. case when deptno=10 then '*' else null end deptno_10,
  3. case when deptno=20 then '*' else null end deptno_20,
  4. case when deptno=30 then '*' else null end deptno_30
  5. from emp
Displaying only the histogram
============================
Expand|Select|Wrap|Line Numbers
  1. select max(deptno_10) d10,
  2.        max(deptno_20) d20,
  3.        max(deptno_30) d30
  4.   from (
  5. select row_number( )over(partition by deptno order by empno) rn,
  6.        case when deptno=10 then '*' else null end deptno_10,
  7.        case when deptno=20 then '*' else null end deptno_20,
  8.        case when deptno=30 then '*' else null end deptno_30
  9.   from emp
  10.        ) x
  11.  group by rn
  12.  order by 1 desc, 2 desc, 3 desc



Closed Thread


Similar Oracle Database bytes