需要从 sql 中的相同字段中查找数据

need to find data from same field in sql

对于 table 具有以下数据,

name      cerification   status
Anuradha       STA  Enrolled
Anuradha       TA   certified
Ravi           TA   certified
Ravi           STA  Enrolled
mandar         TA   certified
sakshi         TA   certified
tushar         TA   certified

我需要找到没有。已注册 "STA" 且 "TA" 身份必须获得认证的人的比例

希望这是您的要求:

SELECT count(DISTINCT name)
FROM TABLE
WHERE cerification='TA'
  AND status='certified'
  AND name IN
    (SELECT DISTINCT name
     FROM TABLE
     WHERE cerification='STA'
       AND status='Enrolled');

祝你好运....谁曾否决过它,这只是一个初步的答案,以便更好地理解它。不要太快判断。

你可以使用子查询

select t1.* from

(
select * from tbale_name where certification='STA'
) t1
  join 
(
select * from tbale_name where certification='TA'
) t2 on t1.name=t2.name

您可以尝试使用 "FILTER" 关键字...

select count(name) filter (where cerification='TA' and status='certified'
       and name in (select name from table where cerification='STA' and  status='Enrolled')
from table;

由于文件在将数据加载到 Qlikview 后被标记为 "qlikview",您可以为此使用集合分析:

Count(DISTINCT {
           < cerification={'STA'}, status={'Enrolled'} > *
           < cerification={'TA'}, status={'Enrolled'} >
} Anuradha)