I have a query which returns the results
time t_count cumulative_t_count zone hour
_____ _____ _________________ ____ ____
1 10 10 1 1
2 20 30 1 1
3 30 60 1 1
4 60 120 1 1
My query will be like
select time,t_count,sum(t_count) over (order by time) as
cumulative_t_count ,zone,hour from (select distinct
time,count(distinct num_id) as t_count,zone,hour from (select * from
public.table1 where day=1 and time>0 order by time)as A group by
time,hour,zone order by hour,zone )B where zone=1 and hour=1;
Now I want an additional column which shows the percentage of cumulative count like this
time t_count cumulative_t_count zone hour percentage_cumulative count
_____ _____ _________________ ____ ____ ____________________________
1 10 10 1 1 10%
2 20 30 1 1 30%
3 30 60 1 1 60%
4 40 100 1 1 100%
I tried with
select time,t_count,sum(t_count) over (order by time) as
cumulative_t_count ,cumulative_t_count/sum(t_count) as percentage_cumulative count,zone,hour from (select distinct
time,count(distinct num_id) as t_count,zone,hour from (select * from
public.table1 where day=1 and time>0 order by time)as A group by
time,hour,zone order by hour,zone )B where zone=1 and hour=1;
But it did not work.Any help is appreciated.
In order to calculate the percentage of cumulative count each row contributes to the total cumulative count, you should run another SQL on your result set and calculate percentage for each row.
I believe query should answer the question you're asking for.