0
Вот сценарий, я пытаюсь использоватьКак сравнить значения столбцов из двух таблиц, где положение
game_studentanswer
--> studentanswerid (primary)
--> questionid
--> answerid (this is the answer selected by user)
game_question
--> questionid
game_officialanswer
--> officalanswerid (primary)
--> questionid
--> answerid (this is the answerid for correct answer)
я пытаюсь создать этот запрос в Yii2:
SELECT COUNT(*) FROM `game_studentanswer` LEFT JOIN `game_question` ON `game_studentanswer`.`questionid` = `game_question`.`questionid` LEFT JOIN `game_officialanswer` ON `game_question`.`questionid` = `game_officialanswer`.`questionid` WHERE (`userid`='1') AND (`game_studentanswer`.`answerid` <> `game_officialanswer`.`answerid`)
Вот является код
$query = MyGameStudentanswer::find()->joinWith('question.gameOfficialanswers')
->where(['userid'=>$userid])->andWhere(['answerid' => 'question.gameOfficialanswers.answerid']);
Моя проблема заключается в «AndWhere()» часть кода - вместо сравнения двух столбцов - это предполагает «вопрос. gameOfficialanswers.answerid»как значение строки в результате запроса, который выполняет Yii2 это
SELECT COUNT(*) FROM `game_studentanswer` LEFT JOIN `game_question` ON `game_studentanswer`.`questionid` = `game_question`.`questionid` LEFT JOIN `game_officialanswer` ON `game_question`.`questionid` = `game_officialanswer`.`questionid` WHERE (`userid`='1') AND (`game_studentanswer`.`answerid` = 'game_officialanswer.answerid')
Любая помощь будет оценена
Я рад, что вы смогли решить это, прежде чем я проверил! :) –