Skip to content
Advertisement

Hana SQL Logic needed

select  groupid,count(value) as x
from test_distinct_count
group by rollup (groupid);

This query gives output like :

enter image description here

What i need is to display the value 5 for all the groupids in a column say Total. Something like this :

enter image description here

how can this be achieved using Hana Sql.

Advertisement

Answer

Am from sql server background hope sum() over() will exist in Hana, try the below solution

create table #temp(groupid int,value int)

insert into #temp values(1,1)
insert into #temp values(1,1)
insert into #temp values(1,1)
insert into #temp values(2,2)
insert into #temp values(2,2)

select 
a.*,sum(x) over()/2 as Total
from (
select  groupid,count(value) as x
from #temp
group by rollup (groupid)
)a
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement