Matching a value to multiple columns (in one statement) from a table using MySQL

后端 未结 9 1835
无人共我
无人共我 2021-02-08 21:29

I\'m working with a table in MySQL that contains the following columns:

id, january, february, march, april, etc

The data in the table looks li

9条回答
  •  天涯浪人
    2021-02-08 22:10

    I understand what Mr.Smith is trying to do.

    It's a question of 12 rows x 4 columns vs. 1 row x 12 columns.

    The former table design would be something like:

    id, someone's id, month, value x 12 per month

    1, 101, january, 1
    2, 101, february, 1
    3, 101, march, 0
    etc..
    

    The corresponding sql statement to this would be:

    $sqlQuery = "SELECT month FROM my_month_table WHERE value = 1";
    

    What I'm guessing Mr.Smith is trying:

    id, someone's id, january, february, march ...

    $sqlQuery = "SELECT corrensponding_column_names_to_where_clause FROM my_month_table WHERE column_value = 1";
    

提交回复
热议问题