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