lundi 9 mars 2015

Giving a row number to mysql data based on date

I have been trying to add a row number for my data i.e. each row would have a number based on my ordering, if I list them based on date, the one which is the oldest date would get row number 1 and so on regardless of their actual id stored in the database.


I have wrote this query but if I insert a column with a date older than the previous ones, it doesn't get the row number 1 as I want it to.


Here is my query :



SET @row_number:=0; Select @row_number:=@row_number+1 AS 'number', evaluation_form_id AS 'id',
CONCAT(student_first_name, ' ' , student_second_name, ' ' , student_third_name, ' ' , student_last_name)
AS 'student_name', date FROM evaluation_form, student
WHERE student_id = @id AND date BETWEEN '@fromDate' AND '@toDate' ORDER BY date ASC ;


I'm using C# and windows forms.


Aucun commentaire:

Enregistrer un commentaire