0
我怎麼能尋找這樣的SQL如何使用Yii ActiveRecord關係?
select user.user_id,count(distinct user.user_id,user_lesson_read.lesson_id) as counter
FROM
user
inner join
user_lesson_read
ON (user.user_id =user_lesson_read.user_id)
GROUP BY user_lesson_read.user_id
having counter >=3
在人工魚礁? 這是數據庫結構:
User
--------------------
user_id |
1 |
--------------------
LessonRead
-------------------------------------
user_id | lesson_id | section_id
-------------------------------------
1 | 2 | A
-------------------------------------
1 | 2 | B
-------------------------------------
1 | 3 | A
-------------------------------------
1 | 4 | A
-------------------------------------
用戶1有3條教訓記錄(教訓2,3,4)
我試着像
'userLessonRead'=>array(
'select'=>'count(distinct t.user_id,t.lesson_id) as b',
//'condition'=>'',
),
一些事情,我會得到一個CDbException,和SQL是不正確的:
t.lesson_id) as b, // one parenthesis here
任何人都可以幫助嗎?謝謝!
謝謝!好像我誤解了with()函數。 – yanis