gpt4 book ai didi

mysql - 在sql中使用内连接创建表

转载 作者:行者123 更新时间:2023-11-30 22:54:57 25 4
gpt4 key购买 nike

我应该使用内连接和另一个表在 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));

最佳答案

去掉外面的括号。应该是:

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;

你也有不匹配的括号,因为你在末尾有两个 )) 匹配开头的 (,和一个额外的 ,传真

这些将修复语法错误。但看起来您也有逻辑错误,因为您的大多数 INNER JOIN 子句都缺少与表相关的 ON 条件。而且您选择了许多从未使用过的列。

关于mysql - 在sql中使用内连接创建表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26819426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com