/* I am building this function to be used for listing clubs classes */
select

/* This section is to get club data */
upper(to_clubs.id) as 'clubId',
upper(to_clubs.title) as 'clubName',
to_clubs.logo as 'clubLogo',

/* This section is to get trainer data */
to_members.id as 'trainerId',
concat(to_members.fname, " ", to_members.lname) as 'trainerName',
to_members.picture as 'trainerPicture',
to_activities.id as 'activityId',
to_activities.name as 'activityName',

/* This section is to get class data */
to_clubs_classes.id as 'classId',
upper(to_clubs_classes.studentType) as 'classStudents',
to_clubs_classes.startTime as 'classStart',
to_clubs_classes.endTime as 'classEnd',
TIMEDIFF(to_clubs_classes.endTime, to_clubs_classes.startTime) as 'classDuration',
to_clubs_classes.studentLimit as 'classlimit',

/* This section is to calculate the number of class members */
(select count(*) from to_clubs_payments where to_clubs_payments.class = to_clubs_classes.id) as 'classMembers',

/* This section is to find out if the class is vacant or full */
if(false, upper('full'), upper('vacant')) AS 'classStatus'

from

/* Source Table */
to_clubs_classes

/* Linked Tables */
left join to_clubs on to_clubs_classes.club = to_clubs.id
left join to_activities on to_clubs_classes.activity = to_activities.id
left join to_members on to_clubs_classes.trainner = to_members.id