【发布时间】:2013-09-04 19:00:29
【问题描述】:
Select "answer"
from 'Details'
where "question" like 'child'
AND "subject" IN (select "subject"
from 'Details'
where "question" like 'child'
AND "answer" = "M" and "test" ="1");
表结构是:
Subject Test Survey Question answer
----------------------------------------------------
rahul 1 one childimmunization Yes
rahul 1 one childgender M
Jyothi 1 one childimmunization No
Jyothi 1 one childgender F
Chikku 1 one childimmunization No
Chikku 1 one childgender M
【问题讨论】:
-
这不会总是导致
answer = M吗? -
不,在“答案”中,我想分别为男性(“M”)和女性(“F”)获得“是”或“否”。但现在我只需要男性,所以在子查询中我将条件设为 answer="M"。
-
您在外部查询中再次选择答案。
-
是的。内部查询和外部查询都在同一个表中,有 2 个不同的行。在内部查询中,我得到主题名称(性别为男性的人名)现在只有选定的人我需要回答(是或否),这是另一行。
-
查询的问题:(1)
question like 'X'与question like 'X%'不一样,完全是question = 'X',(2)您没有在外部查询中声明test=1,因此,当表格中存储多个测试时,您可能会混淆结果。