我有一个名为AES的表,其中包含以下值:
Select visitid_fk from AEs Where AE != 'Headache'
我想选择从未头疼的访问ID。我写在下面的查询:
1
4
4
7
它正在回归:
{{1}}
访问者1曾经头痛过一次。请注意,visitid 1有两个条目。
非常感谢您的帮助。
答案 0 :(得分:2)
一种方法是使用带有派生表的左连接:
{{1}}
答案 1 :(得分:1)
select Visitid_fk
from
yourtable t1
where not exists(
select 1 from yourtable t2 where t1.Visitid_fk=t2.Visitid_fk
and t1.AE='headache')
答案 2 :(得分:1)
我会使用GROUP BY
和HAVING
:
select visitid_fk
from aes
group by visitid_fk
having sum(case when ae = 'Headache' then 1 else 0 end) = 0;
having
子句计算头痛的次数。 = 0
指定没有。
或者,您可以使用not exists
(或类似的东西)。我建议使用visitors
表(或任何外键要点):
select v.*
from visitors v
where not exists (select 1
from aes
where aes.visitorid_fk = v.visitorid and
aes.ae = 'Headache'
);
答案 3 :(得分:0)
您只需使用:
export JAVA_HOME=/home/kishore/BigData/jdk
export PATH=$PATH:$JAVA_HOME/bin
export HADOOP_CLASSPATH=${JAVA_HOME}/lib/tools.jar
或强>
Select visitid_fk from AEs,Yourtable Where (Youtable.visitid_fk = AE.visitid_fk) AND (AE <> 'Headache')
转发所有Select visitid_fk from AEs,Yourtable Where (Youtable.visitid_fk = AE.visitid_fk) AND (AE Not Like 'Headache')
s visitid ID
&lt;&gt; “头痛”。