I've got the following mysql script which gets the total amount of rows in a few tables and adds them together. I then want to use this "Total" in another script which executes next.
I want to display percentage of the count to the total. Obviously the below doesn't work as "Total" is not recognised. How can I use the result from the first statement in the next statement?
select (
(select count(*) from t1) +
(select count(*) from t2) +
(select count(*) from t3) +
(select count(*) from t4) +
(select count(*) from t5) +
(select count(*) from t6)) As Total;
select
round((count(greater10) / Total * 100),2) As greater10,
round((count(8to10) / Total * 100),2) As 8to10,
round((count(6to8) / Total * 100),2) As 6to8,
round((count(4to6) / Total * 100),2) As 4to8,
round((count(2to4) / Total * 100),2) As 2to4,
round((count(halfto2) / Total * 100),2) As halfto2,
round((count(lesshalf)/ Total * 100),2) As lesshalf
from t7;