我必须尽快解决此问题,但我是Transact-SQL
的新手。从现有视图创建视图
我有一个观点vStockSerialsTemp
:
Serial StockCode ActionPrice StockName Warehouse ActionType
123 P-0304 350 Galaxy S4 Centeral Income
456 P-0305 450 Iphone 5s Centeral Income
567 P-0305 450 Iphone 5s Centeral Income
123 P-0304 350 Galaxy S4 Centeral Expense
235 P-0304 350 Galaxy S4 Centeral Income
567 P-0305 450 Iphone 5s Centeral Expense
因此,基于这种观点,我要创建一个新的观点,即会计算每只股票的具有相同序列号的平衡。我们用ActionType减去行数 来自ActionType Income的相同序列的费用。因此,视图应该如下所示:
Serial StockCode ActionPrice StockName Warehouse ActionType
123 P-0304 350 Galaxy S4 Centeral Income
456 P-0305 450 Iphone 5s Centeral Income
567 P-0305 450 Iphone 5s Centeral Income
123 P-0304 350 Galaxy S4 Centeral Expense
235 P-0304 350 Galaxy S4 Centeral Income
567 P-0305 450 Iphone 5s Centeral Expense
-----------------------------------------------------------------
456 P-0305 450 Iphone 5s Centeral Balance
235 P-0304 350 Galaxy S4 Centeral Balance
CREATE vStockSerials as
SELECT * FROM [dbo].[dbo.vStockSerialsTemp]
UNION
// Here is the problem indeed
如何从vStockSerialsTemp
这里选择行?
你能告诉我们什么应该是你创建的新视图的最终输出? – Vasan
我已经定义了最终的View,第二个! –