0
  1. I am trying to design a database for mark sheet data of a school having different types of exams of different levels or class.
  2. Is it possible to have single table where I can store data in string (array serialize PHP) and perform a search based on subjects easily (Maximum/Minimum/Average).

The table look something like this with bit variations-

Class 5

XXXXX ------ Math ----- Hindi ----- English
Amit -------- 10 ------- 20 ----------31
Alok -------- 10 ------- 20 ----------31

Class 8

XXXXX ------ Math ----- Hindi ----- English ---- Science
Amit -------- 10 ------- 20 ----------31 ----------20
Alok -------- 10 ------- 20 ----------31 ----------23

Using PHP's array serialize I will have marks data in string as

a:4:{s:4:"math";i:20;s:5:"hindi";i:30;s:7:"english";i:23;s:7:"science";i:10;}

Should I have separate table or can I have the condensed table so that database does not become too heavy with too many rows?

2
  • Have you tried JSON structure?
    – SQL.RK
    Commented Feb 9, 2017 at 12:20
  • I have advantage of serialize over JSON... Although JSON is efficient too. Commented Feb 9, 2017 at 15:06

1 Answer 1

3

You really should not hide the data you want to do arithmetic inside any kind of structure.

Use a table with 4 columns: class, student, subject, score.

Then things like each student's avg score:

SELECT student,
       AVG(score)
    FROM tbl
    GROUP BY student;
4
  • You are right. But what if data has variable fields or subjects.? How can I handle that? Commented Feb 18, 2017 at 7:47
  • "Variable fields"? Perhaps we need to see some more data, plus more desired output. The new example(s) should highlight what you are asking.
    – Rick James
    Commented Feb 18, 2017 at 16:14
  • Variable fields mean, I need data in variable columns... Commented Feb 18, 2017 at 22:06
  • I will need normalisation here to make it efficient. Commented Jun 5, 2020 at 9:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.