纵表转横表的"SQL"示例:

纵表转横表的"SQL"示例:
  纵表结构:
  
  fname ftype fvalue
  小乔 zaocan 10
  小乔 zhongcan 20
  小乔 wancan 5
  
  转换后的表结构:
  
  fname zaocan_value zhongcan_value wancan_value
  小乔 10 20 5
  
  纵表转横表SQL示例:
  
  select Fname, sum(case Ftype when 'zaocan'
  then Fvalue else 0 end) as zaocan_value,
  sum(case Ftype when 'zhongcan'
  then Fvalue else 0 end) as zhongcan_value,
  sum(case Ftype when 'wancan' then Fvalue else 0 end)
  as wancan_value from case_table group by Fname

阅读更多
文章标签: sql table
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭