I’m working on the SQL project “Analyzing Heart Disease” and some arithmetic doesn’t seem to be working as I would expect.
Step 6 of the exercise asks you to perform some math to find the percentage of active and inactive patients in a database. You have a table of active patients and a table of inactive patients. You then create “dummy” tables and records in order to perform math on these values.
For instance, you create the table and column
total_active.active which contains one record which is the number of active patients. The same goes for
My issue is that I’d like to perform the order of operations slightly differently than the lesson hint because it’s more intuitive for me.
So instead of using
total_active.active * 100 / total_patients.total
I’d like to do the very minor change of
total_active.active / total_patients.total * 100
The problem I’m having is that for some reason the second option produces a result of ‘0’, but that’s obviously not true.
Any help in understanding this would be greatly appreciated.
Original code with correct output:
Revised code with incorrect output: