使用CASE语句
-
sql实现列转行的方法是什么
使用SQL中的CASE语句和聚合函数,将列转换为行。SELECT id, MAX(CASE WHEN column_name = 'column1' THEN value END) AS column1, MAX(CASE WHEN column_name = 'column2' THEN value END) AS column2 FROM table_name;
使用SQL中的CASE语句和聚合函数,将列转换为行。SELECT id, MAX(CASE WHEN column_name = 'column1' THEN value END) AS column1, MAX(CASE WHEN column_name = 'column2' THEN value END) AS column2 FROM table_name;