我有两个表(titleauthor,authors),作者中有名字,
titleauthor(counts) 中书面书籍的内容和内容
我想通过在 titleauthor 中使用 max in counts 来获取作者中的作者姓名。我想我用错了命令.. 任何人都可以纠正这个吗?
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
如果大多数标题的作者之间可能存在平局,那么您可以指定第二列可用于打破平局。如果您只想报告单个作者,这将很有效。如果你真的想报告所有作者,如果有平局,那么我们可以使用子查询。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句