0

大規模なデータセットから値の分布を計算しようとしています。値は 1 から 7 までの FLOAT であり、それらを特定の粒度まで集計したいと考えています。現在、半分の値 (1.0、1.5、2.0 など) に集計していますが、粒度をより動的に設定できるようにしたいと考えています (たとえば、10 進数に)。これを行うスマートな方法はありますか?今、私はこれをします

    //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 INTO 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 into distribution table: " . mysql_error();
  die;
  }

$number_of_1 = "UPDATE distribution_table SET Number = (SELECT SUM(CASE WHEN CollectiveAbility > 0.75 AND CollectiveAbility < 1.25 THEN 1 ELSE 0 END) FROM collective_ability) WHERE Collective_ability = 1.0";
$number_of_1_5 = "UPDATE distribution_table SET Number = (SELECT SUM(CASE WHEN CollectiveAbility > 1.25 AND CollectiveAbility < 1.75 THEN 1 ELSE 0 END) FROM collective_ability) WHERE Collective_ability = 1.5";
$number_of_2 = "UPDATE distribution_table SET Number = (SELECT SUM(CASE WHEN CollectiveAbility > 1.75 AND CollectiveAbility < 2.25 THEN 1 ELSE 0 END) FROM collective_ability) WHERE Collective_ability = 2.0";
$number_of_2_5 = "UPDATE distribution_table SET Number = (SELECT SUM(CASE WHEN CollectiveAbility > 2.25 AND CollectiveAbility < 2.75 THEN 1 ELSE 0 END) FROM collective_ability) WHERE Collective_ability = 2.5";
$number_of_3 = "UPDATE distribution_table SET Number = (SELECT SUM(CASE WHEN CollectiveAbility > 2.75 AND CollectiveAbility < 3.25 THEN 1 ELSE 0 END) FROM collective_ability) WHERE Collective_ability = 3.0";
$number_of_3_5 = "UPDATE distribution_table SET Number = (SELECT SUM(CASE WHEN CollectiveAbility > 3.25 AND CollectiveAbility < 3.75 THEN 1 ELSE 0 END) FROM collective_ability) WHERE Collective_ability = 3.5";
$number_of_4 = "UPDATE distribution_table SET Number = (SELECT SUM(CASE WHEN CollectiveAbility > 3.75 AND CollectiveAbility < 4.25 THEN 1 ELSE 0 END) FROM collective_ability) WHERE Collective_ability = 4.0";
$number_of_4_5 = "UPDATE distribution_table SET Number = (SELECT SUM(CASE WHEN CollectiveAbility > 4.25 AND CollectiveAbility < 4.75 THEN 1 ELSE 0 END) FROM collective_ability) WHERE Collective_ability = 4.5";
$number_of_5 = "UPDATE distribution_table SET Number = (SELECT SUM(CASE WHEN CollectiveAbility > 4.75 AND CollectiveAbility < 5.25 THEN 1 ELSE 0 END) FROM collective_ability) WHERE Collective_ability = 5.0";
$number_of_5_5 = "UPDATE distribution_table SET Number = (SELECT SUM(CASE WHEN CollectiveAbility > 5.25 AND CollectiveAbility < 5.75 THEN 1 ELSE 0 END) FROM collective_ability) WHERE Collective_ability = 5.5";
$number_of_6 = "UPDATE distribution_table SET Number = (SELECT SUM(CASE WHEN CollectiveAbility > 5.75 AND CollectiveAbility < 6.25 THEN 1 ELSE 0 END) FROM collective_ability) WHERE Collective_ability = 6.0";
$number_of_6_5 = "UPDATE distribution_table SET Number = (SELECT SUM(CASE WHEN CollectiveAbility > 6.25 AND CollectiveAbility < 6.75 THEN 1 ELSE 0 END) FROM collective_ability) WHERE Collective_ability = 6.5";
$number_of_7 = "UPDATE distribution_table SET Number = (SELECT SUM(CASE WHEN CollectiveAbility > 6.75 AND CollectiveAbility < 7.25 THEN 1 ELSE 0 END) FROM collective_ability) WHERE 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;
  }
4

0 に答える 0