mysql - First three Groups with Highest Marks should have specific points 5,3, 1 -
this question has answer here:
my table
+------+--------+---------+-------+--------+ | name | group1 | section | marks | points | +------+--------+---------+-------+--------+ | s1 | g1 | class1 | 55 | (null) | | s16 | g1 | class1 | 55 | (null) | | s17 | g1 | class1 | 55 | (null) | | s2 | (null) | class2 | 33 | (null) | | s25 | g10 | class1 | 55 | (null) | | s26 | g10 | class1 | 55 | (null) | | s4 | g88 | class2 | 65 | (null) | | s5 | g88 | class2 | 65 | (null) | | s32 | (null) | class1 | 65 | (null) | | s7 | g5 | class1 | 32 | (null) | | s18 | g5 | class1 | 32 | (null) | | s10 | (null) | class2 | 78 | (null) | | s8 | g8 | class1 | 22 | (null) | | s20 | g8 | class1 | 22 | (null) | | s22 | g9 | class1 | 20 | (null) | | s23 | g9 | class1 | 20 | (null) | | s13 | g55 | class2 | 33 | (null) | | s36 | g55 | class2 | 33 | (null) | +------+--------+---------+-------+--------+
sql fiddle : http://www.sqlfiddle.com/#!2/f4b54/1/0
i have raised question before, according comments tried improve question more clear.
i trying give specific points first 3 groups highest marks in each section. add 5 points each student got highest mark in section, 3 points 2nd highest marks , 1 points 3rd highest group. duplicate marks may occur group.
eg: in class1 - group 'g1' , 'g10' got '55' , got highest mark in 'class1'. give '5' points students in group 'g1' and' g10'.
group g5 got second highest marks, student in group should give 3 points. same way g8 - 1 point.
plz note : student doesnt have group id student participating single item, not consider records.
i using following code, code works fine individual students, dont know how give points group members.
select t1.name, t1.section, t1.marks mytable t1 join (select section, substring_index(group_concat (distinct marks order marks desc), ',', 3) marks3 mytable section = 'class1' group section ) tsum on t1.section = tsum.section , find_in_set(t1.marks, tsum.marks3) > 0 order section, marks desc, id desc
my final output looks section. plz give 1 section (class1)
+------+--------+---------+-------+--------+ | name | group1 | section | marks | points | +------+--------+---------+-------+--------+ | s1 | g1 | class1 | 55 | 5 | | s16 | g1 | class1 | 55 | 5 | | s17 | g1 | class1 | 55 | 5 | | s2 | (null) | class2 | 33 | (null) | | s25 | g10 | class1 | 55 | 5 | | s26 | g10 | class1 | 55 | 5 | | s4 | g88 | class2 | 65 | (null) | | s5 | g88 | class2 | 65 | (null) | | s32 | (null) | class1 | 65 | (null) | | s7 | g5 | class1 | 32 | 3 | | s18 | g5 | class1 | 32 | 3 | | s10 | (null) | class2 | 78 | (null) | | s8 | g8 | class1 | 22 | 1 | | s20 | g8 | class1 | 22 | 1 | | s22 | g9 | class1 | 20 | (null) | | s23 | g9 | class1 | 20 | (null) | | s13 | g55 | class2 | 33 | (null) | | s36 | g55 | class2 | 33 | (null) | +------+--------+---------+-------+--------+
kindly me..
this answer given itay
select t1.`id`, t1.`name`, t1.`group1`, t1.`section`, t1.`marks`, `t_group_points`.`points` `students` t1 left join ( ( select `t4`.`group1`, `t_points`.`points` (select `t3`.`group1`, avg(`t3`.`marks`) `avg` `students` `t3` (`t3`.`section` = 'class1') , (`t3`.`group1` not null) group `t3`.`group1`) `t4` inner join ( (select `top`.`avg`, case @currow := @currow + 1 when '1' 5 when '2' 3 when '3' 1 else null end 'points' (select `t_avg`.`avg` (select `t2`.`group1`, avg(`t2`.`marks`) `avg` `students` `t2` (`t2`.`section` = 'class1') , (`t2`.`group1` not null) group `group1`) `t_avg` group `t_avg`.`avg` order `avg` desc limit 0, 3) `top`, (select @currow:=0) r ) `t_points`) on (`t_points`.`avg` = `t4`.`avg`) ) `t_group_points`) on (`t_group_points`.`group1` = `t1`.`group1`)
Comments
Post a Comment