sorting table data in mysql database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • parimi
    New Member
    • Nov 2008
    • 3

    #1

    sorting table data in mysql database

    hi this is pawanparimi doing mca working on a project "conducting online examination",i have a table in mysql database, the table schema is RANKS=student_i d, section1, section2, section3, totalmarks, rank; i want to sort this table based on the field totalmarks and then i have to give them ranks according to the marks the highest marks get the top rank 1 like that can any one help me please
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    There is no need for that rank column because it can always be calculated based on total marks. Including it in there means that you are going to have to update it (for every row) every time there is a change in one row's total marks.

    A query that gives you that rank looks like

    [CODE=mysql]select @rownum:=@rownu m+1 as rank, t.* from Rank t,
    (SELECT @rownum:=0) r
    order by
    totalmarks desc [/CODE]

    Comment

    Working...