MySQL concat() to create column names to be used in a query?

前端 未结 5 610
走了就别回头了
走了就别回头了 2020-11-30 06:43

I would like to concatenate column names in a way that the first part of the column name is a string and the second part is a number which is the result of another query.

5条回答
  •  无人及你
    2020-11-30 07:25

    I would suggest looking at information_schema. The following code is untested but should theoretically work. Obviously replace your table name with an appropriate table name or link to information_schema.tables and use the table_type in your where clause

    select concat('column', column_name) from information_schema.columns where table_name ='your table name'
    

提交回复
热议问题