2

我有一个包含列字段的答案表,例如:

questionID,answer,email
row1: questionID = 'q1', answer = 'Male', email = 'fake@fake.com'
row2: questionID = 'q2', answer = 'Human',email = 'fake@fake.com'

我想要一个这样的选择语句:

SELECT email 
FROM answers 
WHERE (questionID='q1' AND answer='Male') 
    AND (questionID='q2' AND answer='Human') 

所以换句话说,我想要所有男性和人类的电子邮件。问题是每个“答案”都是一个新行,所以这个查询不起作用。有没有办法轻松做到这一点?谢谢!

4

1 回答 1

4
SELECT email FROM answers 
WHERE answer='Male' OR answer='Human'
group by email 
having count(distinct answer) = 2
于 2012-10-12T15:02:26.697 回答