I want to store schools general results in a database in the most efficient way with less repetitions, so the data will be from different schools for different years and the data is in this way, from division 0-4 and for each division it show number of male and female with that division in distinction. preferably i would like a single row,but don’t know if it will be easy to utilize during use in analysis,pulling in tables and graphs.
What i have done.
public function up()
{
Schema::create('csee', function (Blueprint $table) {
$table->id();
$table->integer('school_id');
$table->integer('year');
$table->json('division1')->comment('json with 2 entries which will respectively male then female');
$table->json('division2')->comment('json with 2 entries which will respectively male then female');
$table->json('division3')->comment('json with 2 entries which will respectively male then female');
$table->json('division4')->comment('json with 2 entries which will respectively male then female');
$table->json('division0')->comment('json with 2 entries which will respectively male then female');
$table->timestamps();
});
}
below is a picture of the results table
Sample of insertion to database would look like this
DB::table('csee')->insert([
'school_id' => 1,
'year' => 2023,
'division1' => json_encode([4, 6]), // 4 males, 6 females
'division2' => json_encode([5, 7]), // 5 males, 7 females
'division3' => json_encode([6, 8]), // 6 males, 8 females
'division4' => json_encode([7, 9]), // 7 males, 9 females
'division0' => json_encode([8, 10]), // 8 males, 10 females
'created_at' => now(),
'updated_at' => now(),
]);