0

我希望这种类型的输出以这种格式从数据库中获取 task_name

Task 10 Task 2 Task 3 Task 5........

我的查询是

 SELECT task_name, section_name, ref_student_id
 FROM scores
 WHERE ref_student_id = '".$studentid."'
    AND section_name = 'sm1'
 GROUP BY task_name

所以我想这样输出..

 Task 2 Task 3 Task 5 Task 10........
4

3 回答 3

1

用这个

"SELECT task_name, section_name, ref_student_id
 FROM scores
WHERE ref_student_id = '1'
AND section_name = 'sm1'
GROUP BY task_name
ORDER BY cast( SUBSTRING( task_name, 5 ) AS unsigned ) ASC"   
于 2012-10-02T05:12:22.820 回答
0

用这个

SELECT task_name, section_name, ref_student_id
FROM scores
WHERE ref_student_id = '".$studentid."'
AND section_name = 'sm1'
ORDER BY ltrim(task_name) ASC          //order by should come for ordering....
GROUP BY task_name

代替

SELECT task_name, section_name, ref_student_id
FROM scores
WHERE ref_student_id = '".$studentid."'
AND section_name = 'sm1'
GROUP BY task_name
于 2012-10-02T05:04:55.980 回答
0
"select task_name,section_name,ref_student_id from scores where ref_student_id = '".$studentid."' and section_name = 'sm1' GROUP BY task_name order by task_name ASC "

按升序排列

于 2012-10-02T05:05:09.027 回答