V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  tkhlo  ›  全部回复第 5 页 / 共 5 页
回复总数  82
1  2  3  4  5  
2022-12-21 16:25:51 +08:00
回复了 BeijingBaby 创建的主题 奇思妙想 dev.com.cn 征集中文名称
网络取名一律叫王富贵(手动狗头)
2022-12-21 10:46:20 +08:00
回复了 yixuling 创建的主题 数据库 请教一个关于 sql server 多对多核销的问题
这是先进先出计算利润的方法,看下有没有参考价值:

select identity(int,1,1) ID,* into #1 from Tin order by 品种,时间
select 品种,sum(数量) 数量 into #2 from Tout group by 品种

select 品种,sum(数量) 数量,sum(数量*价格) 金额
from (
select a.品种,
(case when (select sum(数量) from #1 where ID<=a.ID and 品种=a.品种)<= b.数量 then 0 else
(case when (select isnull(sum(数量),0) from #1 where ID<a.ID and 品种=a.品种)<= b.数量 then
(select sum(数量) from #1 where ID<=a.ID and 品种=a.品种)-b.数量 else a.数量 end) end) 数量,
价格
from #1 a,#2 b
where a.品种=b.品种) a
group by 品种
1  2  3  4  5  
关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   5285 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 17ms · UTC 07:23 · PVG 15:23 · LAX 23:23 · JFK 02:23
♥ Do have faith in what you're doing.