如何使用屏幕截图表获取每个产品代码的期初余额和期末余额。sql server 2008。
从截图来看,产品代码1已经发布了两次,最后余额反映了当前余额....我需要获取所有产品代码的最后余额。
select TOP 1 Balance as OpeningBalance
from StockTransfer where ProductCode = 1 and TransferType = 'Product'
and TransactionDate between '2013-03-17' and '2013-03-22'
select TOP 1 Balance as ClosingBalance
from StockTransfer where ProductCode = 1 and TransferType = 'Product'
and TransactionDate between '2013-03-17' and '2013-03-22'
order by TransactionDate desc
但这仅适用于一种产品。