2013-05-11 116 views
1

我正在学习MySQL,我试图在查询中做简单的算术, 我想写一个命令来确定Instructors在大学里每个学院的编号 任何人都可以帮助我在这?谢谢!下面使用外键关系的MySQL查询

这里是我的两个表:

________________________________________________________ 
    | 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

一些接近这一点:

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

基本上你一个加入到“合并”的两个表,然后按教师的结果,为每个教师计数教授。