我知道我必須在這裏失去了一些東西簡單...但我在與編寫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的用戶,但。
我需要能夠添加更多的條件,但我想我可以補充說,如果我至少可以得到這兩個工作。