SET @a:=0;

SELECT

	@a:=@a+1 No,
	person.id as 'Person ID',
	UPPER(CONCAT(fname, ' ', lname)) as 'NAME',
    YEAR(CURDATE()) - YEAR(person.date_of_birth)as 'AGE',
    person.weight as 'WEIGHT',
    weightclasses.category as 'CATEGORY',
    person.gender as 'GENDER',
    /*weightclasses.classTitle as 'TITLE',*/
    weightclasses.maxWeight as 'UW',
    weightclasses.className as 'NAME',
    clubs.title as 'CLUB'
        
FROM person

LEFT JOIN 
	clubs 
    ON 
    person.clubID = clubs.id

LEFT JOIN 
	weightclasses 
    ON
    YEAR(CURDATE()) - YEAR(person.date_of_birth) BETWEEN weightclasses.minAge AND weightclasses.maxAge

WHERE

	weightclasses.gender = person.gender and 
    person.weight > weightclasses.minWeight and 
    person.weight <= weightclasses.maxWeight
    
/*
    AND
    weightclasses.category = 'SENIOR'
    AND
    weightclasses.gender = 'MALE'
    AND
    weightclasses.className = 'UNDER 68'
*/	

ORDER BY

	weightclasses.category,
    weightclasses.gender,
    weightclasses.minWeight,
    weightclasses.classTitle,
	person.fname,
    person.lname,
    YEAR(CURDATE()) - YEAR(person.date_of_birth)