在记录的检索过程中,往往会有这样的需求,将要搜索的列变成行,即交叉检索,具体解决方案如下:
select emp_year,
sum(decode(emp_month,1,emp_sal,0)) m1,
sum(decode(emp_month,2,emp_sal,0)) m2,
sum(decode(emp_month,3,emp_sal,0)) m3,
sum(decode(emp_month,4,emp_sal,0)) m4
from emp
group by emp_year;