我有以下查詢,我正在使用這兩個運算符來獲取具有特定數字之間的年齡的記錄,但查詢花了很多時間來顯示結果,其鴨舌超過5分鐘仍運行查詢花費很長時間執行
SELECT
*,
(SELECT COUNT(*)
FROM users
WHERE
1=1 OR
LOWER(age) BETWEEN 18 AND 20 OR
LOWER(age) BETWEEN 20 AND 25 OR
LOWER(age) BETWEEN 25 AND 30 OR
LOWER(age) BETWEEN 30 AND 35
) AS totalcount
FROM users, states, countries, user_types, media
WHERE
users.id_user_type = user_types.id AND
users.id_state = states.id AND
users.id_country = countries.id AND
media.id_user = users.id AND
media.profile_photo = 1 AND
users.id_user_type = 3 OR
LOWER(age) BETWEEN 18 AND 20 OR
LOWER(age) BETWEEN 20 AND 25 OR
LOWER(age) BETWEEN 25 AND 30 OR
LOWER(age) BETWEEN 30 AND 35
ORDER BY users.id
令人不安的部分是:使用or
條款你有(它沒有意義)
LOWER(age) BETWEEN 18 AND 20 OR
LOWER(age) BETWEEN 20 AND 25 OR
LOWER(age) BETWEEN 25 AND 30 OR
LOWER(age) BETWEEN 30 AND 35
你是什麼試圖用這個查詢來檢索? – 2014-11-02 12:57:24
你怎麼得出這樣的結論:查詢的那一部分是令人不安的部分? – Guffa 2014-11-02 12:57:29