统计支付成功金额最大的前三十个供应商1-5w等支付笔数.sql

 
 
select a.payeename,
(select count(one_) from
   (select l.payeename, case when (l.payamount >= 10000 and l.payamount < 50000) then 'one' else 'none' end as one_
      from cmcs3_transfer_bill tb ,cmcs3_transfer_bill_list l where tb.transferbillid = l.transferbillid
    and tb.stateid = 2 and l.bankstateid = 3
    and tb.submittime >= to_date('2011-01-01', 'yyyy-MM-dd')
    and tb.submittime < to_date('2012-01-01', 'yyyy-MM-dd')) x where x.one_ != 'none' and x.payeename = a.payeename
),
(select count(two_) from
   (select l.payeename,case when (l.payamount >= 50000 and l.payamount < 500000) then 'two'  else 'none' end as two_
       from cmcs3_transfer_bill tb ,cmcs3_transfer_bill_list l where tb.transferbillid = l.transferbillid
    and tb.stateid = 2 and l.bankstateid = 3
    and tb.submittime >= to_date('2011-01-01', 'yyyy-MM-dd')
    and tb.submittime < to_date('2012-01-01', 'yyyy-MM-dd')) x where x.two_ != 'none' and x.payeename = a.payeename
),
(select count(three_) from
   (select l.payeename,case when (l.payamount >= 500000 and l.payamount < 1000000) then 'three' else 'none' end as three_
      from cmcs3_transfer_bill tb ,cmcs3_transfer_bill_list l where tb.transferbillid = l.transferbillid
    and tb.stateid = 2 and l.bankstateid = 3
    and tb.submittime >= to_date('2011-01-01', 'yyyy-MM-dd')
    and tb.submittime < to_date('2012-01-01', 'yyyy-MM-dd')) x where x.three_ != 'none' and x.payeename = a.payeename
),
(select count(four_) from
   (select l.payeename,case when (l.payamount >= 1000000) then 'four' else 'none' end as four_
       from cmcs3_transfer_bill tb ,cmcs3_transfer_bill_list l where tb.transferbillid = l.transferbillid
    and tb.stateid = 2 and l.bankstateid = 3
    and tb.submittime >= to_date('2011-01-01', 'yyyy-MM-dd')
    and tb.submittime < to_date('2012-01-01', 'yyyy-MM-dd')) x where x.four_ != 'none' and x.payeename = a.payeename
)
from (select l.payeename as payeename,
  case when (l.payamount >= 10000 and l.payamount < 50000) then 'one' else 'none' end as one_,
  case when (l.payamount >= 50000 and l.payamount < 500000) then 'two'  else 'none' end as two_,
  case when (l.payamount >= 500000 and l.payamount < 1000000) then 'three' else 'none' end as three_,
  case when (l.payamount >= 1000000) then 'four' else 'none' end as four_
    from cmcs3_transfer_bill_list l where l.payeename in (select p.payeename from (
    select tbl.payeename,sum(tbl.payamount) as totalAmount from cmcs3_transfer_bill tb ,
    cmcs3_transfer_bill_list tbl
    where tb.transferbillid = tbl.transferbillid
    and tb.stateid = 2 and tbl.bankstateid = 3
    and tb.submittime >= to_date('2011-01-01', 'yyyy-MM-dd')
    and tb.submittime < to_date('2012-01-01', 'yyyy-MM-dd')
    group by tbl.payeename order by totalAmount desc
  ) p where rownum <= 30)) a group by a.payeename;
 
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值