码迷,mamicode.com
首页 > 其他好文 > 详细

卡类消费明细

时间:2014-09-03 15:08:07      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:where

--------------------

--查询收款明细

select L.SKTNO,L.JLBH,C.DEPTID,L.JZRQ,L.JYSJ

  into #SKTJL

  from BFBHDD.SKTXSJL L,BFBHDD.SKTXSJLC C

 where L.SKTNO=C.SKTNO

   and L.JLBH=C.JLBH

   and L.JZRQ>=‘2014-8-1‘

   and L.JZRQ<=‘2014-8-31‘

 group by L.SKTNO,L.JLBH,C.DEPTID,L.JZRQ,L.JYSJ


select * from #SKTJL


--drop table #SKTJL


--获取消费明细

insert into BFBHDD.CZKXFJL

select L.DEPTID,D.HTH,X.KKBL,L.SKTNO,L.JLBH,L.JZRQ,L.JYSJ,sum(M.SKJE) SKJE,sum(M.SKJE)*X.KKBL KKJE

  from BFBHDD.SKTXSJLM M,#SKTJL L,BFBHDD.HT_KKXM X,BFBHDD.HT_DHBM D

 where L.SKTNO=M.SKTNO

   and L.JLBH=M.JLBH

   and L.DEPTID=D.DEPTID

   and D.HTH=X.HTH

   and M.SKFS in (15,3,16,18)

   and X.KKXMID=15

   and D.HTH<90000000

 group by L.DEPTID,D.HTH,X.KKBL,L.SKTNO,L.JLBH,L.JZRQ,L.JYSJ


select * from #SKBL


--获取扣款比率等数据

insert into BFBHDD.KKBL

select L.DEPTID,D.HTH,201408,X.KKBL,I.YKKJE,sum(M.SKJE) SKJE,sum(M.SKJE)*X.KKBL KKJE

  from BFBHDD.SKTXSJLM M,#SKTJL L,BFBHDD.HT_KKXM X,BFBHDD.HT_DHBM D,BFBHDD.JSDKKITEM I

 where L.SKTNO=M.SKTNO

   and L.JLBH=M.JLBH

   and L.DEPTID=D.DEPTID

   and D.HTH=X.HTH

   and M.SKFS in (15,3,16,18)

   and X.KKXMID=15

   and D.HTH<90000000

   and I.DEPTID=L.DEPTID

   and I.JSKKID=15

 group by L.DEPTID,D.HTH,X.KKBL,I.YKKJE


---------------------------

drop table BFBHDD.CZKXFJL

GO

create table BFBHDD.CZKXFJL(

JLBH      int         identity,

DEPTID   varchar(10)        not null,

HTH int not null,

KKBL float not null,

SKTNO varchar(3) not null,

SKTJLBH int not null,

JZRQ datetime not null,

JYSJ datetime not null,

SKJE money not null,

KKJE money not null,

constraint PK_CZKXFJL PRIMARY KEY CLUSTERED (JLBH)

)

with identity_gap=1

GO


drop table BFBHDD.KKBL

GO

create table BFBHDD.KKBL(

JLBH      INT           identity,

DEPTID varchar(10) not null,

HTH     int  not null,

YEARMONTH int not null,

KKBL      float         not null,

YKKJE money null,

SKJE      money    not null,

KKJE       money         not null,

constraint PK_KKBL PRIMARY KEY CLUSTERED (JLBH)

)with identity_gap=1

GO



-------------------------


卡类消费明细

标签:where

原文地址:http://lj1987.blog.51cto.com/167978/1548268

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!