I am trying to run the following query but run this through Yii’s own CDbCriteria so it can work alongside some other queries that are using the Yii CDbCriteria functionality.
I’m not sure how i’d do the following SQL query using the CDbCriteria can anyone assist? The actual section with the CDbCriteria is massive so i’d probably make it more confusing post it here but can if that is preferred.
The idea is to basically select the student that has collected the 1000th point for that particular school and LIMIT by one so we only get a single student in the result.
SELECT
*
FROM
students t1
WHERE
school_id = 1
AND
(
SELECT
sum(points)
FROM
students t2
WHERE
t2.id <= t1.id
) >= 1000
ORDER BY
id
LIMIT 1