这个网站有助于复习sql知识,网址:http://xuesql.cn/lesson/select_queries_with_aggregates_pt_2
重点解决最后两道题
1.1 角色分组算出每个角色按有办公室和没办公室的统计人数(列出角色,数量,有无办公室,注意一个角色如果部分有办公室,部分没有需分开统计)
- 考虑用联合查询解决,分别查询有无办公室人数再联合
SELECT role,count(building),"yes" FROM employees a group by role
union
select role,count(name),"no" from employees b where building is null group by role
<