将CREATE VIEW与多个表一起使用

时间:2017-10-04 07:04:42

标签: mysql

我正在尝试使用CREATE VIEW以及来自3个不同表格的多个单元格,并在两个单元格之间进行相乘。这个地方有一个语法错误,但我似乎无法识别它。

CREATE VIEW ORDERS AS CustFirstname, CustLastName, o.Ordernumber AS OrderNumber, 
o. OrderDate AS OrderDate, o.ShipDate AS ShipDate, c.QuotedPrice, 
c.QuantityOrdered, c.QuotedPrice * c.QuantityOrdered AS ItemTotal FROM Customers 
NATURAL JOIN Orders o NATURAL JOIN Order_Details c

我想要获得的输出是 | CustFirstname | CustLastName | ORDERNUMBER |订购日期|并按ShipDate | ItemTotal |

更新:如果我用“SELECT”替换“CREATE VIEW ORDERS AS”似乎有效

2 个答案:

答案 0 :(得分:2)

您缺少最重要的语句“SELECT”。

    if($(window).width() > 1280) {
        console.log('desktop');
    }

    else if ($(window).width() < 1280) {
        console.log('tablet');
    }

    else if ($(window).width() < 780) {
        console.log('mobile');
    }

答案 1 :(得分:2)

在您的CREATE VIEW声明中,您遗漏了查询的SELECT

CREATE VIEW ORDERS AS 
    SELECT CustFirstname, CustLastName, o.Ordernumber AS OrderNumber, 
        o. OrderDate AS OrderDate, o.ShipDate AS ShipDate, c.QuotedPrice, 
        c.QuantityOrdered, c.QuotedPrice * c.QuantityOrdered AS ItemTotal 
    FROM Customers NATURAL JOIN Orders o NATURAL JOIN Order_Details c

根据CREATE VIEW的定义,您可以看到select_statement是必需的:

CREATE
    [OR REPLACE]
    [ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}]
    [DEFINER = { user | CURRENT_USER }]
    [SQL SECURITY { DEFINER | INVOKER }]
    VIEW view_name [(column_list)]
    AS select_statement
    [WITH [CASCADED | LOCAL] CHECK OPTION]
  

您可以在official docs上找到有关CREATE VIEW的更多信息。