SELECT t1.id,t1.sort_code,t2.name AS bulid_name,t1.floor_number,t1.room_name,t3.name AS check_in_status_cn,t4.name AS gender_cn,t1.bed_count,
(SELECT GROUP_CONCAT(c2.name) FROM room_student_appoint c1
LEFT JOIN xjr_user c2 ON c1.student_user_id = c2.id
WHERE c1.delete_mark = 0 AND c1.room_id = t1.id) AS student_appoint_names,
(SELECT GROUP_CONCAT(c2.name) FROM room_teacher_appoint c1
LEFT JOIN xjr_user c2 ON c1.user_id = c2.id
WHERE c1.delete_mark = 0 AND c1.room_id = t1.id) AS teacher_appoint_names,t1.is_max,t1.remark,
ifnull((
SELECT COUNT(*) FROM room_bed a1
INNER JOIN xjr_user a2 ON a1.student_user_id = a2.id
WHERE a1.delete_mark = 0 AND a2.delete_mark = 0 AND a1.room_id = t1.id
AND a1.student_user_id IS NOT NULL
), 0) AS student_count,
ifnull((
SELECT COUNT(*) FROM room_bed
WHERE delete_mark = 0 AND room_id = t1.id
AND student_user_id IS NULL
), 0) AS empty_count FROM room t1
LEFT JOIN base_office_build t2 ON t1.office_build_id = t2.id
LEFT JOIN xjr_dictionary_detail t3 ON t1.check_in_status = t3.code AND t3.item_id = 1739843696019435521
LEFT JOIN xjr_dictionary_detail t4 ON t1.gender = t4.code AND t4.item_id = 2023000000000000004
WHERE t1.delete_mark = 0
and t1.office_build_id = #{dto.officeBuildId}
and t1.floor_number = #{dto.floorNumber}
and t1.check_in_status = #{dto.checkInStatus}
and t1.gender = #{dto.gender}
ORDER BY t1.sort_code
SELECT t1.id,t1.sort_code,t2.name AS bulid_name,t1.floor_number,t1.room_name,t3.name AS check_in_status_cn,t4.name AS gender_cn,t1.bed_count,
(SELECT GROUP_CONCAT(c2.name) FROM room_student_appoint c1
LEFT JOIN xjr_user c2 ON c1.student_user_id = c2.id
WHERE c1.delete_mark = 0 AND c1.room_id = t1.id) AS student_appoint_names,
(SELECT GROUP_CONCAT(c2.name) FROM room_teacher_appoint c1
LEFT JOIN xjr_user c2 ON c1.user_id = c2.id
WHERE c1.delete_mark = 0 AND c1.room_id = t1.id) AS teacher_appoint_names,t1.is_max,t1.remark FROM room t1
LEFT JOIN base_office_build t2 ON t1.office_build_id = t2.id
LEFT JOIN xjr_dictionary_detail t3 ON t1.check_in_status = t3.code AND t3.item_id = 1739843696019435521
LEFT JOIN xjr_dictionary_detail t4 ON t1.gender = t4.code AND t4.item_id = 2023000000000000004
WHERE t1.delete_mark = 0
and t1.office_build_id = #{dto.officeBuildId}
and t1.floor_number = #{dto.floorNumber}
and t1.check_in_status = #{dto.checkInStatus}
and t1.gender = #{dto.gender}
ORDER BY t1.sort_code
SELECT IFNULL(MAX(sort_code),1) FROM room WHERE delete_mark = 0
SELECT id,(
SELECT COUNT(*) FROM (
SELECT COUNT(*) FROM base_class t1
LEFT JOIN base_student_school_roll t2 ON t2.class_id = t1.id
LEFT JOIN room_bed t3 ON t2.user_id = t3.student_user_id
WHERE t3.room_id = room.id GROUP BY t1.id
) class_data
) AS class_count FROM room
where delete_mark = 0
and id in
#{roomId}
SELECT id,(
SELECT GROUP_CONCAT(DISTINCT t1.class_id) FROM base_student_school_roll t1
LEFT JOIN room_bed t3 ON t1.user_id = t3.student_user_id
WHERE t3.room_id = room.id AND t3.delete_mark = 0
) AS class_count FROM room
where delete_mark = 0
and id in
#{roomId}
UPDATE room SET is_max = 1 WHERE delete_mark = 0
AND (
SELECT COUNT(*) FROM (
SELECT COUNT(*) FROM base_student_school_roll t1
LEFT JOIN room_bed t3 ON t1.user_id = t3.student_user_id
WHERE t3.room_id = room.id AND t3.delete_mark = 0 GROUP BY t1.class_id
) class_data
) > 1
UPDATE room SET is_max = 0 WHERE delete_mark = 0
AND 1 >(
SELECT COUNT(*) FROM (
SELECT COUNT(*) FROM base_student_school_roll t1
LEFT JOIN room_bed t3 ON t1.user_id = t3.student_user_id
WHERE t3.room_id = room.id AND t3.delete_mark = 0 GROUP BY t1.class_id
) class_data
)