How to represent a 2-D data matrix in a database

后端 未结 6 1705
萌比男神i
萌比男神i 2020-12-07 11:38

I have a data set which consists of an ID and a matrix (n x n) of data related to that ID.

Both the column names (A,B,C,D) and the Row names (1,2,3) are also importa

6条回答
  •  情深已故
    2020-12-07 12:06

    If you want a truly relational solution:

    Matrix
    ------
    id
    
    Matrix_Cell
    -----------
    matrix_id
    row
    col
    value
    

    But constraints to make sure you had valid data would be hideous.

    I would consider a matrix as a single value as far as the DB is concerned and store it as csv:

    Matrix
    ------
    id
    cols
    data
    

    Which is somewhat lighter than XML.

提交回复
热议问题