C
channelxp
Unregistered / Unconfirmed
GUEST, unregistred user!
首先是视图SemiPcView,它的作用是把SemiSkTable里面的Amount与Rate字段进行相成,得出一个新字段OP,代码如下:<br><br>ALTER VIEW dbo.SemiPcView<br>AS<br>SELECT dbo.SemiSkTable.*, dbo.SemiTable.SemiName AS SemiName,<br> (SemiSkTable.amount*SemiSkTable.rate) AS OP,<br> dbo.SemiTable.Specs AS Specs, dbo.KilnTable.KilnName AS KilnName<br>FROM dbo.SemiSkTable INNER JOIN<br> dbo.SemiTable ON dbo.SemiSkTable.SemiID = dbo.SemiTable.SemiID INNER JOIN<br> dbo.KilnTable ON dbo.SemiSkTable.KilnID = dbo.KilnTable.KilnID<br><br>然后是SemiPcTotalView,它的作用是把刚才SemiPcView里面的Amount与OP字段根据SemiID进行求合再次生成2个新字段sum(Amount) as Amount 和 sum(OP) AS OP1,代码如下:<br><br>ALTER VIEW dbo.SemiPcTotalView<br>AS<br>SELECT SemiID, SemiName, Specs, sum(Amount) as Amount, sum(OP) AS OP1<br>FROM dbo.SemiPcView<br>group by SemiID, SemiName, Specs<br><br>最后就是产生我的目标视图SemiStView,就是在SemiPcTotalView的基础上,把Amount和OP1字段进行像除,生成字段Rate,代码如下:<br><br>ALTER VIEW dbo.SemiStView<br>AS<br>SELECT SemiID, SemiName, Specs, Amount, (OP1/Amount) as Rate<br>FROM dbo.SemiPcTotalView<br><br>既然3个视图是有关联的,我现在想把它们合成一个视图创建过程,直接生成SemiStView