Skip to Content
Former Member
Apr 08, 2012 at 02:44 PM

Statistics calculations in SQLScript



I have been working on SQLScript for a month or so and have been able to create reasonably complex queries. Now I have come across a scenario where I need to build a nested query that uses one of the aggregate fields calculated by the initial / outer query. So far HANA is refusing to activate the view, saying that MeanX is not a valid column name in the sub query. Please refer to the code attached. Any help would be very appreciated.

Side question: How do you declare a variable of type table in a procedure? It doesn't work like for non table types where we can just write ' temp integer' to declare an integer variable.

var_out = select kunnr "KUNNR",

AVG(cons) as meanx ,

AVG(events) as meany ,

( Select AVG(cons - meanx)*(events - meany) as cov

from "DATA_SLT_IDD800"."ZDATA" as B

where b.kunnr = a.kunnr


from "DATA_SLT_IDD800"."ZDATA" as A

group by kunnr