双重身份问题:

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

相关文章:

  • 2022-02-04
  • 2021-10-22
  • 2021-08-10
  • 2021-10-02
  • 2021-09-09
  • 2021-11-24
  • 2021-12-24
猜你喜欢
  • 2022-12-23
  • 2021-05-15
  • 2021-04-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-20
相关资源
相似解决方案