# 列子查询 Joe 打算写一个查询,根据员工表 ```mysql create table employee ( id int primary key auto_increment, dept varchar(256), name varchar(256), post varchar(16) ) ``` 统计每个部门的人数,但是他不打算用 group by。那么还可以怎做? ## 答案 ```mysql select distinct(dept) as dept, (select count(*) from employee as i where i.dept = o.dept) as emp from employee as o; ``` ## 选项 ### A ```mysql select distinct(dept) as dept, (select count(*) from employee as i) as emp from employee as o; ``` ### B ```mysql select distinct(dept) as dept, (select count(*) from employee where dept = dept) as emp from employee ``` ### C ```mysql select dept as dept, (select count(*) from employee as i where i.dept = o.dept) as emp from employee as o ```