mysql错误:Column 'user_id' in group statement is ambiguous

今天使用下午的语句查询时,报上面的错误

select u.user_id userId,u.user_name userName,hh.total_time answerTimes,count(*) answerCount , min(totalScore) minScore,max(totalScore) maxScore,ROUND(AVG(totalScore),2) avgScore from ( 
select homework_id,user_id,batch_id,sum(score) totalScore  from shuoba_result where homework_id=2329 and exampaper_id="582739989410063361" GROUP BY user_id,batch_id ) tt 
join user u on tt.user_id= u.user_id
join (select user_id, ROUND(sum(total_time)/60) total_time from user_answer_time_history where  homework_id=2329 group by user_id ) hh on  u.user_id = hh.user_id 
GROUP BY user_id
order by hh.total_time

原因为group by 的 user_id没有指定是哪个表,只需改为:tt.user_id即可

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页