1

我有选择查询升序,如......

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

我想按升序设置部分名称,并按 Task1 Task2 等顺序排列任务名称。

意味着我想显示数据

1) 部分名称 = jws1 和类似任务 Task1 Task2 Task3 Task4 的部分下

2) 部分名称 = jws2 和类似任务 Task1 Task2 Task3 Task4 的部分下

等等..

4

3 回答 3

2

只需添加二级订单ORDER BY

ORDER BY 
    section_name ASC,
    TaskName ASC
于 2012-10-06T11:32:08.440 回答
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

或者

ORDER BY m.section_name ASC,CAST(SUBSTRING(m.task_name,LOCATE(' ',m.task_name)+1) AS SIGNED) ASC
于 2012-10-06T11:34:30.967 回答
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
于 2012-10-06T11:45:29.140 回答