我有三个表:S(员工),C(客户),O(操作)。以下是表格的屏幕截图。
如何为每个城市打印客户数量和居住在那里的员工人数? 因此,该表将有3列:City,Count(Clinets),Count(Stuff)
答案 0 :(得分:2)
select city, sum(clients) as clients, sum(staff) as staff
from
(
select city, count() as clients, null as staff from clients group by city
union all
select city, null, count() from staff group by city
) tmp
group by city