gpt4 book ai didi

Mysql 使用 max(count/group by) 使用 join

转载 作者:行者123 更新时间:2023-11-29 19:06:35 25 4
gpt4 key购买 nike

我有两个表(titleauthor、authors)作者中有名字,

titleauthor(counts)中所写书籍的内容

我想通过在 titleauthor 中使用 max in counts 来获取authors中的作者姓名。我认为我使用的命令错误。任何人都可以纠正这个吗?

use pubs;

select (a.au_fname," ", a.au_lname) as Author_Name
from authors a
join titleauthor ta
on a.au_id = ta.au_id
where max(count(*)) group by ta.au_id; // or where max(count(*) group by ta.au_id);

最佳答案

如果您只希望单个作者拥有最多的标题,那么您可以尝试以下操作:

SELECT CONCAT(a.au_fname, ' ', a.au_lname) AS Author_Name
FROM authors a
INNER JOIN titleauthor ta
ON a.au_id = ta.au_id
GROUP BY a.au_id
ORDER BY COUNT(*) DESC
LIMIT 1

如果大多数标题的作者之间可能存在平局,那么您可以指定可用于打破平局的第二列。如果您只想举报单个作者,这会很有效。如果您确实想报告所有作者(如果有平局),那么我们可以使用子查询。

关于Mysql 使用 max(count/group by) 使用 join,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43437813/

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