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

后端 未结 4 1260
慢半拍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:25

    Try this

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

提交回复
热议问题