sql行转列

with tt as(
 select 
 'A' product,
 100 price,
 '2021第1季度' time
  union  all

  select 
 'A' product,
 777 price,
 '2021第1季度' time
  union  all

  select 
 'A' product,
 111 price,
 '2021第2季度' time

 union  all

  select 
 'A' product,
 222 price,
 '2021第2季度' time



 ) 
 select '最大',* from tt pivot(max(price)for time in( [2021第2季度],[2021第1季度]) )a
 union all
  select '最小',* from tt pivot(min(price)for time in( [2021第2季度],[2021第1季度]) )a

 

posted @ 2021-11-12 16:01  212的s  阅读(29)  评论(0)    收藏  举报