gpt4 book ai didi

mysql - 用于查找每本书至少有 2 份副本的分支的分配 SQL

转载 作者:行者123 更新时间:2023-11-29 14:51:27 25 4
gpt4 key购买 nike

   Q. List the branch id and name of all branches that have atleast 2 copies of every  
book.

表格:

    BOOK (Book_ISBN [pk], Title, Publisher_Name [fk])
BOOK_COPIES (Book_ISBN [pk,fk], Branch_ID [pk,fk], Num_Copies)
LIBRARY_BANCH (Branch_ID [pk], Branch_Name, Address)

但是,我尝试做这个问题,但问题是检查 2 个副本。

最佳答案

您可能会在 relational division 上找到这篇文章有用。

SELECT L.Branch_ID,
L.Branch_Name
FROM LIBRARY_BRANCH L
WHERE NOT EXISTS (SELECT *
FROM BOOK B
WHERE NOT EXISTS(SELECT *
FROM BOOK_COPIES BC
WHERE BC.Book_ISBN = B.Book_ISBN
AND Num_Copies >= 2
AND L.Branch_ID = BC.Branch_ID))

关于mysql - 用于查找每本书至少有 2 份副本的分支的分配 SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5651446/

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