--查出所有现金中心的单位ID
with
AllUnit
as(
select t.ORGANIZATIONID orgid,t.parentid
from CDMS_ORGANIZATION t where T.CATEGORY = 4
start with t.organizationid = '05e85693-14b0-4582-8063-8fbde85371f0'
connect by t.parentid = PRIOR t.organizationid),

N_instock
as(
-- instock 完整money,残损money,字段:入库单位ID,mone1,money2
select inunitid,(baint+bunint+intaintNum+baoInt) intMoney,(baDMA+BUNDMA+baoDMA) DMAMoney
from(
select tba.INUNITID,
NVL((case ba.ISDAMAGE when 0 then 100*ba.valuta end),0) as BaInt,
NVL((case ba.ISDAMAGE when 1 then 100*ba.valuta end),0) as BaDmA,
NVL((case bun.ISDAMAGE when 0 then 1000*bun.valuta end),0) as BunINT,
NVL((case bun.ISDAMAGE when 1 then 1000*bun.valuta end),0) as BUNDMA,
NVL(inta.COUNTER*inta.VALUTA,0) intaintNUM,NVL(pack.INTACTNUM,0) baoint,
NVL(pack.DAMAGENUM,0) baodma from
(
select it.inunitid,de.barcode,de.UNIT from GZH_INSTOCK it
left join GZH_INSTOCK_DETAIL de on it.BILLID=de.BILLID
--where to_char(it.billdate,'yyyy-MM')='2016-11' and intype='1311'
)tba
left join GZH_BAINFO ba on tba.BARCODE=ba.BARCODE and tba.unit=1
left join GZH_BUNCHINFO bun on tba.BARCODE=bun.BUNCHCODE and tba.unit=2
left join GZH_PACHETINFO pack on tba.barcode=pack.RFIDNO and tba.unit=4
left join GZH_INTACTBOXINFO inta on tba.BARCODE=inta.BARCODE and tba.unit=3
)
)
,
allData
as(
select t.PARENTID,NVL(sum(t1.FLITTINGMONEY),0) outmoney,
NVL(sum(t2.INTMONEY),0) INTMONEY,
NVL(sum(t2.DMAMONEY),0) DMAMONEY from allunit t
left join GZH_outsTOCK t1 on t.orgid=t1.outUNITID
left join N_instock t2 on t.orgid=t2.inUNITID
--where to_char(t1.billdate,'yyyy-MM')='2016-11' and outtype='1321'
group by t.PARENTID
)
,
TFinfo
as
(
select parentid,
decode((select sum(outmoney) from allData),0,0,outmoney/(select sum(outmoney) from allData)) TFscale,
decode((select sum(intmoney) from allData),0,0,intmoney/(select sum(intmoney) from allData)) HLWscale,
decode((select sum(dmamoney) from alldata),0,0,dmamoney/(select sum(dmamoney) from alldata)) HLCscale
from alldata)

select fullname,TFscale 投放占比,HLWscale 回笼完整占比,HLCscale 回笼完整占比
from TFinfo left join cdms_organization
on cdms_organization.organizationid=tfinfo.parentid;

上面的这段sql是尹哥教我的,虽然不是自己写的,但是按照这个思路,我发现我之前是对的,只是对oracle的认识不够,写不出来

今天最主要的是都让我重新的认识了oracle的查询,和我之前学的sql查询的差距还是挺大的,各种各样的结构的选择和各种各样的代码的编写

在计算比例的时候,我们先对数据进行求和,为了不能表中出现空的字符,我们选用了nvl(字段名,0),这是将空的字符串变为O 的语句。

今天我还用了一个很神奇的方法,decode(a,0,0,b/a*100)这个是为了不让除数为0 的时候,使oracle报错,这个让我的语句更快的写完。

我将这两个用法记录下来就是为了让自己能更好的记住这两个词的用法。

今天加上一点,就是我在这个sql中的一个重要的用法case when then end 这个语句

在我们的这个sql中,我们使用这个语句进行了数据的分类统计,实现了我们直接在数据库中的操作,对我们的数据进行了更好的统计。(2016-11-28)

最新文章

  1. 如何修改SVN已提交项目的message log
  2. Sprint1(11.20)
  3. 表视图控制器(TableViewController)(三) 、 表视图搜索
  4. pthread_rwlock_t读写锁函数说明
  5. 块和内嵌div和span
  6. Maven入门1-在Eclipse中新建Maven Web项目
  7. SSE图像算法优化系列十一:使用FFT变换实现图像卷积。
  8. qt程序启动画面
  9. java中类的三大特征之多态
  10. angular2 学习笔记 ( server-side rendering, angular universal, 服务端渲染 )
  11. mockplus 原型设计工具
  12. python语言学习--2
  13. Oracle 数据库分页查询与排序分页查询
  14. jQuery-form实现文件分步上传
  15. MySQL 删除数据库中重复数据方法
  16. spyder在编辑过程中被自己弄乱了,想要恢复成安装时默认的格式或者重置页面格式的解决办法
  17. python学习 day5 (3月6日)
  18. 面向对象初调用:foolish 电梯
  19. 代码生成器 CodeSmith 的使用(三)
  20. 微信JS-SDK接口 + FLASK实现图片上传

热门文章

  1. jQuery 实现菜单
  2. javascript的异步编程方法
  3. Notification NotificationManager RemoteViews PendingIntent
  4. hdu 2084
  5. Linux kernel map
  6. Libgdx 开发指南(1.3) 应用框架——查询、日志
  7. 【LeetCode OJ】Path Sum II
  8. TortoiseGit 添加ssh key
  9. Matlab数字信号处理
  10. setsockopt 设置 SO_LINGER 选项