gpt4 book ai didi

MySQL:如何计算对表引用的引用?

转载 作者:太空宇宙 更新时间:2023-11-03 10:40:32 25 4
gpt4 key购买 nike

假设我有一个出版商的数据库,他们雇用作者,他们写

或者换句话说,每本都是由作者撰写的,他为出版商工作。

publishers: id
authors: id, publisher_id
books: id, author_id

我知道如何从 this question 中获取一份出版商列表以及每个出版商雇佣了多少作者.

我如何获得一份出版商列表以及每家出版商出版了多少本书

我怎样才能同时获得两者 - 出版商,每个出版商都有作者数量图书数量

最佳答案

试试这个

SELECT COUNT(DISTINCT b.`id`) noofbooks,COUNT(DISTINCT au.id) noofauthers,pub.id publisher FROM publisher pub
INNER JOIN auther au ON au.`pub_id`= pub.`id`
INNER JOIN books b ON b.`aut_id` = au.`id` GROUP BY pub.id

关于MySQL:如何计算对表引用的引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39422796/

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