如何将下面的sql查询转换为yii2代码

时间:2017-01-11 07:29:33

标签: php yii yii2 yii2-advanced-app yii2-basic-app

SELECT student_subjects.student_id,student_subjects.subject_id,student_subjects.amount FROM student_subjects NOT NOT EXISTS(来自payment_history的subject subject_id,其中student_subjects.subject_id = payment_history.subject_id)

1 个答案:

答案 0 :(得分:1)

试试这个

$sql="SELECT student_subjects.student_id,student_subjects.subject_id,student_subjects.amount FROM student_subjects where NOT EXISTS(SELECT subject_id from payment_history where student_subjects.subject_id=payment_history.subject_id)"
Yii::app()->db->createCommand($sql)->queryAll();