我想拉只有在下面的查詢maxscore =分數的測驗,請告訴我什麼是錯誤的語法?mysql查詢語法錯誤
$database->setQuery('SELECT distinct qui.title AS name,' .
' (SELECT GROUP_CONCAT(profiles.title)
FROM #__jquarks_users_profiles AS users_profiles
LEFT JOIN #__jquarks_profiles AS profiles ON users_profiles.profile_id = profiles.id
WHERE users_profiles.user_id = sessionWho.user_id) AS profile, ' .
' (SELECT sum(score)
FROM #__jquarks_quizzes_answersessions
WHERE quizsession_id = quizSession.id
AND status <> -1) AS score,' .
' (SELECT count(distinct(question_id))
FROM #__jquarks_quizzes_answersessions
WHERE quizsession_id = quizSession.id) AS maxScore,' .
' (SELECT count(id)
FROM #__jquarks_quizzes_answersessions
WHERE status=-1
AND quizsession_id = quizSession.id) AS evaluate,' .
' quizSession.finished_on,sessionWho.email' .
' FROM #__jquarks_quizsession AS quizSession' .
' LEFT JOIN #__jquarks_users_quizzes AS users_quizzes ON users_quizzes.id = quizSession.affected_id' .
' LEFT JOIN #__jquarks_quizzes AS qui ON users_quizzes.quiz_id = qui.id' .
' LEFT JOIN #__jquarks_quizzes_answersessions AS quizSessAns ON quizSessAns.quizsession_id = quizSession.id' .
' LEFT JOIN #__jquarks_sessionwho AS sessionWho ON sessionWho.session_id = quizSession.id' .
' LEFT JOIN #__jquarks_users_profiles AS users_profiles ON users_profiles.user_id = sessionWho.user_id' .
' LEFT JOIN #__jquarks_profiles AS profiles ON profiles.id = users_profiles.profile_id '.
' WHERE sessionWho.user_id =' .$id AND score = maxScore) ;
所以有語法問題,不是一個SQL查詢本身? – sll
拼寫語法。 – GolezTrol
你可以直接去phpmyadmin並逐個檢查子查詢嗎? – WooDzu