我有一个包含列字段的答案表,如:
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')
换句话说,我想要所有男性和人类的电子邮件。问题是每个'答案'都是一个新行,所以这个查询不起作用。有没有办法轻松做到这一点?谢谢!
答案 0 :(得分:4)
SELECT email FROM answers
WHERE answer='Male' OR answer='Human'
group by email
having count(distinct answer) = 2