select a.商品名,a.规格,a.单价,a.数量+b.数量-c.数量 as 库存,a.金额+b.金额-c.金额
from a,b,c
where a.商品名=b.商品名 and a.商品名=c.商品名
解决方案 »
- **********请问关于sql2005中AWE的问题*************
- 数字化档案管理,那些图片是怎么存放好?
- 超有难度啊,求一SQL语句啊
- 存储过程可以跨数据库执行吗?
- 一个排序问题,请大家帮帮我,在线等.........急
- sql2008企业版登陆报错
- 那位大哥能指点我做bcb+sql server,多谢了,建议即可。
- 求一个求加权平均分的语句
- @@@@@@@@ 字段合成问题 ¥¥¥¥¥¥
- 怎样写一个涵数,类于sum ,例:select myfun(aa) as aa from table 其中myfun 是我将要定义的函数,请问,应怎样去写这个函数?
- SQL server安装问题,先谢谢各位大哥大姐了
- 如何使别人不能注册我的SQL Server?解决即给分。
a 1*1 0.20000000000000001 35.0 7.0
c 2*4 0.10000000000000001 80.0 8.0
e 2*2 0.5 20.0 10.0
a 1*1 0.20000000000000001 35.0 7.0
c 2*4 0.10000000000000001 80.0 8.0
e 2*2 0.5 20.0 10.0
a 1*1 0.20000000000000001 35.0 7.0
c 2*4 0.10000000000000001 80.0 8.0
e 2*2 0.5 20.0 10.0
declare @b table([商品名] varchar(10),[规格] varchar(10),[单价] decimal(12,1),[数量] int,[金额] money)
declare @c table([商品名] varchar(10),[单价] decimal(12,1),[数量] int,[金额] money)insert @a
select 'a','1*1',0.2,10,2 union
select 'b','3*5',0.6,20,12 union
select 'c','2*4',0.1,30,3 union
select 'd','1*2',0.8,20,16 union
select 'e','2*2',0.5,10,5 insert @b
select 'a','1*1',0.2,30,6 union
select 'c','2*4',0.1,60,6 union
select 'e','2*2',0.5,20,10 insert @c
select 'a',0.2,5,1 union
select 'c',0.1,10,1 union
select 'e',0.5,10,5select A.[商品名],
[数量]=A.[数量]-isnull(C.[数量],0),
[金额]=A.[金额]-isnull(C.[金额],0)from (
select [商品名],[数量]=sum([数量]),[金额]=sum(金额)
from
(
select * from @a
union all
select * from @b
)T group by [商品名]
) A
left join
(
select [商品名],[数量]=sum([数量]),[金额]=sum(金额) from @c group by [商品名]
) C on A.[商品名]=C.[商品名]--结果
/*
商品名 数量 金额
---------- ----------- ---------------------
a 35 7.0000
b 20 12.0000
c 80 8.0000
d 20 16.0000
e 20 10.0000(所影响的行数为 5 行)
*/