请教一个sql语句的写法 select k.id,sum(k.qty) from (select * from t_stock_in union all select * from t_stock_out) k group by k.id 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select a.id ,a.qty + b.qty as qtyfrom t_stock_in left join t_stock_outon a.id = b.id 感谢各位,再问如果有三个表以上两个不变,再增加一个表t_stock依然有两个字段,id 和 qty用t_stock 中的每一条数据,加上t_stock_in 中的数据,再减去t_stock_out中的每一条数据,如何得到结果呢??? select *,qty + (select sum(qty) from t_stock_in where id = t_stock.id) - (select sum(qty) from t_stock_Out where id = t_stock.id)from t_stock select *,qty + (select sum(qty) from t_stock_in where id = t_stock.id) - (select sum(qty) from t_stock_Out where id = t_stock.id)from t_stock playyuer(小干部儿) :我是想得到计算后a:??b:??c:??d:?阿,你这样得不到阿 建立临时表,再把全部表的记录insert 临时表,再 group by id 或者select [id]+':'+convert(varchar(10),qty)from (select [id],qty=sum(qty)from (select a.* from aunion select b.* from b)as tgroup by [id])as tt select k.id,':',sum(k.qty) from (select * from t_stock_in union all select * from t_stock_out) k group by k.id 如何快速生成随即串码 15亿 这样设计数据库的表如何? 挪到这里问一下啊 关于一个MSSQL 现有的数据库问题 不知道是架构还是前缀,2000导入2005数据出错 大家快来帮我看看,数据库之间的表复制问题.................(在线等待) 我用SQL SEVER数据库开发数据库软件,如何做才能把数据库移植到别的机器呢?(自己写程序) Jsp+Tomcat+Sql Server2000问题! SQL Server中为什么不能设置1个以上的text列 那位高手知道如何刷新表格控件的行标记? sql server 2000? 求教
from t_stock_in left join t_stock_out
on a.id = b.id
依然有两个字段,id 和 qty
用t_stock 中的每一条数据,加上t_stock_in 中的数据,再减去t_stock_out
中的每一条数据,如何得到结果呢???
qty + (select sum(qty) from t_stock_in where id = t_stock.id) - (select sum(qty) from t_stock_Out where id = t_stock.id)
from t_stock
+ (select sum(qty)
from t_stock_in
where id = t_stock.id)
- (select sum(qty)
from t_stock_Out
where id = t_stock.id)
from t_stock
from
(
select [id],qty=sum(qty)
from
(
select a.*
from a
union
select b.*
from b
)as t
group by [id]
)as tt
from (select * from t_stock_in
union all
select * from t_stock_out) k
group by k.id