subject table, which can be understood as a classification table. The
course and source_book tables are associated with subjectnow use the subject table as the main table to query how many courses and books are under this category.
- query statement 1: query the number of courses under each category
SELECT
`subject`.sid,
COUNT( book.id ) AS book_count
FROM
`subject`
LEFT JOIN `book` ON `subject`.`sid` = `book`.`sid`
GROUP BY
`subject`.`sid`
< table >
< thead > < tr >
< th > sid < / th >
< th > book_count < / th >
< / tr > < / thead >
< tbody >
< tr >
< td > s@_5a61cb6e8d76c11548vIrM < / td >
< td > 4 < / td >
< / tr >
< tr >
< td > s@_5a65bd36d97902207DvomQ < / td >
< td > 0 < / td >
< / tr >
< tr >
< td > s@_5a65bd36dc7ec2207LdZAM < / td >
< td > 0 < / td >
< / tr >
< tr >
< td > s@_5a65bd36deea72207Flx2K < / td >
< td > 0 < / td >
< / tr >
< tr >
< td > s@_5a65bd36e3cae22075HcSq < / td >
< td > 2 < / td >
< / tr >
< tr >
< td > s@_5a65bd36f26dc2207Y9s5m < / td >
< td > 1176 < / td >
< / tr >
< / tbody >
< / table >
< hr >
< table > < thead > < tr > < th > sid < / th > < th > course_count < / th > < th > book_count < / th > < / tr > < / thead > < tbody > < tr > < td > s@_5a61cb6e8d76c11548vIrM < / td > < td > 5 < / td > < td > 4 < / td > < / tr > < tr > < td > s@_5a65bd36d97902207DvomQ < / td > < td > 10 < / td > < td > 0 < / td > < / tr > < tr > < td > s@_5a65bd36dc7ec2207LdZAM < / td > < td > 52 < / td > < td > 0 < / td > < / tr > < tr > < td > s@_5a65bd36deea72207Flx2K < / td > < td > 34 < / td > < td > 0 < / td > < / tr > < tr > < td > s@_5a65bd36e3cae22075HcSq < / td > < td > 143 < / td > < td > 2 < / td > < / tr > < tr > < td > s@_5a65bd36f26dc2207Y9s5m < / td > < td > 1200 < / td > < td > 1176 < / td > < / tr > < / tbody > < / table >so how do you combine these two sql statements to get such a result?