gpt4 book ai didi

mysql - SQL连接一些表

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

我有这四个表:

用户(userId,username,password)

书籍(id,title,author,isbn,cost)

Orders(orderID,orderDate,userId)(manyToOne 到 User,oneToMany 到 OrderItem)

OrderItem(id,quantity,totalPrice,Book_id, order_orderID)(manyToOne 到 Order,manyToOne 到 Book)

我要检索 title , cost , author , orderID , Quantity 其中 userID=1

这是我的查询:

SELECT
book.title,
book.cost,
book.author,
orders.orderDate,
orderitem.quantity,
orderitem.totalPrice
FROM book
JOIN orderitem ON book.id = orderitem.id
JOIN orders ON orders.orderID = orderitem.order_orderID WHERE user_id=1;

但是这个查询没有结果!

最佳答案

 SELECT
book.title,
book.cost,
book.author,
orders.orderDate,
orderitem.quantity,
orderitem.totalPrice
FROM book
INNER JOIN orderitem ON book.id = orderitem.Book_id
INNER JOIN orders ON orders.orderID = orderitem.order_orderID
WHERE user_id = 1;

关于mysql - SQL连接一些表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29876383/

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