我有升序的选择查询,如...
select DISTINCT
(m.task_name) as TaskName,
m.activity_name as ActivityName,
m.actual_score,
m.score,
m.section_name
from
users u,
som_scores m
where
m.ref_student_id = '".$row['userid']."' and
m.section_name IN('jws1','jws2','jws3','jws4','sm1','srs1','Pws1','Pws2','lws1','sp1')
ORDER BY
m.section_name ASC
我想按升序设置Section名称,并按Task1 Task2等顺序创建任务名称顺序。
表示我想显示
等数据1)部分名称= jws1和类似任务的部分 Task1 Task2 Task3 Task4
2)部分名称= jws2以及类似任务的部分 Task1 Task2 Task3 Task4
等等..
答案 0 :(得分:2)
只需在ORDER BY
ORDER BY
section_name ASC,
TaskName ASC
答案 1 :(得分:0)
使用此查询
select DISTINCT(m.task_name) as TaskName, m.activity_name as ActivityName,m.actual_score,m.score,m.section_name from users u, som_scores m where m.ref_student_id = '".$row['userid']."' and m.section_name IN('jws1','jws2','jws3','jws4','sm1','srs1','Pws1','Pws2','lws1','sp1') ORDER BY m.section_name ASC,m.task_name ASC
这将首先按部分排序,然后按任务名称
排序尝试此订单
m.task_name+0 ASC
OR
ORDER BY m.section_name ASC,CAST(SUBSTRING(m.task_name,LOCATE(' ',m.task_name)+1) AS SIGNED) ASC
答案 2 :(得分:0)
我找到了这样的解决方案“cast( SUBSTRING(TaskName, 5 ) AS unsigned ) ASC
”
select DISTINCT
(m.task_name) as TaskName,
m.activity_name as ActivityName,
m.actual_score,
m.score,
m.section_name
from
users u,
som_scores m
where
m.ref_student_id = '".$row['userid']."' and
m.section_name IN('jws1','jws2','jws3','jws4','sm1','srs1','Pws1','Pws2','lws1','sp1')
ORDER BY
m.section_name ASC,
cast( SUBSTRING(TaskName, 5 ) AS unsigned ) ASC,
ActivityName ASC