Home > database >  Mysql Query brings up position 0 when datatype is double
Mysql Query brings up position 0 when datatype is double

Time:07-21

I have the following query that positions students according to average mark, but it works well when the data type is an integer, when it is a double or floats it positions some students to be zero, what could be the problem?

SELECT 
 assessement_progress_reports.student_id
,assessement_progress_reports.student_average
,FIND_IN_SET(assessement_progress_reports.student_average
,(SELECT 
GROUP_CONCAT(assessement_progress_reports.student_average 
ORDER BY assessement_progress_reports.student_average DESC) 
FROM 
assessement_progress_reports 
WHERE 
assessement_id=1 
AND student_stream=1)) student_position
FROM 
assessement_progress_reports  
WHERE 
assessement_id=2  
AND student_id=123 
AND student_stream=2

CodePudding user response:

FIND_IN_SET() is only supposed to be used on strings, not any sort of numbers. it's actually curious that it works on INTs.

you should look into the RANK() function, as I believe it will do exactly what you are trying to do in a more efficient way.

  • Related