oracle出库查询,oracle中的查询语句(关于出库入库信息表,明细表,把捆包箱表,单位信息表的集中查询)...

--查出所有现金中心的单位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报错,这个让我的语句更快的写完。

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

原文:http://www.cnblogs.com/sun1512/p/6105118.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值