1

I want to automate the calculation of percentages of pass/fail columns from my tables. What I have done up to now is to use

$query = mysqli_query(
   $con, 
   "SELECT column_name FROM information_schema.columns WHERE TABLE_NAME='door1'"
);

in order to get all the column names and then

$x=mysqli_query(
  $con,
  "SELECT 100 * SUM($b ='$a')/COUNT($b) AS total FROM door1"
);

to calculate the percentages. Certain columns are not pass/fail but include other information that is irrelevant to this.

I want for those columns to print N/A instead of 0%. I thought of changing the data type of the pass fail columns to something else and run the above only for them but I am not sure how to do that. These columns that are different change from table to table so I don't want to write out all of the columns I want or don't want. Any ideas?

Sabuj Hassan
  • 38,281
  • 14
  • 75
  • 85
  • see here: http://stackoverflow.com/questions/770579/how-to-calculate-percentage-with-a-sql-statement – Awlad Liton Jan 04 '14 at 19:44
  • No. That had a specific column to look into. The columns for me are different for each table and some tables have numerous columns. I just want to exclude the ones that are not pass/fail. I am not looking how to get the percentage as I already did that. – user3159515 Jan 04 '14 at 19:47

0 Answers0