Was needed to count progress of finished / all elements,below is an example how to do this…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
CREATE DEFINER=`root`@`localhost` FUNCTION `eventElementProgress`(eventsID integer,testsID integer) RETURNS varchar(45) CHARSET utf8 BEGIN DECLARE allVar INT; DECLARE finishedVar INT; DECLARE rounded decimal(10,2); DECLARE r decimal(10,2); DECLARE progressInChars varchar(45); SELECT count(*) FROM coffeetest_db.users_has_events_has_tests where events_id=eventsID and tests_id=testsID into allVar; SELECT count(*) FROM coffeetest_db.users_has_events_has_tests where events_id=eventsID and tests_id=testsID and status_id=(select max(id) from status) into finishedVar; #select (finishedVar/allVar*100) into r; #select cast(round((finishedVar/allVar*100),2) as char (50)) into progressInChars ; select (finishedVar/allVar*100) into r; select round(r,2) into rounded; select cast(rounded as char(50)) into progressInChars; #select round(r,2) into rounded; #select progressInChars; RETURN progressInChars; END |