我知道我必须在这里失去了一些东西简单...但我在与编写SQL查询的子问题。鉴于以下数据问题与编写SQL查询子
user_id question_id answer_text
89 1 value1
89 2 value2
80 2 value2
99 2 value2
96 1 value1
96 2 value2
111 1 value1
111 2 value2
我需要得到USER_ID的同时具有question_id 1 =“值1”,并有question_id 2 =“值”
上述结果与使用该查询生成:
SELECT `User_answer`.`user_id`, `User_answer`.`question_id`, `User_answer`.`answer_text` FROM `user_answers` AS `User_answer` WHERE `User_answer`.`question_id` IN (1, 2) AND `User_answer`.`answer_text` IN ('value1', 'value2')
当然它返回有一个完全不同的答案不是“值2”(反之亦然)回答问题1“值1”,但问题2的用户,但。
我需要能够添加更多的条件,但我想我可以补充说,如果我至少可以得到这两个工作。