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中文網其他相關文章!