您好我正在使用 Oracle SQL Developer 并试图在我的表上获取百分比。
我当前的查询是:
select
decode(grouping(life), 1, 'Total', life) as "LifeName",
sum(case
when task is not null and to_char(datee, 'MM') = '08'
and to_char(datee, 'YYYY') = '2013'
then 1
else 0
end) as "MonthStatus"
from life_lk, task_c
where life_lk.life_id = task_c.life_id
group by rollup(life)
我得到的当前输出是:
LifeName MonthStatus
dog 5
bear 20
cat 1
Fish 4
Total 30
但是,我希望输出为:
LifeName MonthStatus Percent
dog 5 16
bear 20 66
cat 1 3
Fish 4 13
Total 30 100
因此,对于月份状态下的每个单元格,我希望将数字除以在本例中为 30 的总数。该数字将随时间动态变化,因此我不能简单地除以 30。
对不起,看起来邋遢的桌子。我不知道如何让它们看起来整齐排列。
谢谢您的帮助