SELECT c.class_id,c.class_name,c.capacity,c.start_date,c.end_date
FROM `learningcenter_class` as cLEFT JOIN
( SELECT min(start_time) as min_time, max(end_time) as max_time
FROM learningcenter_sessions
GROUP BY class_id
) s ON s.class_id =c.class_id
WHERE c.start_date between now() and now() + INTERVAL 1 MONTH ORDER BY
created_date ASC
我有2个表1是类,另一个是会话。我想为这门课提供最短时间和最长时间的课程。我使用的是mysql数据库。这是错误的
答案 0 :(得分:0)
您没有在内部SQL中选择class_id
。将此列添加到选择列表
SELECT class_id , min(start_time) as min_time, max(end_time) as max_time
FROM learningcenter_sessions
GROUP BY class_id