Come apportare valore in ordine ascendente nel mysql?
-
12-12-2019 - |
Domanda
Voglio questo tipo di output da recuperare Task_Name dal database come in questo formato
Task 10 Task 2 Task 3 Task 5........
.
La mia query è
SELECT task_name, section_name, ref_student_id
FROM scores
WHERE ref_student_id = '".$studentid."'
AND section_name = 'sm1'
GROUP BY task_name
.
Quindi voglio produrre come questo ..
Task 2 Task 3 Task 5 Task 10........
. Soluzione
Usa questo
"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"
. Altri suggerimenti
"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 "
.
ordine crescendo
use this
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
instead of
SELECT task_name, section_name, ref_student_id
FROM scores
WHERE ref_student_id = '".$studentid."'
AND section_name = 'sm1'
GROUP BY task_name
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow