MySQL Query使用外键关系

时间:2013-05-11 23:47:55

标签: mysql

我正在学习MySQL,我正在尝试在查询中进行简单的算术运算, 我正在尝试编写一个命令来确定大学每个学院中Instructors的数量 任何人都可以帮助我吗?谢谢!

以下是我的两张表:

    ________________________________________________________
    |    Department       |    Faculty         |  Building  |      
    --------------------------------------------------------        
    |    Humanities       |  Arts and Sciences |  Chardon   |
    |     English         |  Arts and Sciences |  Chardon   |
    |   Mathematics       |  Arts and Sciences |  Monzon    |
    | General Engineering |    Engineering     |  Stefani   |
    |     Agronomy        |    Agriculture     |  Pinero    |

     _________________________________________________________________________
    |  Professor  |      Department        |      Rank           |  Salary    |
    ---------------------------------------------------------------------------
    |  Joe Blow   |         Biology        |     Professor       | $73,500.00 |
    |  Sam Snow   |       Mathematics      |     Instructor      | $45,700.00 |   
    | George Grow | Electrical Engineering | Associate Professor | $69,250.00 |
    | Hiram Lowe  |         English        | Assistant Professor | $63,750.00 |

1 个答案:

答案 0 :(得分:1)

接近这一点:

select department.faculty, count(professor.professor) as instructors from department join professor on department.department = professor.department group by department.faculty

基本上你做一个联合来“合并”这两个表,然后由教师分组结果,并为每个教师计算教授。