双重身份问题:
create table role_tab (
person char(5) not null,
role char(1) not null
)
insert into role_tab values('smith','O'),('smith','D'),('niu','O'),('jia','O'),('yong','O'),('yong','D')
O代表高级职员,D代表主管,
问题:现查询职员,如果是双重身份的则显示B,
此题一看到就想到用union,和count(*)做。除了union外呢
解惑1:
select r.person,case when count(r.rol)=1 then max(r.rol) else 'B' end from role_tab r group by r.person
解惑2:
select person,substring('DOB' from sum(position(rol in 'DO')) for 1) from role_tab where role_tab where rol in ('O','D') group by person