这里是PHPSQL语法错误。看起来像我错过了什么
$query = sprintf("SELECT SUM(value) AS totalvalue
FROM (
SELECT *
FROM answers
WHERE user_id='%s'
AND test_id ='%s'
ORDER BY answers.id DESC
LIMIT '%s'
)
AS subquery",
$user_id,
mysql_real_escape_string($test_id),
$num_of_q);
这里结合我的SQL代码的错误:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''40') AS subquery' at line 8
有什么问题吗?从限值
只是旁注:因为你只需要'值'列,不要在子查询中使用'select *'。在那里使用'select value',为引擎提供更多优化查询的可能性 – 2012-07-07 08:24:08