how to increament a value in mysql

1009 views mysql
5

I want increment a value after every cycle after every row @a value must be incremented

SET @a=1;
SELECT  @a,std_id,SUM(`read_mark`+`write_mark`+`homework`+`classwork`) AS tot FROM tbl_exam
where `class_detail_id`=26 AND YEAR(`date`)=1397 GROUP BY `std_id` ORDER BY
SUM(`read_mark`+`write_mark`+`homework`+`classwork`) DESC;
SET @a=@a+1;

answered question

1 Answer

11

You can try below

SET @a = 0;

SELECT 
    (@a:=@a + 1) AS num, std_id,SUM(`read_mark`+`write_mark`+`homework`+`classwork`) AS tot 
    FROM tbl_exam
    where `class_detail_id`=26 AND YEAR(`date`)=1397 GROUP BY `std_id` 
   ORDER BY tot  DESC

posted this

Have an answer?

JD

Please login first before posting an answer.