我是mysql的初学者 任何人都可以帮我解决第5行的错误:
[5, 'number', 'wumbly']
答案 0 :(得分:4)
您的ORDER BY应该在GROUP BY之后。
答案 1 :(得分:2)
在Group By
条款之前使用Order by
子句。
如下:
select a.*, count(b.user_id) as attempts from survey a
left join survey_attempt b on a.survey_id = b.attempt_surveyid
where a.survey_status != 0
GROUP by a.survey_id
order by survey_order asc
答案 2 :(得分:1)
您ORDER
之前不允许GROUP
,因此您的查询应如下所示:
select a.*, count(b.user_id) as attempts
from survey a
left join survey_attempt b on a.survey_id = b.attempt_surveyid
where a.survey_status != 0
group by a.survey_id
order by survey_order asc
可以找到更多详细信息here,其中提出了类似的问题,并收到了更详细的答案。
作为旁注,请尝试避免使用*
并添加必填列。