Try:
select T.cpbh,
sum(T.sl),
sum(T.sl*T.jg),
sum(T.sl)*(select sum(dj) WLDA where wlbh in(select wlbh from PF where cpbh=T.cpbh))*(select sum(yl) from PF where cpbh=T.cpbh),
sum(T.sl*T.jg)-sum(T.sl)*(select sum(dj) WLDA where wlbh in(select wlbh from PF where cpbh=T.cpbh))*(select sum(yl) from PF where cpbh=T.cpbh)
from XFJLB T
group by cpbh
select T.cpbh,
sum(T.sl),
sum(T.sl*T.jg),
sum(T.sl)*(select sum(dj) WLDA where wlbh in(select wlbh from PF where cpbh=T.cpbh))*(select sum(yl) from PF where cpbh=T.cpbh),
sum(T.sl*T.jg)-sum(T.sl)*(select sum(dj) WLDA where wlbh in(select wlbh from PF where cpbh=T.cpbh))*(select sum(yl) from PF where cpbh=T.cpbh)
from XFJLB T
group by cpbh
解决方案 »
- sp_adddistributor中的@password是什么密码??
- 郁闷~~ 希望醒来的时候有人可以为我解答....一个未解决的触发器问题(80分)
- 【sql2000问题】数据导入问题.......
- 比较复杂的sql语句,请高手帮忙?
- 超级简单问题 sql 2005 express edition beta 2 如何建一个数据库?100分送上
- 像51job的那种多条件并且带关键字的SQL查询
- 关于sql关联查询问题
- SQL2005如果创建几十万个表,对读写的性能影响大不大呢
- 向临时表动态添加的列为什么不能马上查询呢?
- 怎样用sqlserver实现全文检索?
- 请教现在的论坛一般用什么数据库比较多一些
- 在winxp sp2的操作系统上装sql server2000,是不是会将mdac的版本降低呀?
a.cpbh,
sum(a.sl*a.jg),
sum(a.sl*c.ckpjdj*b.yl),
sum(a.sl*a.jg)-sum(a.sl*c.ckpjdj*b.yl)
from
XFJLB a,
PF b,
WLDA c
where
a.cpbh=b.cpbh and b.wlbh=c.wlbh
group by
a.cpbh
a.cpbh as 编号,
sum(a.sl) as 销售数量,
sum(a.sl*a.jg) as 销售金额,
sum(a.sl*c.dj*b.yl) as 物料成本,
sum(a.sl*a.jg)-sum(a.sl*c.dj*b.yl) as 利润
from XFJLB a inner join PF b on a.cpbh=b.cpbh
inner join WLDA c on b.wlbh=c.wlbh
group by a.cpbh