Calculate the distribution of values in PHP and MySQL -
i'm trying calculate distribution of values large data set. values floats between 1 , 7, , i'd aggregate them granularity. right i'm aggregating half values (1.0, 1.5, 2.0, etc) i'd able set granularity more dynamically (for example 1 decimal). there smart way of doing this? right this
//create distribution table $distribution_table="create table distribution_table(collective_ability float primary key, number int)"; // execute query if (mysql_query($distribution_table)) { echo "table distribution_table created successfully"; } else { echo "error creating distribution table: " . mysql_error(); die; } //calculate distribution of collective ability $distribution = "insert distribution_table (collective_ability) values (1.0),(1.5),(2.0),(2.5),(3.0),(3.5),(4.0),(4.5),(5.0),(5.5),(6.0),(6.5),(7.0)"; // execute query if (mysql_query($distribution)) { } else { echo "error selecting inserting values distribution table: " . mysql_error(); die; } $number_of_1 = "update distribution_table set number = (select sum(case when collectiveability > 0.75 , collectiveability < 1.25 1 else 0 end) collective_ability) collective_ability = 1.0"; $number_of_1_5 = "update distribution_table set number = (select sum(case when collectiveability > 1.25 , collectiveability < 1.75 1 else 0 end) collective_ability) collective_ability = 1.5"; $number_of_2 = "update distribution_table set number = (select sum(case when collectiveability > 1.75 , collectiveability < 2.25 1 else 0 end) collective_ability) collective_ability = 2.0"; $number_of_2_5 = "update distribution_table set number = (select sum(case when collectiveability > 2.25 , collectiveability < 2.75 1 else 0 end) collective_ability) collective_ability = 2.5"; $number_of_3 = "update distribution_table set number = (select sum(case when collectiveability > 2.75 , collectiveability < 3.25 1 else 0 end) collective_ability) collective_ability = 3.0"; $number_of_3_5 = "update distribution_table set number = (select sum(case when collectiveability > 3.25 , collectiveability < 3.75 1 else 0 end) collective_ability) collective_ability = 3.5"; $number_of_4 = "update distribution_table set number = (select sum(case when collectiveability > 3.75 , collectiveability < 4.25 1 else 0 end) collective_ability) collective_ability = 4.0"; $number_of_4_5 = "update distribution_table set number = (select sum(case when collectiveability > 4.25 , collectiveability < 4.75 1 else 0 end) collective_ability) collective_ability = 4.5"; $number_of_5 = "update distribution_table set number = (select sum(case when collectiveability > 4.75 , collectiveability < 5.25 1 else 0 end) collective_ability) collective_ability = 5.0"; $number_of_5_5 = "update distribution_table set number = (select sum(case when collectiveability > 5.25 , collectiveability < 5.75 1 else 0 end) collective_ability) collective_ability = 5.5"; $number_of_6 = "update distribution_table set number = (select sum(case when collectiveability > 5.75 , collectiveability < 6.25 1 else 0 end) collective_ability) collective_ability = 6.0"; $number_of_6_5 = "update distribution_table set number = (select sum(case when collectiveability > 6.25 , collectiveability < 6.75 1 else 0 end) collective_ability) collective_ability = 6.5"; $number_of_7 = "update distribution_table set number = (select sum(case when collectiveability > 6.75 , collectiveability < 7.25 1 else 0 end) collective_ability) collective_ability = 7.0"; // execute query if (mysql_query($number_of_1)) { } else { echo "error entering number count: " . mysql_error(); die; } // execute query if (mysql_query($number_of_1_5)) { } else { echo "error entering number count: " . mysql_error(); die; } // execute query if (mysql_query($number_of_2)) { } else { echo "error entering number count: " . mysql_error(); die; } // execute query if (mysql_query($number_of_2_5)) { } else { echo "error entering number count: " . mysql_error(); die; } // execute query if (mysql_query($number_of_3)) { } else { echo "error entering number count: " . mysql_error(); die; } // execute query if (mysql_query($number_of_3_5)) { } else { echo "error entering number count: " . mysql_error(); die; } // execute query if (mysql_query($number_of_4)) { } else { echo "error entering number count: " . mysql_error(); die; } // execute query if (mysql_query($number_of_4_5)) { } else { echo "error entering number count: " . mysql_error(); die; } // execute query if (mysql_query($number_of_5)) { } else { echo "error entering number count: " . mysql_error(); die; } // execute query if (mysql_query($number_of_5_5)) { } else { echo "error entering number count: " . mysql_error(); die; } // execute query if (mysql_query($number_of_6)) { } else { echo "error entering number count: " . mysql_error(); die; } // execute query if (mysql_query($number_of_6_5)) { } else { echo "error entering number count: " . mysql_error(); die; } // execute query if (mysql_query($number_of_7)) { } else { echo "error entering number count: " . mysql_error(); die; }