我应该使用内部连接和另一个表在sql中创建一个表。我带来了这样的解决方案,但MySQL Workbench一直告诉我SQL语法中存在错误。我没有任何想法。如果有人能帮助我,我将不胜感激。
CREATE TABLE BigTable AS(
SELECT
ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued
FROM `northwind`.`products`
INNER JOIN(
SELECT
CustomerID, EmployeeID, OrderDate, RequiredDate, ShipVia, Freight, ShipName, ShipAddress, ShipCity, ShipRegion, ShipPostalCode, ShipCountry, ProductID, UnitPrice, Quantity, Discount
FROM `northwind`.`orders`
INNER JOIN `northwind`.`order_details`
ON orders.OrderID=order_details.OrderID) AS products
INNER JOIN(
SELECT
LastName, FirstName ,Title ,TitleOfCourtesy ,BirthDate ,HireDate ,Address ,City , Region, PostalCode, Country, HomePhone, Extension, Photo, Notes, ReportsTo, CompanyName,ContactName,ContactTitle,Address,City,Region,PostalCode,Country,Phone,Fax,
FROM `northwind`.`employees`
INNER JOIN `northwind`.`customers`) AS People));
答案 0 :(得分:0)
摆脱外围的括号。它应该是:
CREATE TABLE BigTable AS
SELECT
ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued
FROM `northwind`.`products`
INNER JOIN(
SELECT
CustomerID, EmployeeID, OrderDate, RequiredDate, ShipVia, Freight, ShipName, ShipAddress, ShipCity, ShipRegion, ShipPostalCode, ShipCountry, ProductID, UnitPrice, Quantity, Discount
FROM `northwind`.`orders`
INNER JOIN `northwind`.`order_details`
ON orders.OrderID=order_details.OrderID) AS products
INNER JOIN(
SELECT
LastName, FirstName ,Title ,TitleOfCourtesy ,BirthDate ,HireDate ,Address ,City , Region, PostalCode, Country, HomePhone, Extension, Photo, Notes, ReportsTo, CompanyName,ContactName,ContactTitle,Address,City,Region,PostalCode,Country,Phone,Fax
FROM `northwind`.`employees`
INNER JOIN `northwind`.`customers`) AS People;
您的括号也不匹配,因为最后两个))
与开头(
匹配,,
之后额外Fax
。
这些将修复语法错误。但是看起来您也有逻辑错误,因为大多数INNER JOIN
子句都缺少ON
条件来关联表。而且您正在选择许多您从未使用的列。