You should normalize your database tables, as already mentioned by several other people. The result database structure should look like:
BOOK_MASTER
book_master_id book_name
1 Book 1
2 Book 2
3 Book 3
4 Book 4
AUTHOR
author_id author_name
22 Jim
23 Roger
24 Andrew
BOOK_AUTHOR
book_master_id author_id
1 22
1 23
2 23
3 24
4 23
4 24
You should ofcourse set the correct constraints on your database schema, but this will give you an idea.
With this database structure you can use the following query to get the result you want:
SELECT
a.author_name,
COUNT(*) as number_of_books
FROM
author a
JOIN book_author ba ON a.id = ba.author_id
GROUP BY
a.author_name
ORDER BY number_of_books DESC
Writing a script that moves the author_id comma separated lists of you current books table into the new author_book table should be fairly trivial, something in the line of the following would probably work:
<?php
$query = "SELECT book_master_id, author_id FROM books";
$result = mysql_query($query);
while ($row = mysql_fetch_row($result)) {
$values = array();
foreach (explode(',', $row['author_id']) as $authorId) {
$values[] = "(" . $row['book_master_id'] . ", " . $authorId . ")";
}
$query = "INSERT IGNORE INTO book_author (book_master_id, author_id) VALUES ";
$query .= implode(', ', $values);
mysql_query($query);
}
Note that I did not test this code, and you should first try it out on a test database to see if it actually does what it is supposed to do. Furthermore, if you have a lot of data, this script can take some time to execute. And finally, maybe there is an SQL query that can do this, but this was the first solution that came to mind.