对于25000条记录,此查询大约需要45秒到1分钟。我需要一个替代案例 expirydate字段的条件
SELECT a.id,
a.name,
a.lastname,
a.plainpass,
a.email,
a.custom_usertype,
a.custom_registertype,
a.content_state,
a.year,
a.bflag,
a.block,
a.trail_expiry,
a.subscribe_date,
CASE a.custom_usertype
WHEN (5)
THEN
(IF(
(SELECT custom_usertype
FROM skw_users
WHERE id = a.parent_id AND custom_usertype = 11) = 11
AND a.custom_registertype = "subscribed",
(SELECT DATE_FORMAT(prod.expiry_date, "%Y-%m-%d")
FROM skw_product prod
WHERE prod.student_id = a.id
ORDER BY prod.expiry_date DESC
LIMIT 1),
IF(
(SELECT custom_usertype
FROM skw_users
WHERE id = a.parent_id AND custom_usertype = 10) =
10
AND a.custom_registertype = "subscribed",
(SELECT DATE_FORMAT(prod.expiry_date, "%Y-%m-%d")
FROM skw_product prod
WHERE prod.User_id = a.parent_id
ORDER BY prod.expiry_date DESC
LIMIT 1),
(SELECT DATE_FORMAT(trail_expiry, "%Y-%m-%d")
FROM skw_users
WHERE id = a.parent_id))))
WHEN (3)
THEN
(IF(a.custom_registertype = "subscribed",
(SELECT DATE_FORMAT(prod.expiry_date, "%Y-%m-%d")
FROM skw_product prod
WHERE prod.User_id = a.parent_id
ORDER BY prod.expiry_date DESC
LIMIT 1),
(SELECT DATE_FORMAT(trail_expiry, "%Y-%m-%d")
FROM skw_users
WHERE id = a.parent_id)))
ELSE
(IF(a.custom_registertype = "subscribed",
(SELECT DATE_FORMAT(prod.expiry_date, "%Y-%m-%d")
FROM skw_product prod
WHERE prod.User_id = a.id
ORDER BY prod.expiry_date DESC
LIMIT 1),
(SELECT DATE_FORMAT(trail_expiry, "%Y-%m-%d")
FROM skw_users
WHERE id = a.id)))
END
AS expiry_date_n,
CASE a.custom_usertype
WHEN (5)
THEN
(SELECT TRIM(NAME)
FROM skw_users
WHERE id = a.parent_id AND custom_usertype = 10)
WHEN (3)
THEN
(SELECT TRIM(NAME)
FROM skw_users
WHERE id = a.parent_id)
WHEN (10)
THEN
(SELECT TRIM(NAME)
FROM skw_users
WHERE id = a.id AND a.custom_usertype = 10)
END
AS schoolname
FROM `skw_users` AS a
INNER JOIN
skw_user_usergroup_map AS map2
ON map2.user_id = a.id
WHERE map2.group_id = 2
GROUP BY a.id
ORDER BY trim(a.name) ASC
对于25000条记录,此查询大约需要45秒到1分钟。我需要一个替代案例 expirydate字段的条件
答案 0 :(得分:0)
尝试添加Primary Key
列a.id
上的索引以及您应用a.custom_usertype
希望这会加快查询的执行速度:)