2013-05-11 111 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 

基本上你一個加入到「合併」的兩個表,然後按教師的結果,爲每個教師計數教授。