Sql 查询 3 个表(计数)
Sql query on 3 tables (count)
我有三个 table:S(员工)、C(客户)、O(运营)。下面是 tables 的截图。
如何打印每个城市的客户数量和居住在那里的员工数量?
因此,table 将有 3 列:City、Count(Clinets)、Count(Stuff)
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
我有三个 table:S(员工)、C(客户)、O(运营)。下面是 tables 的截图。
如何打印每个城市的客户数量和居住在那里的员工数量? 因此,table 将有 3 列:City、Count(Clinets)、Count(Stuff)
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