答案 0 :(得分:3)
如果每行有多个值,那么您期望没有聚合函数?
如果每行都有一个值,那么无论使用sum,min,max还是avg聚合函数都是如此。
像这样(在oracle中):
select row_id, 'C1', 'C2', 'C3'
from (select 1 table_id, 'C1' Column_id, 1 Row_id, 20000 "value" from dual union all
select 1 table_id, 'C2' Column_id, 1 Row_id, 30000 "value" from dual union all
select 1 table_id, 'C3' Column_id, 1 Row_id, 25000 "value" from dual union all
select 1 table_id, 'C1' Column_id, 2 Row_id, 80200 "value" from dual union all
select 1 table_id, 'C2' Column_id, 2 Row_id, 50000 "value" from dual union all
select 1 table_id, 'C3' Column_id, 2 Row_id, 95000 "value" from dual)
pivot(max("value") for column_id in('C1', 'C2','C3'))
答案 1 :(得分:1)
Select Row_ID,
Min(Case DBColumnName When 'c1' Then Value End) c1,
Min(Case DBColumnName When 'c2' Then Value End) c2,
Min(Case DBColumnName When 'c3' Then Value End) c3
From table
Group By Row_ID
编辑:我没有编辑和编写这篇文章。没有运行SQL。我希望,你明白了。