sql

mysql錯誤:Column ‘user_id’ in group statement is ambiguous

今天使用下午的語句查詢時,報上面的錯誤

  1. 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 (
  2. 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
  3. join user u on tt.user_id= u.user_id
  4. 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
  5. GROUP BY user_id
  6. order by hh.total_time

原因為group by 的 user_id沒有指定是哪個表,只需改為:tt.user_id即可

本文章已修改原文用詞符合繁體字使用者習慣使其容易閱讀

版權宣告:此處為CSDN博主「尋夢太極」的原創文章,依據CC 4.0 BY-SA版權協議,轉載請附上原文出處連結及本宣告。

原文連結:https://blog.csdn.net/xzj80927/article/details/101281836