使用 T-SQL 中的单个查询的 FIFO 库存老化报告

问题描述

我有一个库存交易表:

产品 日期 方向 数量
A 日期 1 输入 3
B 日期 2 输入 55.7
A 日期 3 退出 1
B 日期 3 退出 8
B 日期 3 输入 2

我可以通过以下查询轻松获取任何日期的库存:

import React,{ useState } from 'react'

const Artist = ({ currentArtist }) => {
  const [isGhost,setIsGhost] = useState(false)
  const ghostify = () => setIsGhost(!isGhost)
  const { vid,ghostVid,name,title } = currentArtist

  return (
    <div className='artist'>
      <img src={isGhost ? vid : ghostVid} alt={name} />
      {name && <h2>{name}</h2>}
      {title && <h3>{title}</h3>}
      <button onClick={() => ghostify}>Ghostify</button>
    </div>
  )
}

export default Artist

现在我的目的是使用先进先出原则让股票像这样老化

产品 总库存 0-30 天 31-60 天 61-90 天 91+ 天
A 3 3 0 0 0
B 34.2 10 14.2 7 3
C 25 20 3 1 1
D 10 2 8 0 0
E 1 0 0 1 0

我使用的是 sql Server 2016 和 SSMS 18。 解决方案应该快速,因为它适用于3,000,000+行的表。 单一查询是首选,因为它将被集成到 ERP 系统中。 经过数周的研究,我还没有找到基于单个查询解决方案。任何帮助表示赞赏。提前致谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)