日期:2014-05-20  浏览次数:20641 次

今天为止 人生最长sql
select n.neco_id,
  n.neco_name,
  n.neco_userid_fk,
  n.neco_regional,
  n.neco_balancetype,
  newcoop_data.nqcp,
  newcoop_data.boss
  from (select n.neco_id newcoopId,
  sum(cc.ccbd_newuserchecknum) boss,
  sum(cd.cdse_newuserchecknum) nqcp
  from userinfov2.tbl_stat_coopcheckbyruledaily cc,
  boss_nqcp.tbl_nqcp_coopdailysettlement_r cd,
  userinfov2.tbl_cooperator c,
  userinfov2.tbl_newcooperator_i n
  where cc.ccbd_coopid_fk = cd.cdse_coopid_fk(+)
  and cc.ccbd_date = cd.cdse_date(+)
  and c.coop_id = cc.ccbd_coopid_fk
  and c.coop_necoid_fk = n.neco_id
  and c.coop_onlinestatus = 1
  and c.coop_paytype = 2
  and c.coop_balance_state = 1
  and n.neco_onlinestatus = 1
  and n.neco_userid_fk = 'sunchengqi'
  and n.neco_regional = 0
  and cc.ccbd_date between
  to_date('2008-08-01 00:00:00', 'yyyy/MM/DD hh24:mi:ss') and
  to_date('2008-08-31 23:59:59', 'yyyy/MM/DD hh24:mi:ss')
  group by n.neco_id
  union
  select n.neco_id newcoopId,
  sum(sm.smco_newuserchecknum) boss,
  sum(ic.icds_newuserchecknum) nqcp
  from USERINFOV2.TBL_STAT_SETTLEMENTBYCOUN_H sm,
  boss_nqcp.TBL_NQCP_INTERCOOPDAILYSETT_R ic,
  userinfov2.tbl_cooperator c,
  userinfov2.tbl_newcooperator_i n
  where sm.smco_coopid_fk = ic.icds_coopid_fk(+)
  and sm.smco_counid_fk = ic.icds_counid_fk(+)
  and sm.smco_date = ic.icds_date(+)
  and c.coop_id = sm.smco_coopid_fk
  and c.coop_necoid_fk = n.neco_id
  and c.coop_onlinestatus = 1
  and c.coop_paytype = 2
  and c.coop_balance_state = 1
  and n.neco_onlinestatus = 1
  and n.neco_userid_fk = 'sunchengqi'
  and n.neco_regional = 1
  and sm.smco_date between
  to_date('2008-08-01 00:00:00', 'yyyy/MM/DD hh24:mi:ss') and
  to_date('2008-08-31 23:59:59', 'yyyy/MM/DD hh24:mi:ss')
  and exists
  (select chco.chco_counid_fk
  from boss_nqcp.tbl_nqcp_channelcountry_c chco
  where chco.chco_coopid_fk = c.coop_id
  and chco.chco_counid_fk = sm.smco_counid_fk)
  group by n.neco_id
  union
  select yzboss.newcoopId, yzboss.num boss, yznqcp.num nqcp
  from (select yztmp.newcoopId, sum(yztmp.num) num
  from (select n.neco_id newcoopId, count(ccbi.ccbi_imei) num
  from userinfov2.TBL_STAT_COOPCHECKBYIMEI ccbi,
  userinfov2.tbl_cooperator c,
  userinfov2.tbl_newcooperator_i n
  where ccbi.ccbi_coopid_fk = c.coop_id
  and c.coop_necoid_fk = n.neco_id
  and c.coop_onlinestatus = 1
  and c.coop_paytype = 2
  and c.coop_balance_state = 1
  and n.neco_onlinestatus = 1
  and n.neco_userid_fk = 'sunchengqi'
  and n.neco_regional = 2