gpt4 book ai didi

MySQL 数据库中的表连接?

转载 作者:行者123 更新时间:2023-11-29 23:02:26 26 4
gpt4 key购买 nike

我想知道mysql如何形成一个新表来显示我想要的数据?

Current having Purchase table and Product table

我的产品表:

=====Product=====
field productID
field category
field brand
field name
field createtime

我的购买表:

=====Purchase=====
field UID
field productID
field username
field email
field purchaseDate

我希望得到的结果表:

=====OrderList=====
field UID
field productID
field category
field brand
field name
field username
field email
field purchaseDate

我的疑问,一旦在Purchase表中插入新记录,mysql OrderList表会在数据库中自动更新吗?

below is the example method do this solve my problem?

SELECT Purchase.UID, Purchase.productID, Product.category, Product.brand,
Product.name, Purchase.username, Purchase.email, Purchase.purchaseDate
FROM Product
LEFT JOIN Purchase
ON Product.productID=Purchase.productID

最佳答案

使用“VIEW”,例如:

CREATE VIEW OrderListAS     SELECT Purchase.UID,            Purchase.productID,            Product.category,            Product.brand,            Product.name,            Purchase.username,            Purchase.email,            Purchase.purchaseDate       FROM   Product, Purchase       WHERE  Product.productID = Purchase.productID   ORDER BY Customers.CustomerName

关于MySQL 数据库中的表连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28426748/

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