公司要取个表报,求帮助
有7个店,他们有会员卡。 想取往来账目,就是A店的会员卡 去其他几个店花了多钱,其他几个店的会员在A店花了多钱。谁能帮帮我写个简单的。我写的太麻烦
--本店在其他店商品消费
select d.deptname, b.deptname deptnameM,sum(a.TotalAmt) Price into #a from dbo.CusOrderM a
left join basdept b on a.deptno=b.deptno
inner join Customer c on a.CustomerNo =c.CustomerNo
left join basdept d on c.deptno =d.deptno
where a.deptno<>'010101' and c.deptno='010101' and a.paytype=0 and a.IfFree=0 and a.docno
not in(select orderno from OrderReservation where a.docno=orderno) and a.DocDate>='2016-1-1' and a.DocDate<'2016-5-1'
group by d.deptname, b.deptname
--本店在其他店服务消费
select d.deptname, b.deptname deptnameM,sum(a.Price) Price into #b from dbo.OrderReservation a
left join basdept b on a.deptno=b.deptno
inner join Customer c on a.CustomerNo =c.CustomerNo
left join basdept d on c.deptno =d.deptno
where a.deptno<>'010101' and c.deptno='010101' and a.paytype=0 and a.IfFree=0 and a.PlaceTime>='2016-1-1' and a.PlaceTime<'2016-5-1'
group by d.deptname, b.deptname
--本店在其他店续卡
select d.deptname, b.deptname deptnameM,-sum(a.RechAmount) Price into #c from RechargeRecord a
left join basdept b on a.deptno=b.deptno
inner join Customer c on a.CustomerNo =c.CustomerNo
left join basdept d on c.deptno =d.deptno
where a.deptno<>'010101' and c.deptno='010101' and a.Rechtime>='2016-1-1' and a.Rechtime<'2016-5-1'
group by d.deptname, b.deptname
--其他店在本店商品消费
select d.deptname, b.deptname deptnameM,sum(a.TotalAmt) Price into #d from dbo.CusOrderM a
left join basdept b on a.deptno=b.deptno
inner join Customer c on a.CustomerNo =c.CustomerNo
left join basdept d on c.deptno =d.deptno
where a.deptno='010101' and c.deptno<>'010101' and a.paytype=0 and a.IfFree=0
and a.docno not in(select orderno from OrderReservation where a.docno=orderno) and a.DocDate>='2016-1-1' and a.DocDate<'2016-5-1'
group by d.deptname, b.deptname
--其他店在本店服务消费
select d.deptname, b.deptname deptnameM,sum(a.Price) Price into #e from dbo.OrderReservation a
left join basdept b on a.deptno=b.deptno
inner join Customer c on a.CustomerNo =c.CustomerNo
left join basdept d on c.deptno =d.deptno
where a.deptno='010101' and c.deptno<>'010101' and a.paytype=0 and a.IfFree=0 and a.PlaceTime>='2016-1-1' and a.PlaceTime<'2016-5-1'
group by d.deptname, b.deptname
--其他店在本店续卡
select d.deptname, b.deptname deptnameM,-sum(a.RechAmount) Price into #f from RechargeRecord a
left join basdept b on a.deptno=b.deptno
inner join Customer c on a.CustomerNo =c.CustomerNo
left join basdept d on c.deptno =d.deptno
where a.deptno='010101' and c.deptno<>'010101' and a.Rechtime>='2016-1-1' and a.Rechtime<'2016-5-1'
group by d.deptname, b.deptname
--取本店和其他店来往帐
select * into #dept from (
select #a.deptname,#a.deptnameM from #a
union
select #b.deptname,#b.deptnameM from #b
union
select #c.deptname,#c.deptnameM from #c
union
select #d.deptnameM,#d.deptname from #d
union
select #e.deptnameM,#e.deptname from #e
union
select #f.deptnameM,#f.deptname from #f) a
--取报表
select #dept.deptname '门店', #dept.deptnameM '其他门店',#a.Price '本店会员在其他门店消费产品',
#b.Price '本店会员在其他门店消费服务',#c.Price '本店会员在其他门店消费续卡',#a.Price+#b.Price+#c.Price '支出合计',
#d.Price '其他店会员在本店消费产品',#e.Price '其他店会员在本店消费服务',#f.Price '其他店会员在本店消费服务续卡',#d.Price+#e.Price+#f.Price '总收入'
from #dept
left join #a on #dept.deptname=#a.deptname and #dept.deptnameM=#a.deptnameM
left join #b on #dept.deptname=#b.deptname and #dept.deptnameM=#b.deptnameM
left join #c on #dept.deptname=#c.deptname and #dept.deptnameM=#c.deptnameM
left join #d on #dept.deptname=#d.deptnameM and #dept.deptnameM=#d.deptname
left join #e on #dept.deptname=#e.deptnameM and #dept.deptnameM=#e.deptname
left join #f on #dept.deptname=#f.deptnameM and #dept.deptnameM=#f.deptname
drop table #a,#b,#c,#d,#e,#f,#dept
--本店在其他店商品消费
select d.deptname, b.deptname deptnameM,sum(a.TotalAmt) Price into #a from dbo.CusOrderM a
left join basdept b on a.deptno=b.deptno
inner join Customer c on a.CustomerNo =c.CustomerNo
left join basdept d on c.deptno =d.deptno
where a.deptno<>'010101' and c.deptno='010101' and a.paytype=0 and a.IfFree=0 and a.docno
not in(select orderno from OrderReservation where a.docno=orderno) and a.DocDate>='2016-1-1' and a.DocDate<'2016-5-1'
group by d.deptname, b.deptname
--本店在其他店服务消费
select d.deptname, b.deptname deptnameM,sum(a.Price) Price into #b from dbo.OrderReservation a
left join basdept b on a.deptno=b.deptno
inner join Customer c on a.CustomerNo =c.CustomerNo
left join basdept d on c.deptno =d.deptno
where a.deptno<>'010101' and c.deptno='010101' and a.paytype=0 and a.IfFree=0 and a.PlaceTime>='2016-1-1' and a.PlaceTime<'2016-5-1'
group by d.deptname, b.deptname
--本店在其他店续卡
select d.deptname, b.deptname deptnameM,-sum(a.RechAmount) Price into #c from RechargeRecord a
left join basdept b on a.deptno=b.deptno
inner join Customer c on a.CustomerNo =c.CustomerNo
left join basdept d on c.deptno =d.deptno
where a.deptno<>'010101' and c.deptno='010101' and a.Rechtime>='2016-1-1' and a.Rechtime<'2016-5-1'
group by d.deptname, b.deptname
--其他店在本店商品消费
select d.deptname, b.deptname deptnameM,sum(a.TotalAmt) Price into #d from dbo.CusOrderM a
left join basdept b on a.deptno=b.deptno
inner join Customer c on a.CustomerNo =c.CustomerNo
left join basdept d on c.deptno =d.deptno
where a.deptno='010101' and c.deptno<>'010101' and a.paytype=0 and a.IfFree=0
and a.docno not in(select orderno from OrderReservation where a.docno=orderno) and a.DocDate>='2016-1-1' and a.DocDate<'2016-5-1'
group by d.deptname, b.deptname
--其他店在本店服务消费
select d.deptname, b.deptname deptnameM,sum(a.Price) Price into #e from dbo.OrderReservation a
left join basdept b on a.deptno=b.deptno
inner join Customer c on a.CustomerNo =c.CustomerNo
left join basdept d on c.deptno =d.deptno
where a.deptno='010101' and c.deptno<>'010101' and a.paytype=0 and a.IfFree=0 and a.PlaceTime>='2016-1-1' and a.PlaceTime<'2016-5-1'
group by d.deptname, b.deptname
--其他店在本店续卡
select d.deptname, b.deptname deptnameM,-sum(a.RechAmount) Price into #f from RechargeRecord a
left join basdept b on a.deptno=b.deptno
inner join Customer c on a.CustomerNo =c.CustomerNo
left join basdept d on c.deptno =d.deptno
where a.deptno='010101' and c.deptno<>'010101' and a.Rechtime>='2016-1-1' and a.Rechtime<'2016-5-1'
group by d.deptname, b.deptname
--取本店和其他店来往帐
select * into #dept from (
select #a.deptname,#a.deptnameM from #a
union
select #b.deptname,#b.deptnameM from #b
union
select #c.deptname,#c.deptnameM from #c
union
select #d.deptnameM,#d.deptname from #d
union
select #e.deptnameM,#e.deptname from #e
union
select #f.deptnameM,#f.deptname from #f) a
--取报表
select #dept.deptname '门店', #dept.deptnameM '其他门店',#a.Price '本店会员在其他门店消费产品',
#b.Price '本店会员在其他门店消费服务',#c.Price '本店会员在其他门店消费续卡',#a.Price+#b.Price+#c.Price '支出合计',
#d.Price '其他店会员在本店消费产品',#e.Price '其他店会员在本店消费服务',#f.Price '其他店会员在本店消费服务续卡',#d.Price+#e.Price+#f.Price '总收入'
from #dept
left join #a on #dept.deptname=#a.deptname and #dept.deptnameM=#a.deptnameM
left join #b on #dept.deptname=#b.deptname and #dept.deptnameM=#b.deptnameM
left join #c on #dept.deptname=#c.deptname and #dept.deptnameM=#c.deptnameM
left join #d on #dept.deptname=#d.deptnameM and #dept.deptnameM=#d.deptname
left join #e on #dept.deptname=#e.deptnameM and #dept.deptnameM=#e.deptname
left join #f on #dept.deptname=#f.deptnameM and #dept.deptnameM=#f.deptname
drop table #a,#b,#c,#d,#e,#f,#dept

...全文
相关推荐
求余与取模的区别
通常情况下取模运算(mod)和求余(rem)运算被混为一谈,因为在大多数的编程语言里,都用'%'符号表示取模或者求余运算。在这里要提醒大家要十分注意当前环境下'%'运算符的具体意义,因为在有负数存在的情况下,两者的结果是不一样的。
表报开发实例 javaweb
表报开发实例javaweb 这是个源码包,采用ireport5设计表报,myeclipse开发的web项目。
专题资料(2021-2022年)KIP表报分析与管理PPT 30页.ppt
专题资料
js取模(求余数)隔行变色
今天需要用js实现做隔行变色功能,原来用的是asp程序都是用mod取模,原来js中用的是%,具体如下需要的朋友可以参考下
C# 报表设计器 (winform 设计端)开发与实现生成网页的HTML报表 开放源码及调试
记得2000年之前,公司的项目基本上都要用到报表,以前我们常用的方法就是针对客户的需求来定制化开发(基本上是死写代码)来实现,经常导致项目经常性的延期,因为客户的需求经常会变化,随着用户的使用认知度的提高,对报表的要求越来越高,导致程序员不停的修改代码来实现,效率不高、结束遥遥无期。。。非常的痛苦;当然市面上有很多报表开发工具可以实现,但是针对小公司来说采购一套这样的系统的成本也非常的高,所以我们


