create table Employees (id number unique, name text);
create table Services (Sid number unique, Sname text);
create table EmployeesServices (EEid number, ESid number);
insert into Employees values (1, 'bob');
insert into Employees values (2, 'joan');
insert into Employees values (3, 'philippe');
insert into Services values (100, 'fell tree');
insert into Services values (101, 'row boat');
insert into Services values (102, 'read book');
insert into Services values (103, 'sell book');
insert into Services values (104, 'sell ticket');
insert into EmployeesServices values (1, 100);
insert into EmployeesServices values (2, 101);
insert into EmployeesServices values (2, 101);
insert into EmployeesServices values (3, 101);
insert into EmployeesServices values (3, 103);
insert into EmployeesServices values (3, 103);
insert into EmployeesServices values (3, 104);
insert into EmployeesServices values (1, 100);
insert into EmployeesServices values (1, 101);
insert into EmployeesServices values (1, 102);
insert into EmployeesServices values (1, 102);
insert into EmployeesServices values (1, 102);
insert into EmployeesServices values (1, 102);
select count(*) as Number_of_Unique_Services_Available from Services;
select id, name, count(distinct Sid) as Unique_Services_Performed
from Employees, Services, EmployeesServices
where id = EEid and Sid = ESid
group by id
order by Unique_Services_Performed desc, name;
我创建了一些表进行测试。我假设员工可以多次执行相同的服务。第一个 select 语句告诉可用的唯一服务的数量。第二个创建输出,显示每个员工执行的唯一服务的数量。下面的示例输出显示了 5 个独特的服务,并且没有人执行所有这些服务。
Number_of_Unique_Services_Available
-----------------------------------
5
id name Unique_Services_Performed
---------- ---------- -------------------------
1 bob 3
3 philippe 3
2 joan 1