我想创建一个 View ,其中包含我拥有的 3 个表中的所有记录。但是我收到错误,我不知道如何解决它。
错误是 Customer.customerID 重复。
Create view overview as
Select
customer.customerID,
customer.username,
customer.name,
customer.surname,
customer.city,
customer.street,
customer.zipcode,
customer.birthdate,
customer.`payment method`,
customer.screenname,
order.OrderID,
order.customerID,
order.date,
order.GameID,
games.GameID,
games.game,
games.price,
games.released,
games.genre,
games.grid
FROM customer
INNER JOIN order
ON customer.customerID = order.customerID
INNER JOIN games
ON games.GameID = order.GameID
表格及其行:
订单 订单ID、客户ID、日期、游戏ID
游戏 GameID、游戏、价格、发布、类型、网格
客户 customerID、用户名、姓名、城市、街道、邮政编码、出生日期、付款方式、屏幕名称
请帮忙。
最佳答案
CustomerID
列被选择两次且名称相同,您必须使用别名 AS ...
为其中一个列指定不同的名称,如下所示:
Create view overview as
Select
customer.customerID,
customer.username,
customer.name,
customer.surname,
customer.city,
customer.street,
customer.zipcode,
customer.birthdate,
customer.`payment method`,
customer.screenname,
order.OrderID,
order.customerID AS OrderCustomerId, -- this
order.date,
order.GameID,
games.GameID gamesGameID, -- This too
games.game,
games.price,
games.released,
games.genre,
games.grid
FROM customer
INNER JOIN order
ON customer.customerID = order.customerID
INNER JOIN games ON games.GameID = order.GameID
或者将其从选择中删除,因为它与 Customers.CustomerId
的值相同。
关于mysql - 在 SQL 中创建包含三个表的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27525602/