一条语句轻松写出一个报表(含明细、小计、合计、总计)

来源:互联网 发布:linux samba 安装配置 编辑:程序博客网 时间:2024/06/06 03:16
 select x1,x2,x3... from (
with mx as (
select x1,x2,x3,(select x4 from m where ... and rownum <2 ) x4,...
from x,y,z
where ...
)
select x1,x2,x3... from mx
union all
select x1,
x2,
'' x3,
...
sum(x7) x7,
sum(x8) x8,
sum(x9) hj
from mx
group by ROLLUP(x1, x2)
) t
order by x1,x2,x3...
原创粉丝点击