17,377
社区成员
发帖
与我相关
我的任务
分享
--采用并行查询:
SELECT Sum(
CASE WHEN (sysdate-birthday)/365>=0 and (sysdate-birthday)/365<=25 THEN 1
WHEN (sysdate-birthday)/365>=26 and (sysdate-birthday)/365<=35 THEN 1
WHEN (sysdate-birthday)/365>=36 and (sysdate-birthday)/365<=45 THEN 1
WHEN (sysdate-birthday)/365>=46 and (sysdate-birthday)/365<=55 THEN 1
WHEN (sysdate-birthday)/365>=56 and (sysdate-birthday)/365<=59 THEN 1
WHEN (sysdate-birthday)/365>=60 THEN 1
END) as count,
CASE WHEN (sysdate-birthday)/365>=0 and (sysdate-birthday)/365<=25 THEN '25岁及以下'
WHEN (sysdate-birthday)/365>=26 and (sysdate-birthday)/365<=35 THEN '26到35岁'
WHEN (sysdate-birthday)/365>=36 and (sysdate-birthday)/365<=45 THEN '36到45岁'
WHEN (sysdate-birthday)/365>=46 and (sysdate-birthday)/365<=55 THEN '46到54岁'
WHEN (sysdate-birthday)/365>=56 and (sysdate-birthday)/365<=59 THEN '55到59岁'
WHEN (sysdate-birthday)/365>=60 THEN '60岁以上'
END as tab
from MV_UT_MEMBER
where INSTR(BELONGDZB,'001.001.032.092')>0
GROUP BY (
CASE WHEN (sysdate-birthday)/365>=0 and (sysdate-birthday)/365<=25 THEN '25岁及以下'
WHEN (sysdate-birthday)/365>=26 and (sysdate-birthday)/365<=35 THEN '26到35岁'
WHEN (sysdate-birthday)/365>=36 and (sysdate-birthday)/365<=45 THEN '36到45岁'
WHEN (sysdate-birthday)/365>=46 and (sysdate-birthday)/365<=55 THEN '46到54岁'
WHEN (sysdate-birthday)/365>=56 and (sysdate-birthday)/365<=59 THEN '55到59岁'
WHEN (sysdate-birthday)/365>=60 THEN '60岁以上'
END )
select
case when (sysdate-birthday)/365>=0 and (sysdate-birthday)/365<=25 then '25岁及以下'
when (sysdate-birthday)/365>=26 and (sysdate-birthday)/365<=35 then '26到35岁'
when (sysdate-birthday)/365>=36 and (sysdate-birthday)/365<=45 then '36到45岁'
when (sysdate-birthday)/365>=46 and (sysdate-birthday)/365<=55 then '46到54岁'
when (sysdate-birthday)/365>=56 and (sysdate-birthday)/365<=59 then '55到59岁'
when (sysdate-birthday)/365>=60 then '60岁以上' end,
count(1) as cnt
from MV_UT_MEMBER
where INSTR(BELONGDZB,'001.001.032.092')>0
group by case when (sysdate-birthday)/365>=0 and (sysdate-birthday)/365<=25 then '25岁及以下'
when (sysdate-birthday)/365>=26 and (sysdate-birthday)/365<=35 then '26到35岁'
when (sysdate-birthday)/365>=36 and (sysdate-birthday)/365<=45 then '36到45岁'
when (sysdate-birthday)/365>=46 and (sysdate-birthday)/365<=55 then '46到54岁'
when (sysdate-birthday)/365>=56 and (sysdate-birthday)/365<=59 then '55到59岁'
when (sysdate-birthday)/365>=60 then '60岁以上' end
----INSTR(BELONGDZB,'001.001.032.092') 建个函数索引
---我的 你试试
select
case when (sysdate-birthday)/365>=0 and (sysdate-birthday)/365<=25 then '25岁及以下'
when (sysdate-birthday)/365>=26 and (sysdate-birthday)/365<=35 then '26到35岁'
when (sysdate-birthday)/365>=36 and (sysdate-birthday)/365<=45 then '36到45岁'
when (sysdate-birthday)/365>=46 and (sysdate-birthday)/365<=55 then '46到54岁'
when (sysdate-birthday)/365>=56 and (sysdate-birthday)/365<=59 then '55到59岁'
when (sysdate-birthday)/365>=60 then '60岁以上' end,
count(1) as cnt
from MV_UT_MEMBER
where INSTR(BELONGDZB,'001.001.032.092')>0
---你的 把union 改成union all
select '25岁及以下' as tab,count(1) as cnt from MV_UT_MEMBER
where (sysdate-birthday)/365>=0 and (sysdate-birthday)/365<=25 and INSTR(BELONGDZB,'001.001.032.092')>0
union all
select '26到35岁' as tab,count(1) as cnt from MV_UT_MEMBER where (sysdate-birthday)/365>=26 and (sysdate-birthday)/365<=35 and INSTR(BELONGDZB,'001.001.032.092')>0
union all
select '36到45岁' as tab,count(1) as cnt from MV_UT_MEMBER where (sysdate-birthday)/365>=36 and (sysdate-birthday)/365<=45 and INSTR(BELONGDZB,'001.001.032.092')>0
union all
select '46到54岁' as tab,count(1) as cnt from MV_UT_MEMBER where (sysdate-birthday)/365>=46 and (sysdate-birthday)/365<=55 and INSTR(BELONGDZB,'001.001.032.092')>0
union all
select '55到59岁' as tab,count(1) as cnt from MV_UT_MEMBER where (sysdate-birthday)/365>=56 and (sysdate-birthday)/365<=59 and INSTR(BELONGDZB,'001.001.032.092')>0
union all
select '60岁以上' as tab,count(1) as cnt from MV_UT_MEMBER
where (sysdate-birthday)/365>=60 and INSTR(BELONGDZB,'001.001.032.092')>0