Combine multiple rows into one MySQL

后端 未结 2 544
臣服心动
臣服心动 2020-12-20 08:43

I need some help. I googled for solution, but I didn\'t found one.

I have three tables:

langs
(int) id | (varchar) language
    1    |       English
         


        
2条回答
  •  隐瞒了意图╮
    2020-12-20 09:40

    SELECT CONCAT(
      ' SELECT `value`.`key_id`,'
    ,        '`keys`.`keys`,'
    ,         GROUP_CONCAT(
               'GROUP_CONCAT(IF(`value`.`lang_id`=',id,',`value`.`value`,NULL))'
              ,   ' AS `', REPLACE(language, '`', '``'), '`'
              )
    , ' FROM `keys` JOIN `value` ON `value`.`key_id` = `keys`.`id`'
    , ' GROUP BY `value`.`key_id`'
    )
    INTO @sql
    FROM `langs`;
    
    PREPARE stmt FROM @sql;
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt;
    

提交回复
热议问题