![](/img/trans.png)
[英]Creating a VIEW from multiple tables each with a different number of columns
[英]creating a view from multiple tables with no like columns
我正在處理一個作業問題,感到很沮喪。 這是問題:
這是我所擁有的,而我得到的錯誤是“無效的列名FinalPrice”
USE th0664920
GO
CREATE VIEW Order_Item_Products
AS
SELECT o.OrderID, o.OrderDate, o.TaxAmount, o.ShipDate, p.ProductName
FROM Orders AS o, Products AS p
GO
SELECT ItemPrice, DiscountAmount, (ItemPrice - DiscountAmount) AS
FinalPrice, Quantity, (FinalPrice + TaxAmount) AS ItemTotal
FROM OrderItems, Orders;
我不想讓任何人為我寫這篇文章,但是我希望得到幫助以了解我在做錯什么來得到該錯誤。 先感謝您
幾個問題
在第一個
使用不來自表的聯接,表語法
需要一個加入條件-最有可能的productID
在第二
不確定
一個視圖應該是一個查詢
您的查詢有很多問題,但是您自己承認,您才剛剛開始。 您遇到的特定錯誤是因為您使用的數據庫引擎不允許您按照嘗試的方式在select子句中使用別名。 具體來說,您有:
SELECT ItemPrice
, DiscountAmount
, (ItemPrice - DiscountAmount) AS FinalPrice
, Quantity
, (FinalPrice + TaxAmount) AS ItemTotal
FinalPrice
是別名,而不是列。 大多數數據庫引擎都會拋出錯誤,就像您使用的那樣。 您必須重復計算。 換句話說,這是:
, (FinalPrice + TaxAmount) AS ItemTotal
必須是這個
, (ItemPrice -DiscountAmount + TaxAmount) AS ItemTotal
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.