17,089
社区成员
发帖
与我相关
我的任务
分享
with tmp as (
select 'A' id , '类型1' name from dual union all
select 'B', '类型2' from dual union all
select 'C','类型3' from dual
),
t2 as
(select 'A' id,'1001' gid,100 total from dual union all
select 'A','1002',200 from dual union all
select 'A','1003',300 from dual union all
select 'B','2001',400 from dual union all
select 'B','2002',500 from dual union all
select 'B','2003',600 from dual union all
select 'C','3001',700 from dual union all
select 'C','3002',800 from dual union all
select 'C','3003',900 from dual)
SELECT ID, ROUND(WEIGHT) || '%', ROUND(SUM(WEIGHT) OVER(ORDER BY ID)) || '%'
FROM (SELECT ID, TOTAL / SUM(TOTAL) OVER() * 100 AS WEIGHT
FROM (SELECT A.ID, SUM(B.TOTAL) AS TOTAL
FROM TMP A
LEFT JOIN T2 B
ON A.ID = B.ID
GROUP BY A.ID))