在两个表格question
中answer
,我需要转储特定用户的所有未回答的问题。在SQL中
select * from question where question.user_id = user_id
and (select count(*) from answer where answer.question_id = question.id) = 0
但是如何将这个命令转换为activequery?
Question::find()->where(['user_id' => user_id]) ....
一个活动查询,用于查找没有答案的给定用户的每个问题。
Question::find()->leftJoin('answer', 'answer.question_id=question.id')
->where(['question.user_id' => $user_id])
->andWhere(['answer.id' => null)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句