开发者社区 问答 正文

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

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

展开
收起
吴孟桥 2016-06-16 16:54:57 2280 分享 版权
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
    赞同 展开评论