生成报表的相关sql 博客分类: oracle sql报表
程序员文章站
2024-02-22 18:57:28
...
一张(l 和 h是同一张表,起了不同的别名)保存了名称,机构编码,上级编码的机构编码表,通过sql语句进行加工,得到一张报表的行数据(横向多排),别且根据数据条件形成不同层次.
select code1, name1, name2
from ((select h.org||'00' code1,
l.name || ' ' name1,
h.name name2
from l
join h
on (l.org = h.orgtype)
where l.m=1 AND l.o = decode(,'000000', '-1', )) union all
(select ||'00', '总计', '总计'
from dual
union all
select l.org||'00' code1,
l.name || ' ' name1,
'合计'||getNbsp(rownum) name2
from l
where l.m=1 AND l.org <> '000000'
and l.o = decode(,'000000', '-1', ))
union all
select l.org||'01' code1,
l.name || ' ' name1,
l.name||decode(,'000000','(责任单位)','(合作单位)') name2
from l
where l.m=1 AND l.o = decode(,'000000', '-1',)
and l.org<>'000000'
union all
select l.org||'02' code1,
l.name||'(责任单位)' name1,
'合计' name2
from l
where l.mgrtype=1 AND l.org = decode(,'000000', '-1',)
)
order by code1
select code1, name1, name2
from ((select h.org||'00' code1,
l.name || ' ' name1,
h.name name2
from l
join h
on (l.org = h.orgtype)
where l.m=1 AND l.o = decode(,'000000', '-1', )) union all
(select ||'00', '总计', '总计'
from dual
union all
select l.org||'00' code1,
l.name || ' ' name1,
'合计'||getNbsp(rownum) name2
from l
where l.m=1 AND l.org <> '000000'
and l.o = decode(,'000000', '-1', ))
union all
select l.org||'01' code1,
l.name || ' ' name1,
l.name||decode(,'000000','(责任单位)','(合作单位)') name2
from l
where l.m=1 AND l.o = decode(,'000000', '-1',)
and l.org<>'000000'
union all
select l.org||'02' code1,
l.name||'(责任单位)' name1,
'合计' name2
from l
where l.mgrtype=1 AND l.org = decode(,'000000', '-1',)
)
order by code1
推荐阅读
-
生成报表的相关sql 博客分类: oracle sql报表
-
生成报表的神器sql
-
Oracle PL/SQL 中循环语法语句的应用 博客分类: 数据库 OraclePL/SQL循环
-
JXLS生成报表的常规应用及扩展(下) 博客分类: 报表 JAVAJXLS报表cglib
-
SQL Server大表数据的导出与导入命令BCP 博客分类: Oracle&MSSQL sql server
-
MSSQL对表自动生成带insert语句的建表语句 博客分类: MSSQL SQL Server
-
oracle的sqlnet.ora , tnsnames.ora , Listener.ora 文件的作用 博客分类: database Oracle配置管理网络协议数据结构SQL Server
-
oracle数据库中慢SQL的优化过程(awr报表为例)
-
通过订单数据表生成每日的订单数量和增长量统计报表,该如何编写sql?
-
oracle数据库中慢SQL的优化过程(awr报表为例)