开发者社区> 问答> 正文

数据库 SQL查询语句 简化语句

screenshot
screenshot
请问 怎样从上面的数据表中查询出下面表的效果?求大神指教

展开
收起
吴孟桥 2016-06-16 16:54:57 2134 0
1 条回答
写回答
取消 提交回答
  • select months 月份,type1+type2+type3 总数
    ,case when type1>0 then 1 else 0 then 执照1
    ,case when type2>0 then 1 else 0 then 执照2
    ,case when type3>0 then 1 else 0 then 执照3
    from(
    select yeas,months
    ,case when licenseType=1 then counts else 0 end type1
    ,case when licenseType=2 then counts else 0 end type2
    ,case when licenseType=3 then counts else 0 end type3
    from 表
    ) a

    2019-07-17 19:41:21
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
2022 DTCC-阿里云一站式数据库上云最佳实践 立即下载
云时代的数据库技术趋势 立即下载
超大型金融机构国产数据库全面迁移成功实践 立即下载