p19359899 2017-03-29 07:17 采纳率: 60%
浏览 1371

sql 语句 竖表转横表再加连接查询(如下图),求sql 语句

sql 语句 竖表转横表再加连接查询(如下图),求sql 语句

图片说明

  • 写回答

2条回答 默认 最新

  • yongc20 2017-03-29 08:12
    关注

    select a.reportid,a.reportdate,a.person,a.remark,
    sum((case b.testitem when '项目1' then b.testvalue end)) "项目1",
    sum((case b.testitem when '项目2' then b.testvalue end)) "项目2",
    sum((case b.testitem when '项目3' then b.testvalue end)) "项目3",
    sum((case b.testitem when '项目4' then b.testvalue end)) "项目4",
    sum((case b.testitem when '项目5' then b.testvalue end)) "项目5",
    sum((case b.testitem when '项目6' then b.testvalue end)) "项目6",
    sum((case b.testitem when '项目7' then b.testvalue end)) "项目7"
    from table_a a
    left join table_b b
    on a.reportid=b.reportid
    group by a.reportid,a.reportdate,a.person,a.remark
    order by a.reportid

    评论

报告相同问题?

悬赏问题

  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素