`

待账单统计语句

阅读更多

-----------------------------------------------------------------------------------
--------------------------已优化的待开帐语句--------------------------------------------
------------------------------------------------------------------------------------
--优化版本
--把待开帐和已开帐的统计结果都取出,两个结果集 中去除已开帐的统计信息
WITH
 waitingBill as

(
 select t.inv_seller_cid invSellerCid,t.inv_seller_name invSellerName,t.debtor_cid debtorCid,t.debtor_name debtorName,to_char(t.bill_date,'yyyy-mm-dd') billDate,to_char(t.payoff_date,'yyyy-mm-dd') payoffDate,t.bill_plan billPlan,count(t.id_ticket) count,
    --已确认总金额
    sum(case
        when  t.status='C'
              then dc.bill_amt
              else 0
        end
     ) as confirmedAmt,
     ----已确认总数
      sum(case
        when  t.status='C'
              then 1
              else 0
        end
     ) as confirmedCount,
     --已确认订票总金额
       sum(case
        when  t.status='C' and t.orig_id_ticket is null
              then dc.bill_amt
              else 0
        end
     ) as billBookAmt,
     --已确认订票总数
     sum(case
        when  t.status='C' and t.orig_id_ticket is null
              then 1
              else 0
        end
     ) as billBookCount,
     --已确认退票总金额
     sum(case
        when  t.status='C' and t.orig_id_ticket is not null
              then dc.bill_amt
              else 0
        end
     ) as billReturnAmt,
     --已确认退票总数
     sum(case
        when  t.status='C' and t.orig_id_ticket is not null
              then 1
              else 0
        end
     ) as billReturnCount,
     --未确认订票总金额
      sum(case
        when  t.status!='C' and t.orig_id_ticket is null
              then t.amt
              else 0
        end
     ) as unconfirmedBillBookAmt,
     --未确认订票总数
     sum(case
        when  t.status!='C' and t.orig_id_ticket is null
              then 1
              else 0
        end
     ) as unconfirmedBillBookCount,
    --未确认退票总金额
     sum(case
        when  t.status!='C' and t.orig_id_ticket is not null
              then t.amt
              else 0
        end
     ) as unconfirmedBillReturnAmt,
    --未确认退票总数
     sum(case
        when  t.status!='C' and t.orig_id_ticket is not null
              then 1
              else 0
        end
     ) as unconfirmedBillReturnCount,
    --未确认总数
    sum(case
       when  t.status!='C'
           then 1
           else 0
       end
  )  as unconfirmedCount  from t_ticket t left join t_debtor_clear_list dc on t.id_ticket=dc.id_ticket
   where 1=1   and t.bill_date is not null
   --开帐日 在当前月中
    and to_char(t.bill_date,'yyyy-mm-dd')>='2009-06-01' and to_char(t.bill_date,'yyyy-mm-dd')<='2009-06-30'
    and t.bill_status='0'
    group by t.inv_seller_cid,t.inv_seller_name,t.debtor_cid,t.debtor_name, to_char(t.bill_date,'yyyy-mm-dd'),to_char(t.payoff_date,'yyyy-mm-dd'),t.bill_plan
),
billedBill as
(
 select a.* from  waitingBill a ,t_debtor_bill b
 where a.invSellerCid=b.bill_seller_cid and a.invSellerName=b.bill_seller_name and a.debtorCid=b.bill_debtor_cid and a.debtorName=b.bill_debtor_name and a.billDate=to_char(b.bill_date,'yyyy-mm-dd') and a.payoffDate=to_char(b.payoff_date,'yyyy-mm-dd') and a.billPlan=b.bill_plan
 )
--SELECT * FROM  waitingBill WHERE  billDate!=(SELECT  billDate from billedBill )
SELECT * FROM  waitingBill WHERE  (invSellerCid||invSellerName||debtorCid||debtorName||billDate||payoffDate||billPlan)!=(SELECT  (invSellerCid||invSellerName||debtorCid||debtorName||billDate||payoffDate||billPlan) from billedBill )

 


--原始版本
--把待开帐和已开帐的统计结果都取出,用 MINUS  在数据库内存中 去除已开帐的统计信息

select * from (select t.inv_seller_cid invSellerCid,t.inv_seller_name invSellerName,t.debtor_cid debtorCid,t.debtor_name debtorName,to_char(t.bill_date,'yyyy-mm-dd') billDate,to_char(t.payoff_date,'yyyy-mm-dd') payoffDate,t.bill_plan billPlan,count(t.id_ticket) count,
  --已确认总金额
  sum(case
      when  t.status='C'
            then dc.bill_amt
            else 0
      end
   ) as confirmedAmt,
   ----已确认总数
    sum(case
      when  t.status='C'
            then 1
            else 0
      end
   ) as confirmedCount,
   --已确认订票总金额
     sum(case
      when  t.status='C' and t.orig_id_ticket is null
            then dc.bill_amt
            else 0
      end
   ) as billBookAmt,
   --已确认订票总数
   sum(case
      when  t.status='C' and t.orig_id_ticket is null
            then 1
            else 0
      end
   ) as billBookCount,
   --已确认退票总金额
   sum(case
      when  t.status='C' and t.orig_id_ticket is not null
            then dc.bill_amt
            else 0
      end
   ) as billReturnAmt,
   --已确认退票总数
   sum(case
      when  t.status='C' and t.orig_id_ticket is not null
            then 1
            else 0
      end
   ) as billReturnCount,
   --未确认订票总金额
    sum(case
      when  t.status!='C' and t.orig_id_ticket is null
            then t.amt
            else 0
      end
   ) as unconfirmedBillBookAmt,
   --未确认订票总数
   sum(case
      when  t.status!='C' and t.orig_id_ticket is null
            then 1
            else 0
      end
   ) as unconfirmedBillBookCount,
  --未确认退票总金额
   sum(case
      when  t.status!='C' and t.orig_id_ticket is not null
            then t.amt
            else 0
      end
   ) as unconfirmedBillReturnAmt,
  --未确认退票总数
   sum(case
      when  t.status!='C' and t.orig_id_ticket is not null
            then 1
            else 0
      end
   ) as unconfirmedBillReturnCount,
  --未确认总数
  sum(case
     when  t.status!='C'
         then 1
         else 0
     end
)  as unconfirmedCount  from t_ticket t left join t_debtor_clear_list dc on t.id_ticket=dc.id_ticket
 where 1=1   and t.bill_date is not null
 --开帐日 在当前月中
  and to_char(t.bill_date,'yyyy-mm-dd')>='2009-06-01' and to_char(t.bill_date,'yyyy-mm-dd')<='2009-06-30'
  and t.bill_status='0'
   group by t.inv_seller_cid,t.inv_seller_name,t.debtor_cid,t.debtor_name,to_char(t.bill_date,'yyyy-mm-dd'),to_char(t.payoff_date,'yyyy-mm-dd'),t.bill_plan
 order by to_char(t.bill_date,'yyyy-mm-dd') asc,t.debtor_name desc)

--去除充分的统计信息
MINUS


 select a.* from (select t.inv_seller_cid invSellerCid,t.inv_seller_name invSellerName,t.debtor_cid debtorCid,t.debtor_name debtorName,to_char(t.bill_date,'yyyy-mm-dd') billDate,to_char(t.payoff_date,'yyyy-mm-dd') payoffDate,t.bill_plan billPlan,count(t.id_ticket) count,
  --已确认总金额
  sum(case
      when  t.status='C'
            then dc.bill_amt
            else 0
      end
   ) as confirmedAmt,
   ----已确认总数
    sum(case
      when  t.status='C'
            then 1
            else 0
      end
   ) as confirmedCount,
   --已确认订票总金额
     sum(case
      when  t.status='C' and t.orig_id_ticket is null
            then dc.bill_amt
            else 0
      end
   ) as billBookAmt,
   --已确认订票总数
   sum(case
      when  t.status='C' and t.orig_id_ticket is null
            then 1
            else 0
      end
   ) as billBookCount,
   --已确认退票总金额
   sum(case
      when  t.status='C' and t.orig_id_ticket is not null
            then dc.bill_amt
            else 0
      end
   ) as billReturnAmt,
   --已确认退票总数
   sum(case
      when  t.status='C' and t.orig_id_ticket is not null
            then 1
            else 0
      end
   ) as billReturnCount,
   --未确认订票总金额
    sum(case
      when  t.status!='C' and t.orig_id_ticket is null
            then t.amt
            else 0
      end
   ) as unconfirmedBillBookAmt,
   --未确认订票总数
   sum(case
      when  t.status!='C' and t.orig_id_ticket is null
            then 1
            else 0
      end
   ) as unconfirmedBillBookCount,
  --未确认退票总金额
   sum(case
      when  t.status!='C' and t.orig_id_ticket is not null
            then t.amt
            else 0
      end
   ) as unconfirmedBillReturnAmt,
  --未确认退票总数
   sum(case
      when  t.status!='C' and t.orig_id_ticket is not null
            then 1
            else 0
      end
   ) as unconfirmedBillReturnCount,
  --未确认总数
  sum(case
     when  t.status!='C'
         then 1
         else 0
     end
)  as unconfirmedCount  from t_ticket t left join t_debtor_clear_list dc on t.id_ticket=dc.id_ticket
 where 1=1   and t.bill_date is not null
 --开帐日 在当前月中
  and to_char(t.bill_date,'yyyy-mm-dd')>='2009-06-01' and to_char(t.bill_date,'yyyy-mm-dd')<='2009-06-30'
  and t.bill_status='0'
   group by t.inv_seller_cid,t.inv_seller_name,t.debtor_cid,t.debtor_name,to_char(t.bill_date,'yyyy-mm-dd'),to_char(t.payoff_date,'yyyy-mm-dd'),t.bill_plan
 order by to_char(t.bill_date,'yyyy-mm-dd') asc,t.debtor_name desc) a,
 (
 select db.*
 from t_debtor_bill db where db.bill_status=1) b
 -- where a.invSellerCid!=b.bill_seller_cid and a.invSellerName!=b.bill_seller_name and a.debtorCid!=b.bill_debtor_cid and a.debtorName!=b.bill_debtor_name and a.billDate!=b.bill_date and a.payoffDate!=b.payoff_date and a.billPlan!=b.bill_plan
where a.invSellerCid=b.bill_seller_cid and a.invSellerName=b.bill_seller_name and a.debtorCid=b.bill_debtor_cid and a.debtorName=b.bill_debtor_name and a.billDate=to_char(b.bill_date,'yyyy-mm-dd') and a.payoffDate=to_char(b.payoff_date,'yyyy-mm-dd') and a.billPlan=b.bill_plan

 

分享到:
评论

相关推荐

    android仿支付宝账单统计图

    在Android开发中,为了提供用户友好的界面和丰富的交互体验,常常需要实现各种图表功能,如支付宝账单统计图所示。这种图表通常采用饼图的形式,因为它能够直观地展示各个部分占整体的比例,非常适合用于财务数据的...

    昱杰账单管理系统(ThinkPHP版) 网络账单管理 账单管理系统 php账单管理系统

    3、账单统计:按天、按月、按年全方位为您解析账单数据,一键导出账单统计数据到excel; 4、资金流动:经常将资金从一处流动到另一处,但又记不清每一笔的去向?别担心,此模块帮您记录。 系统模块: 1、系统设置:...

    财务仓库进货账单统计进销存管理系统

    《财务仓库进货账单统计进销存管理系统详解》 在当今的企业管理中,进销存管理系统扮演着至关重要的角色,它能有效地跟踪和管理商品的采购、销售和库存情况,提高企业的运营效率。本文将围绕“财务仓库进货账单统计...

    账单管理及报表

    开发者可能使用JDBC(Java Database Connectivity)来连接数据库,并编写SQL语句以按日期范围筛选账单数据。同时,系统还支持Ireport报表预览和打印,IReport是一款强大的报表设计工具,可以生成复杂的报表布局并...

    北大青鸟_超市账单管理系统(含sql语句在WebRoot下)

    - **INSERT**语句:插入新的记录,例如新增商品信息或新产生的购物账单。 - **UPDATE**语句:修改现有记录,如调整商品价格或更新库存。 - **DELETE**语句:删除不再需要的记录,如清理过期或滞销商品的信息。 - **...

    超市账单管理

    首先,超市账单管理系统的核心目标是实现对销售数据的自动化处理,包括记录商品销售、生成账单、统计销售额、管理库存等。这样的系统通常包含多个模块,如商品管理、订单管理、库存管理、客户管理以及报表分析等。 ...

    Python 统计年度消费账单 Python源码

    Python 统计年度消费账单 Python源码Python 统计年度消费账单 Python源码Python 统计年度消费账单 Python源码Python 统计年度消费账单 Python源码Python 统计年度消费账单 Python源码Python 统计年度消费账单 Python...

    python统计年度消费账单

    年度消费账单是指个人或家庭在一年内的所有消费记录...统计和分析:通过对消费数据的统计和分析,可以了解整体的消费水平、主要支出项目以及各类别的消费比例。这有助于识别消费习惯、发现潜在节省机会并进行财务规划。

    swift-仿支付宝账单统计日历周报选择

    "仿支付宝账单统计日历周报选择"就是一个典型的例子,它涉及到UI设计、事件处理以及数据绑定等多个方面。这个项目很可能是为了实现一个类似支付宝应用中的功能,让用户能够方便地查看和选择特定日期范围内的账单,...

    pb基本循环语句详解

    【PB基本循环语句详解】 在PowerBuilder (PB)编程中,循环语句是不可或缺的部分,它们用于重复执行一段代码,直到满足特定条件为止。...例如,你可能会在某个条件满足时,使用WHILE循环来处理多个账单记录。

    超市账单管理系统

    4. DAO层使用JDBC(Java Database Connectivity)连接Oracle数据库,执行SQL语句。 5. 数据处理完成后,Service将结果返回给Servlet,Servlet再将结果封装成HTTP响应,返回给浏览器。 6. 浏览器接收响应,解析HTML...

    安卓简单的账单管理软件

    添加账单意味着插入新记录,查询消费情况和查看记录涉及SELECT语句,而修改和删除则对应UPDATE和DELETE语句。 4. **UI交互** 应用界面通常包括添加账单的输入表单(日期选择器、金额输入框、类别选择等)、展示...

    个人账单管理系统(20190420最终版).rar

    2. **使用教程**:介绍系统界面和操作方法,包括账单录入、分类管理、统计分析等功能的使用。 3. **常见问题解答**:列出用户可能遇到的问题及解决办法,提高用户体验。 4. **数据库设计详解**:解释数据库的设计...

    家庭账单_家庭账单_

    4. **账务管理**:系统会自动统计每月的收入和支出,生成详细的收支报表,帮助用户了解家庭的财务状况。此外,还能设定预算,实时提醒用户当月的花费进度,防止超支。 5. **多人共享**:对于有多个家庭成员的家庭,...

    C语言程序设计课设简单的记账管理系统,提供了添加账单、显示账单列表、修改账单信息等功能,实现了对账单的增删改查与保存到文件的功能

    该项目为一个简单的账单管理程序,提供了添加账单、显示账单列表、修改账单信息等功能。通过该程序,我们可以轻松地管理和查询自己的消费记录,更好地维护个人财务状况。 该项目的主要功能和实现思路如下: 添加...

    基于JavaWeb的手机账单查询系统

    3. 结算功能:用户可以查看待结算账单,并进行在线支付,支持多种支付方式,如支付宝、微信支付等。 4. 管理员模块:管理员可以查看所有用户的账单,进行数据分析,处理缴费异常情况,如设置逾期提醒,处理退款请求...

    仿支付宝账单列表

    【标题】"仿支付宝账单列表"所涉及的知识点主要集中在UI设计和数据展示上,尤其是在Android开发领域。支付宝账单列表是一种常见的用户界面元素,它以清晰、有序的方式显示用户的交易记录,通常包括日期、金额、类别...

    超市账单管理系统.zip

    开发者可能使用SQL语句来操作这些数据,包括增删查改,以满足系统各种功能的需求。 系统原型设计是开发过程中的重要环节,它帮助开发者和用户可视化系统的基本功能和交互流程。在本项目中,原型设计可能包括了商品...

Global site tag (gtag.js) - Google Analytics