博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
总部分公司往来查询所有分公司[工程部统计总部扣所有分公司信息化]
阅读量:5031 次
发布时间:2019-06-12

本文共 4869 字,大约阅读时间需要 16 分钟。

之前的强大good sql只可以通过一个个输入分公司代码查询单一分公司和总部的往来,昨天江斌问我要所有扣分公司项目信息化20万的表,于是这个需求来了

昨天想了好久,通过先查询一个凭证中是总部的pk_detail,然后再查询所有是往来的(通过rn>=2)减去总部的,或者子查询pk_detail总部的就可以了。

sql会很重复,很长,但是能解决。

昨天写了,可是查询结果是空。

无望了。

刚刚来马晓莉家,想通了,pk_detail是一行一行的,应该查询pk_voucher,然后再detail

下面是总部往来的pk_detail

select *  from (select count(distinct gl_freevalue.valuecode) over(partition by gl_detail.prepareddatev, gl_voucher.no) rn,               gl_voucher.pk_voucher,               gl_freevalue.valuecode,               gl_detail.explanation ex,               bd_accsubj.dispname,               gl_detail.debitamount debit,               gl_detail.creditamount credit,               gl_detail.prepareddatev vdate,               gl_voucher.no,               bd_bdinfo.bdname,                              --gl_freevalue.valuename,               gl_detail.pk_systemv,               gl_detail.detailindex          from bd_accsubj          join gl_detail            on gl_detail.pk_accsubj = bd_accsubj.pk_accsubj          join bd_glorgbook            on bd_glorgbook.pk_glorgbook = bd_accsubj.pk_glorgbook          join gl_voucher            on gl_detail.pk_voucher = gl_voucher.pk_voucher          left join gl_freevalue            on gl_detail.assid = gl_freevalue.freevalueid          left join bd_bdinfo            on gl_freevalue.checktype = bd_bdinfo.pk_bdinfo         where gl_detail.dr = '0'           and gl_detail.yearv >= '2012'           and bd_glorgbook.glorgbookcode = '0100-0001'           and gl_detail.explanation <> '期初'              --and bd_accsubj.subjcode like '150103%'           --and gl_freevalue.valuecode <> '777777'           --and gl_freevalue.valuecode in ('010101', '&a')           and bd_bdinfo.bdname='客商辅助核算'           ) where rn >= 2   and valuecode = '010101'   /*and ex not like '上收%'     and ex not like '下拨%'  */   and substr(ex,1,2)<>'上收'   and substr(ex,1,2)<>'下拨'    and  ex not like '%0.4%'    order by vdate, no

 

sql

select                --gl_voucher.pk_voucher,               --gl_detail.pk_detail,               gl_freevalue.valuecode,               gl_freevalue.valuename,               gl_detail.explanation ex,               --bd_accsubj.dispname,               gl_detail.debitamount   debit,               gl_detail.creditamount credit,               gl_detail.prepareddatev vdate,               gl_voucher.no,               --bd_bdinfo.bdname,                              --gl_freevalue.valuename,               --gl_detail.pk_systemv,               gl_detail.detailindex          from bd_accsubj          join gl_detail            on gl_detail.pk_accsubj = bd_accsubj.pk_accsubj                 join gl_voucher            on gl_detail.pk_voucher = gl_voucher.pk_voucher          left join gl_freevalue            on gl_detail.assid = gl_freevalue.freevalueid          left join bd_bdinfo            on gl_freevalue.checktype = bd_bdinfo.pk_bdinfo         where  bd_bdinfo.bdname='客商辅助核算'--删除制单中的银行账号和7777往来 and  gl_freevalue.valuecode <> '010101'--删除总部的 and (gl_detail.debitamount=200000 or gl_detail.creditamount=200000 )--信息化扣款20万,如果是汇总扣或退则不行 and  gl_voucher.pk_voucher in ( select pk_voucher from  ( select *  from (select count(distinct gl_freevalue.valuecode) over(partition by gl_detail.prepareddatev, gl_voucher.no) rn,               gl_voucher.pk_voucher,               gl_detail.pk_detail,               gl_freevalue.valuecode,               gl_detail.explanation ex,               bd_accsubj.dispname,               gl_detail.debitamount debit,               gl_detail.creditamount credit,               gl_detail.prepareddatev vdate,               gl_voucher.no,               bd_bdinfo.bdname,                              --gl_freevalue.valuename,               gl_detail.pk_systemv,               gl_detail.detailindex          from bd_accsubj          join gl_detail            on gl_detail.pk_accsubj = bd_accsubj.pk_accsubj          join bd_glorgbook            on bd_glorgbook.pk_glorgbook = bd_accsubj.pk_glorgbook          join gl_voucher            on gl_detail.pk_voucher = gl_voucher.pk_voucher          left join gl_freevalue            on gl_detail.assid = gl_freevalue.freevalueid          left join bd_bdinfo            on gl_freevalue.checktype = bd_bdinfo.pk_bdinfo         where gl_detail.dr = '0'           and gl_detail.yearv >= '2012'           and bd_glorgbook.glorgbookcode = '0100-0001'                      and gl_detail.explanation <> '期初'              --and bd_accsubj.subjcode like '150103%'           --and gl_freevalue.valuecode <> '777777'           --and gl_freevalue.valuecode in ('010101', '&a')           and bd_bdinfo.bdname='客商辅助核算'            ) where rn >= 2   and valuecode = '010101'   /*and ex not like '上收%'     and ex not like '下拨%'  */   and substr(ex,1,2)<>'上收'   and substr(ex,1,2)<>'下拨'    and  ex not like '%0.4%'    )  )   order by valuecode,vdate, no

 

 

转载于:https://www.cnblogs.com/sumsen/p/3824999.html

你可能感兴趣的文章
程序员高效开发的几个技巧
查看>>
js-权威指南学习笔记19.2
查看>>
hexo 搭建博客
查看>>
关于 UIWebView 几个高级用法
查看>>
maven创建的项目中无法创建src/main/java 解决方案
查看>>
华为软件开发云测评报告二:代码检查
查看>>
集合1
查看>>
关键词 virtual
查看>>
建造者模式(屌丝专用)
查看>>
UVALive 4730 Kingdom +段树和支票托收
查看>>
[APIO2010]特别行动队
查看>>
SpringBoot 集成ehcache
查看>>
初步swift语言学习笔记2(可选类型?和隐式可选类型!)
查看>>
Nginx + Tomcat 反向代理 如何在高效的在一台服务器部署多个站点
查看>>
在Vs2012 中使用SQL Server 2012 Express LocalDB打开Sqlserver2012数据库
查看>>
在Macos下完美解决Adobe Dreamweaver CC 2018 汉化及操作方法
查看>>
【转】 Newtonsoft.Json高级用法
查看>>
CodeBlocks X64 SVN 编译版
查看>>
Excel催化剂开源第42波-与金融大数据TuShare对接实现零门槛零代码获取数据
查看>>
bug记录_signalr执行$.connnection.testhub结果为空
查看>>