How to count rows in one table based on another table in mysql

后端 未结 4 1205
慢半拍i
慢半拍i 2021-01-19 18:17

I have two tables in a MySQL database. The first one has a list of department names.

departments
    abbreviation | name
    -------------|-------------
             


        
4条回答
  •  盖世英雄少女心
    2021-01-19 18:27

    SELECT d.abbreviation, COUNT(*) num
    FROM departments d
    INNER JOIN courses c ON c.section LIKE CONCAT(d.abbreviation, "%")
    GROUP BY d.abbreviation
    

    Sql Fiddle

提交回复
热议问题