gpt4 book ai didi

使用外键关系的 MySQL 查询

转载 作者:行者123 更新时间:2023-11-29 00:31:03 25 4
gpt4 key购买 nike

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

下面是我的两个表:

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

最佳答案

接近这个的东西:

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

基本上,您执行联接以“合并”这两个表,然后按教员对结果进行分组,并计算每个教员的教授数。

关于使用外键关系的 MySQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16502808/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com