简体   繁体   English

MySQL行和列选择

[英]MySQL row and column select

I got a table structure in my HTML 我的HTML中有一个表格结构

在此处输入图片说明

Needs to populate the data as rows and columns, some columns having a value "1" 需要将数据填充为行和列,某些列的值为“ 1”

Fixed 10 Rows and 10 Columns and there are multiple tables 固定10行和10列,并且有多个表

So I just created a database like the following 所以我刚刚创建了一个如下数据库

ga_id (pk)   |   A1  |  A2  |  A3 ......
-------------+-------+------+-------------
 125         |  1    | 0    |  0 ..........
-------------+-------+------+--------------
 126         |  0    | 1    |  1 ...

I got the following questions 我有以下问题

  1. For achieving the same, is my approach is correct ? 为了达到相同目的,我的方法正确吗?

  2. I need to check whether a column or a row is fully occupied with a value "1" 我需要检查列或行是否被值“ 1”完全占用

    for eg:- 例如:
    Case block D4 then I need to check D1,D2,D3..... D10 having the same value ie 1 情况D4,然后我需要检查D1,D2,D3 ..... D10具有相同的值,即1

And A4,B4,C4,D4.......J4 values having the same value 并且A4,B4,C4,D4 ....... J4值具有相同的值

Hope my question is clear, 希望我的问题清楚,

As a comment, the " correct approach " is whatever approach solves your issue. 作为评论,“ 正确的方法 ”是解决您的问题的任何方法。 While normalization and the third normal form are concepts that are battle tested and definitely worth mastering, if the current structure solves your particular issue, go with it. 虽然规范化和第三个范式是经过实战检验并且绝对值得掌握的概念,但是如果当前结构解决了您的特定问题,请继续使用它。

A possible, normalized DB structure would be: 可能的标准化数据库结构为:

  • Table columns: column_id, name 表格栏:column_id,名称
  • Table rows: row_id, name 表格行:row_id,名称
  • Table tables: table_id, name 表格表格:table_id,名称
  • Table table_rows_columns: table_id, row_id, column_id, value 表table_rows_columns:table_id,row_id,column_id,值

By way of example, a normalised environment might look something like this: 举例来说,规范化的环境可能看起来像这样:

CREATE TABLE my_table 
(id INT NOT NULL
,x INT NOT NULL
,y CHAR(1) NOT NULL
,val INT NOT NULL
,PRIMARY KEY(id,x,y)
);

INSERT INTO my_table VALUES
(101,2,'B',1),
(101,2,'I',1),
(101,4,'D',1),
(101,5,'I',1),
(101,7,'D',1),
(101,7,'H',1),
(101,8,'G',1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM