MySQL 将表列数据转换为行
要在 MySQL 中有效地将表列数据转换为行,您可以使用聚合函数的组合和有条件的
查询:
SELECT a.ID, a.user_ID, a.job_id, MAX(CASE WHEN c.question = 'Is it this?' THEN b.answer END) 'Is it this?', MAX(CASE WHEN c.question = 'Or this?' THEN b.answer END) 'Or this?', MAX(CASE WHEN c.question = 'Or that? ' THEN b.answer END) 'Or that? ' FROM Results a INNER JOIN Answers b ON a.id = b.fk_result_id INNER JOIN Question c ON b.fk_question_id = c.ID GROUP BY a.ID, a.user_ID, a.job_id;
解释:
其他提示:
以上是如何使用聚合和条件语句将 MySQL 列数据转换为行?的详细内容。更多信息请关注PHP中文网其他相关文章!