Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
173 views
in Technique[技术] by (71.8m points)

sql - Mysql Error: Invalid use of group function

What should I use in the outer GROUP BY, or what is the error?

Without using MIN() in both outer and inner queries, it's working fine.

SELECT DISTINCT (C.id) AS `course_id`, C.name, C.type, C.description, C.image, C.extra,
    C.first_flow_question_id, C.menu_flow_question_id, C.last_question_id, C.lang_id, C.author_id,
    C.organization_id, C.country_id, C.created_at, C.updated_at, C.deleted_at, M.id AS `message_id`,
    MIN(M.date_created) AS `first_message`, MAX(M.date_created) AS `last_message`
FROM `user` U, `course` C, `user_course_group` UCG, `message` M
WHERE U.id = 244
AND U.id = UCG.user_id
AND M.course_id = C.id
AND C.id = UCG.course_id
AND C.deleted_at IS NULL
AND C.last_question_id IS NOT NULL
AND UCG.last_question_id IS NOT NULL
AND UCG.last_question_id = C.last_question_id
AND (M.course_id, MIN(M.date_created), MAX(M.date_created)) IN 
(
    SELECT C.id, MIN(M.date_created), MAX(M.date_created)
    FROM message M, course C
    WHERE (M.`from_user_id`= 244 OR M.`to_user_id`= 244)
    AND M.course_id = C.id
    GROUP BY C.id
)
GROUP BY C.id;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...