这不断出现错误,我无法弄清楚为什么......
SELECT
i.user_id
FROM (SELECT
SUM(us.score) AS score_sum,
us.user_id
FROM user_scores us
WHERE us.created >= DATE(DATE_SUB(NOW(),INTERVAL 7 DAY))
GROUP BY us.user_id) AS i
ORDER BY i.score_sum
LIMIT 1
带有消息的异常“CDbException”
CDbCommand 未能执行 SQL 语句:CDbCommand 未能准备 SQL 语句:SQLSTATE[HY000]:一般错误:1 接近“7”:语法错误。
执行的 SQL 语句是:
SELECT
i.user_id
FROM (SELECT
SUM(us.score) AS score_sum,
us.user_id
FROM user_scores us
WHERE us.created >= DATE(DATE_SUB(NOW(),INTERVAL 7 DAY))
GROUP BY us.user_id) AS i
ORDER BY i.score_sum
LIMIT 1
<?php
class WinnerCommand extends CConsoleCommand
{
public function actionSelect()
{
$sql = "SELECT i.user_id FROM
(SELECT SUM(us.score) AS score_sum, us.user_id FROM user_scores us
WHERE us.created >= DATE(DATE_SUB(NOW(),INTERVAL 7 DAY))
GROUP BY us.user_id) AS i
ORDER BY i.score_sum
LIMIT 1";
$user_id = Yii::app()->db->createCommand($sql)->queryScalar();
echo $user_id;
return $user_id;
}
}
?>