スクリーンショット テーブルを使用して各 productCode の期首残高と期末残高を取得する方法を教えてください。sql server 2008.
ショットから、製品コード 1 は 2 回発行され、最後の残高は現在の残高を反映しています....すべての製品コードの最後の残高を取得する必要があります。
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
ただし、これは 1 つの製品に対してのみ機能します。