|
Home > Archive > MySQL Server Forum > June 2005 > Advanced Sorting SQL command
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Advanced Sorting SQL command
|
|
| Asteras 2005-06-17, 1:23 pm |
| Hi there,
If we have a student score table with the names of 5 students and their
marks in two exams:
+--------+-------+-------+
| Name | Mark1 | Mark2 |
+--------+-------+-------+
| John | 10 | 8 |
| George | 7 | 2 |
| Paul | 3 | 6 |
| Nick | 9 | 6 |
| Adam | 4 | 8 |
+--------+-------+-------+
I want to order the entries, according to the WORST of the two marks of
each of the students. IE:
+--------+-------+-------+------------+
| Name | Mark1 | Mark2 | Worst Mark |
+--------+-------+-------+------------+
| John | 10 | 8 | 8 |
| Nick | 9 | 6 | 6 |
| Adam | 4 | 8 | 4 |
| Paul | 3 | 6 | 3 |
| George | 7 | 2 | 2 |
+--------+-------+-------+------------+
Of course, I do not really want the "Worst Mark" column (that is just
to show you, on what criteria I want the sorting).
I would be indebted if you could suggest any SQL command for this
advanced sorting.
Thanks in advance.
Asteras
| |
| Malcolm Dew-Jones 2005-06-17, 8:23 pm |
| Asteras (asteras@gmail.com) wrote:
: Hi there,
: If we have a student score table with the names of 5 students and their
: marks in two exams:
: +--------+-------+-------+
: | Name | Mark1 | Mark2 |
: +--------+-------+-------+
: | John | 10 | 8 |
: | George | 7 | 2 |
: | Paul | 3 | 6 |
: | Nick | 9 | 6 |
: | Adam | 4 | 8 |
: +--------+-------+-------+
: I want to order the entries, according to the WORST of the two marks of
: each of the students. IE:
: +--------+-------+-------+------------+
: | Name | Mark1 | Mark2 | Worst Mark |
: +--------+-------+-------+------------+
: | John | 10 | 8 | 8 |
: | Nick | 9 | 6 | 6 |
: | Adam | 4 | 8 | 4 |
: | Paul | 3 | 6 | 3 |
: | George | 7 | 2 | 2 |
: +--------+-------+-------+------------+
In mysql
select * from student_score_table order by least(Mark1,Mark2);
--
This space not for rent.
| |
| Asteras 2005-06-20, 7:23 am |
| Dear Malcolm,
Thank you very much for your advice. It worked perfectly.
Best Regards,
Ioannis
|
|
|
|
|