SUMSEN

Oracle&Sql爱好者,用友NC管理员

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

 select o.orgname,t3.sumb,b.period,b.balamt,b.busdate,b.createdate
 from new_jsjg_ie.dbo.iest_balance b,new_jsjg_ie.dbo.iecm_org o,
(select   orgname+max(period) nm,sum(b.balamt) sumb
 from new_jsjg_ie.dbo.iest_balance b,new_jsjg_ie.dbo.iecm_org o
 where b.orgid=o.id and b.balamt<>0 group by  o.orgname)t3
where b.orgid=o.id
and  o.orgname+b.period=nm  order by period desc

1.9号更新,增加所属分公司

select (select  orgname from new_jsjg_ie.dbo.iecm_org  where id=c.locationindeprid) 所属分公司,
 c.contractno 合同编码,o.orgname 项目名称,
convert(varchar(100),c.planstartdate,23)合同开始时间,
convert(varchar(100),c.planenddate,23)合同结束时间,
convert(varchar(100),convert(decimal(18,2),c.contractcost))+''  合同额,
convert(varchar(100),convert(decimal(18,2),t3.sumb/10000))+'' 开累业主计量,
b.period 最新月,convert(varchar(100),convert(decimal(18,2),b.balamt/10000))+'' 最新月业主计量,
convert(varchar(100),b.busdate,23) 建账日期
 from new_jsjg_ie.dbo.iest_balance b,new_jsjg_ie.dbo.iecm_org o, new_jsjg_ie.dbo.iect_contract c ,
(select   orgname+max(period) nm,sum(b.balamt) sumb
 from new_jsjg_ie.dbo.iest_balance b,new_jsjg_ie.dbo.iecm_org o 
 where b.orgid=o.id and b.balamt<>0 group by  o.orgname)t3
where b.orgid=o.id
      and o.id=c.orgid
      and  o.orgname+b.period=nm
      and c.contracttype='P1'
  order by period desc

posted on 2013-01-08 17:45  sumsen  阅读(543)  评论(0编辑  收藏  举报