table_source

PIVOT(

聚合函数(value_column

FOR pivot_column

IN(<column_list>)

)

对于一个字段的汇总和转置,只用一次。

) tb pivot(max(copies) for ORDER_TYPE in ([11],[12],[13],[14])) tb

wKiom1fJL62BzNw0AAAx3ojxOmk986.png-wh_50

对于多个字段的汇总和转置,要嵌套多次。

) tb pivot(max(copies) for ORDER_TYPE in ([11],[12],[13],[14])) tb 

) tb1 pivot(max(price) for order_type1 in ([11],[12],[13],[14])) tb1 

) tb2 pivot(max(amt) for order_type2 in ([11],[12],[13],[14])) tb2 

wKioL1fJL_Czh9HvAABlXUC3gEY984.png-wh_50