我试图通过在我之前制作的数据库上创建视图来进行SQL查询。在查看具有联接的表之前它工作正常,但是现在当我尝试创建一个视图时,我得到一个"不正确的语法接近'。'"来自第一个INNER JOIN语句的错误消息。为什么会这样?
CREATE VIEW vm_order_cost
AS
SELECT orders.order_id,
orders.order_date,
products.product_id,
customers.name,
order_cost = (order_details.quantity * products.unit_price)
FROM orders
INNER JOIN customers AS orders.customer_id = customers.customer_id
INNER JOIN order_details AS orders.order_id = order_details.order_id
INNER JOIN products AS order_details.product_id = products.product_id
WHERE order_id BETWEEN '10000' AND '10200'
GO
答案 0 :(得分:4)
您应该使用ON
代替AS
:
CREATE VIEW vm_order_cost
AS
SELECT orders.order_id,
orders.order_date,
products.product_id,
customers.name,
order_cost = (order_details.quantity * products.unit_price)
FROM orders
INNER JOIN customers ON orders.customer_id = customers.customer_id
INNER JOIN order_details ON orders.order_id = order_details.order_id
INNER JOIN products ON order_details.product_id = products.product_id
WHERE order_id BETWEEN '10000' AND '10200'