Advanced Sorting SQL command

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Asteras

    #1

    Advanced Sorting SQL command

    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

    #2
    Re: Advanced Sorting SQL command

    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_t able order by least(Mark1,Mar k2);

    --

    This space not for rent.

    Comment

    • Asteras

      #3
      Re: Advanced Sorting SQL command

      Dear Malcolm,

      Thank you very much for your advice. It worked perfectly.

      Best Regards,

      Ioannis

      Comment

      Working...