需要从SQL中的同一字段中查找数据

时间:2019-01-28 06:52:18

标签: sql qlikview

对于具有以下数据的表,

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”身份的人必须得到认证

4 个答案:

答案 0 :(得分:0)

我希望这是您的要求:

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');

祝你好运....如此投票的人,这只是一个初步的答案,可以使人们更好地理解它。不要太快判断。

答案 1 :(得分:0)

您可以使用子查询

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

答案 2 :(得分:0)

您可以尝试使用“ 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;

答案 3 :(得分:0)

将文件加载到Qlikview后,文件被标记为“ qlikview”,因此您可以使用集合分析:

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