0

The output is not matching the code.

You are working on the library database, which contains the Books and Authors tables. Columns of the Books table: id, name, year, author_id. Columns of the Authors table: id, name. Write a query to get the author names and the number of books they have in the Books table. Note that some authors do not have any books associated with them. In this case, the result needs to include their names and have 0 as the count. The count column should be called books in the result. SELECT Authors.name AS author_name, COALESCE(COUNT(Books.id), 0) AS books FROM Authors LEFT JOIN Books ON Authors.id = Books.author_id GROUP BY Authors.id, Authors.name;

6th May 2024, 3:27 AM
Div Anand
Div Anand - avatar
4 Respuestas
+ 4
Div Anand , it helps a lot if your post / question has some more information which tutorial / lesson / exercise you are talking about (if it is a sololearn exercise). [edited]: sql intermediate - working with data - joins - lesson takeaways code coach: number of books
6th May 2024, 9:14 AM
Lothar
Lothar - avatar
+ 4
Div Anand , i found these issues: > autors name col. should not be renamed > grouping should be only by autors name > missing order statement according description
6th May 2024, 9:41 AM
Lothar
Lothar - avatar
+ 3
Does the task ask you to rename the column? What about the sorting order?
6th May 2024, 5:11 AM
Wong Hei Ming
Wong Hei Ming - avatar
0
What is the answer of this question?
10th May 2024, 5:01 PM
Div Anand
Div Anand - avatar