求一SQL - MS-SQL Server / 基础类
两表,
A 表(订单)
order style customer qty
1000 22 33 10
1000 22 33 -4
1000 22 33 -1
1000 44 33 8
1000 44 33 -4
B表(已出货)
order style customer qty
1000 22 33 2
1000 22 33 1
1000 44 33 3
想得到以下剩余量
order style customer qty
1000 22 33 2
1000 44 33 1
谢谢!
SQL code:
select a.order,a.style,a.customer,(sum(a.qty)-sum(b.qty)) qty
from a,b
where a.order=b.order,a.style=b.style,a.customer=b.customer
group by a.order,a.style,a.customer
SQL code:
select a.order,a.style,a.customer, (a.qty-b.qty) as [qty]
from (select order,style,cusomer,sum(qty) as qty
from tb_a
group by order,style,cusomer) a left join (select order,style,cusomer,sum(qty) as qty
from tb_b
group by order,style,cusomer)b
on a.order=b.order and a.style=b.style and a.customer=b.customer
我发现我是最笨的
相关问答:
执行的顺序:
1)文件浏览框(选择文件使用)
选择好文件后
点击一个导入按钮的时候 ,把上面上传框里的csv文件以一个ID为文件名,上传到**/**文件夹下
2)读取这个文件夹下的csv的文件,转换成sql
3 ......
可能因为工作的原因 接触数据库这块比较少,之前都是做程序这块,数据库这块都有专门的人来做 分工都很明细 所以对数据库这一块完全不了解。前段时间 去面试了几家公司 几乎都是在数据库这块挂掉的 连个简单的SQ ......
tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......
我觉得mysql和sqlserver有共同的地方:
有个问题是关于表的锁问题:
进程A 进程B
select * from user where id in lock share mode(共享锁)
&nb ......
有这样一条SQL
Select Get_Costtaxrate(col1), Get_Tcostvalue(col1) from a
其中Get_Costtaxrate、Get_Tcostvalue都是函数,这两个函数里面都是查找一个大表,Get_Tcostvalue还需要调用Get_C ......