免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 44753 | 回复: 0
打印 上一主题 下一主题

union all语句简化问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-07-26 16:59 |显示全部楼层 |倒序浏览
求大神支招,下面的多个union all语句如何简化?
里面查询的是从201205到201607的日志表数据

with tb as(
select * from AOP_STAT_INVOKED_LOG_201205 t1 where t1.app_id=-1 and t1.ability_id<>-1 union all   
select * from AOP_STAT_INVOKED_LOG_201206 t2 where t2.app_id=-1 and t2.ability_id<>-1 union all
select * from AOP_STAT_INVOKED_LOG_201207 t3 where t3.app_id=-1 and t3.ability_id<>-1 union all
select * from AOP_STAT_INVOKED_LOG_201208 t1 where t1.app_id=-1 and t1.ability_id<>-1 union all   
select * from AOP_STAT_INVOKED_LOG_201209 t2 where t2.app_id=-1 and t2.ability_id<>-1 union all
select * from AOP_STAT_INVOKED_LOG_201210 t3 where t3.app_id=-1 and t3.ability_id<>-1 union all
select * from AOP_STAT_INVOKED_LOG_201211 t1 where t1.app_id=-1 and t1.ability_id<>-1 union all   
select * from AOP_STAT_INVOKED_LOG_201212 t2 where t2.app_id=-1 and t2.ability_id<>-1 union all
...
select * from AOP_STAT_INVOKED_LOG_201607 t3 where t3.app_id=-1 and t3.ability_id<>-1 )  
select tb.ability_id,tc.ability_name,sum(tb.invoked_nums) from tb,aop_ability_baseinfo tc where tb.ability_id=tc.ability_id group by tb.ability_id,tc.ability_name order by 3 desc;  
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP