开发者

How to Group By This Comma-Delimited Data

开发者 https://www.devze.com 2023-03-29 23:50 出处:网络
I have data like this : IDBookAuthor 1Book AAndy, Brian 2Book BAndy, Charlie 3Book CBrian How to group by the data so i can get like this:

I have data like this :

ID  Book    Author
1   Book A  Andy, Brian
2   Book B  Andy, Charlie
3   Book C  Brian

How to group by the data so i can get like this:

Author  Count
开发者_StackOverflow中文版Andy    2
Brian   2
Charlie 1


If we assume you have a normalized structure, you simply need to :

SELECT a.author, count(*) 
FROM books b
INNER JOIN author a ON a.author_id=b.author_id
GROUP BY a.author
0

精彩评论

暂无评论...
验证码 换一张
取 消