orcale数据列补位操作
来源:互联网 发布:水准仪高程测量数据 编辑:程序博客网 时间:2024/04/30 14:17
首先将两上相同 地表放在一起,在前一个表里面预留列位,同时后一个表也要预留列位,这样整体查询出来地数据都会相应补位。
select a.dwjc,NVL(sum(a.jcz), 0) jcz,
NVL(sum(a.jsq), 0) jsq,
NVL(sum(a.jdw), 0) jdw,
NVL(sum(a.jxx), 0) jxx,
NVL(sum(a.gj), 0) gj,
NVL(sum(a.sj), 0) sj,
NVL(sum(a.dq), 0) dq,
nvl(sum(a.jcz + a.jsq + a.jdw + a.jxx), 0) ct
from(
select b.dwjc,
nvl((CASE
WHEN lb = 1 then
(select count(id)
from xc_fiveenterbase
where lb = a.lb
and lrdw = b.dwdm)
else
0
end),
0) as jcz,
nvl((CASE
WHEN lb = 2 then
(select count(id)
from xc_fiveenterbase
where lb = a.lb
and lrdw = b.dwdm)
else
0
end),
0) as jsq,
nvl((CASE
WHEN lb = 3 then
(select count(id)
from xc_fiveenterbase
where lb = a.lb
and lrdw = b.dwdm)
else
0
end),
0) as jdw,
nvl((CASE
WHEN lb = 4 then
(select count(id)
from xc_fiveenterbase
where lb = a.lb
and lrdw = b.dwdm)
else
0
end),
0) as jxx,
nvl(0, 0) gj,
nvl(0, 0) sj,
nvl(0, 0) dq
from (select *
From xc_fiveenterbase
where lrdw like '52%'
and lrsj >= to_date('2011-03-01', 'yyyy-MM-dd')
and lrsj <= to_date('2011-08-04', 'yyyy-MM-dd')) a,
ud_unit b
where a.lrdw = b.dwdm(+)
group by b.dwjc, dwdm, lb
union all
select b.dwjc,
nvl(0, 0) jcz,
nvl(0, 0) jsq,
nvl(0, 0) jdw,
nvl(0, 0) jxx,
nvl((CASE
WHEN jb = 1 then
(select count(id)
from xc_fiveenterbase
where jb = a.jb
and lrdw = b.dwdm)
else
0
end),
0) as gj,
nvl((CASE
WHEN jb = 2 then
(select count(id)
from xc_fiveenterbase
where jb = a.jb
and lrdw = b.dwdm)
else
0
end),
0) as sj,
nvl((CASE
WHEN jb = 3 then
(select count(id)
from xc_fiveenterbase
where jb = a.jb
and lrdw = b.dwdm)
else
0
end),
0) as dq
from (select *
From xc_fiveenterbase
where lrdw like '52%'
and lrsj >= to_date('2011-03-01', 'yyyy-MM-dd')
and lrsj <= to_date('2011-08-04', 'yyyy-MM-dd')) a,
ud_unit b
where a.lrdw = b.dwdm
group by b.dwjc, dwdm, jb
) a group by a.dwjc order by sj
select a.dwjc,NVL(sum(a.jcz), 0) jcz,
NVL(sum(a.jsq), 0) jsq,
NVL(sum(a.jdw), 0) jdw,
NVL(sum(a.jxx), 0) jxx,
NVL(sum(a.gj), 0) gj,
NVL(sum(a.sj), 0) sj,
NVL(sum(a.dq), 0) dq,
nvl(sum(a.jcz + a.jsq + a.jdw + a.jxx), 0) ct
from(
select b.dwjc,
nvl((CASE
WHEN lb = 1 then
(select count(id)
from xc_fiveenterbase
where lb = a.lb
and lrdw = b.dwdm)
else
0
end),
0) as jcz,
nvl((CASE
WHEN lb = 2 then
(select count(id)
from xc_fiveenterbase
where lb = a.lb
and lrdw = b.dwdm)
else
0
end),
0) as jsq,
nvl((CASE
WHEN lb = 3 then
(select count(id)
from xc_fiveenterbase
where lb = a.lb
and lrdw = b.dwdm)
else
0
end),
0) as jdw,
nvl((CASE
WHEN lb = 4 then
(select count(id)
from xc_fiveenterbase
where lb = a.lb
and lrdw = b.dwdm)
else
0
end),
0) as jxx,
nvl(0, 0) gj,
nvl(0, 0) sj,
nvl(0, 0) dq
from (select *
From xc_fiveenterbase
where lrdw like '52%'
and lrsj >= to_date('2011-03-01', 'yyyy-MM-dd')
and lrsj <= to_date('2011-08-04', 'yyyy-MM-dd')) a,
ud_unit b
where a.lrdw = b.dwdm(+)
group by b.dwjc, dwdm, lb
union all
select b.dwjc,
nvl(0, 0) jcz,
nvl(0, 0) jsq,
nvl(0, 0) jdw,
nvl(0, 0) jxx,
nvl((CASE
WHEN jb = 1 then
(select count(id)
from xc_fiveenterbase
where jb = a.jb
and lrdw = b.dwdm)
else
0
end),
0) as gj,
nvl((CASE
WHEN jb = 2 then
(select count(id)
from xc_fiveenterbase
where jb = a.jb
and lrdw = b.dwdm)
else
0
end),
0) as sj,
nvl((CASE
WHEN jb = 3 then
(select count(id)
from xc_fiveenterbase
where jb = a.jb
and lrdw = b.dwdm)
else
0
end),
0) as dq
from (select *
From xc_fiveenterbase
where lrdw like '52%'
and lrsj >= to_date('2011-03-01', 'yyyy-MM-dd')
and lrsj <= to_date('2011-08-04', 'yyyy-MM-dd')) a,
ud_unit b
where a.lrdw = b.dwdm
group by b.dwjc, dwdm, jb
) a group by a.dwjc order by sj
- orcale数据列补位操作
- orcale 时间操作
- orcale用户操作语句
- Orcale数据库操作练习
- Orcale数据库操作
- orcale数据恢复
- Orcale循环插入数据
- 对orcale数据库中表的创建以及对表中数据的基本操作
- ORCALE 日期函数的操作
- orcale 操作练习 Part 1
- orcale视图的DML操作
- orcale删除全部表数据 .
- c# 直连orcale数据
- ORCALE
- orcale
- orcale数据上传(大数据汇聚)
- linux 下orcale基本操作指令
- mysql和orcale数据库连接与SQL操作
- C++ 程序的死去方式
- 深入理解C语言中的指针与数组之指针篇
- UILabel自适应高度和自动换行
- Oracle中文、数字混杂字段的排序
- How to show a toast in Android Framework service. 如何在Framework层显示toast.
- orcale数据列补位操作
- 让你的C程序更有效率的10种方法
- linuxcode_turing
- 有一个数组,存储的元素为1到10000000的任意数,在其中查找出一个重复的数字
- java发送邮件
- HTML学习
- orcale优化统计以及占位操作、统计函数的应用(1)
- Extern "C"
- 各个版本的iPhone SDK下载地址