我正在使用 mysql 5.1。
这是我的数据库架构
office
+--------------+----------------+
| office_id | office_name |
+--------------+----------------+
employee
+--------------+-----------------------+------------+
| employee_id | employee_hierarchy_id | office_id |
+--------------+-----------------------+------------+
employee_hierarchy
+-----------------------+-------------------------------+
| employee_hierarchy_id | employee_hierarchy_description|
+-----------------------+-------------------------------+
我想计算number of employees
group by employee_hierarchy_id
每个office_id
这是我列出 factory_id 和 employee_hierarchy_id 的请求:
SELECT office_id, employee_hierarchy_id
FROM office, employee_hierarchy
ORDER BY office_id ASC
如果我尝试添加计数,它只显示一行:
SELECT office_id, employee_hierarchy_id, COUNT(*)
FROM office, employee_hierarchy
ORDER BY office_id ASC