所以我目前有一个sql语句:
Select room_no, category from help_desk where room_no = '133' OR room_no = '120';
它返回:
我将如何编写一个像这样返回它的sql语句
如何提高这个 mysql 语句的速度?花了 1.10 秒,但想知道是否可以让它更快。
SELECT
res_rooms.room_id AS room,
res_rooms.type AS room_type,
res_rooms.status AS room_status,
IFNULL(utilizations.user_id, - 1) AS user_id,
CONCAT_WS(0, system_users.surname, camps.s_surname) AS surname,
CONCAT_WS(0, system_users.name, camps.s_first) AS name,
IFNULL(utilizations.start_date, NULL) AS start_date,
IFNULL(utilizations.end_date, NULL) AS end_date,
utilizations.keys_issued AS keys_issued,
utilizations.resource_type AS resource_type,
utilizations.staff_id AS staff_id,
CONCAT_WS(0, students.handled_by, camps.handled_by) AS handled_by,
CONCAT_WS(0,
students.date_of_birth,
camps.date_of_birth) AS dob,
CONCAT_WS(0, students.gender, camps.sex) AS gender,
CONCAT_WS(0, students.status, camps.status) AS status,
countries.common_name AS citizenship,
CONCAT_WS(0, students.applying_for, camps.applying) AS applying_for,
IFNULL(fee_schedule.ResiLife_type, 'N/A') AS residence_type,
IFNULL(fee_schedule.Resi_Amount, 'N/A') AS reslife_amount
FROM
res_rooms
LEFT JOIN
utilizations ON utilizations.resource_id = res_rooms.room_id
LEFT JOIN
system_users ON system_users.user_id = utilizations.user_id
LEFT JOIN
camps ON camps.camp_id = utilizations.user_id
LEFT JOIN
students ON students.user_id = utilizations.user_id
LEFT JOIN
countries ON (students.citizenship = countries.code
|| camps.citizenship = countries.code)
LEFT JOIN
fee_schedule ON utilizations.user_id = fee_schedule.Stud_id
WHERE
(students.status = 'B'
OR students.status = 'VC')
AND utilizations.start_date <= CURDATE()
ORDER BY room_id , start_date DESC
使用时Explain
:
查询统计: