我有这样的数据:
ID Book Author
1 Book A Andy, Brian
2 Book B Andy, Charlie
3 Book C Brian
如何按数据分组,以便我可以这样:
Author Count
Andy 2
Brian 2
Charlie 1
答案 0 :(得分:0)
如果我们假设您有一个标准化结构,您只需要:
SELECT a.author, count(*)
FROM books b
INNER JOIN author a ON a.author_id=b.author_id
GROUP BY a.author