我想按以下顺序订购作为字符串的等级。
K, 1, 2, 4, .... 12
但我不断得到5, 4, 3, ... 12, K, 1
sims_classroom 中的成绩列是 VARCHAR(255),表格是 latin1;
我已经尝试了书中的每一个演员和技巧。目前,我通过添加 0 来获得以下技巧。我究竟做错了什么?
SELECT
(SELECT district_get_name_function(sod.parent_id, sod.id)) AS 'district_name',
(SELECT school_get_name_function(so.id)) AS 'school_name',
st.teacher_username,
st.teacher_first_name,
st.teacher_last_name,
c.name as 'classroom_name',
c.grade,
c.id,
d.name AS 'discipline_name',
d.id AS 'discipline_id',
lc.name AS 'program_name',
lc.id AS 'program_id'
FROM sims_classroom c
.
.
.
ORDER BY
CASE lower(sort_direction) WHEN 'asc' THEN
CASE lower(sort_order)
WHEN 'grade' THEN
CASE c.grade
WHEN 'K' THEN 0
ELSE (c.grade + 0)
END
WHEN 'teachername' THEN lower(st.teacher_first_name)
ELSE c.name
END
END ASC,
CASE lower(sort_direction) WHEN 'desc' THEN
CASE lower(sort_order)
WHEN 'grade' THEN
CASE c.grade
WHEN 'K' THEN 10000
ELSE (c.grade + 0)
END
WHEN 'teachername' THEN lower(st.teacher_first_name)
ELSE c.name
END
END DESC