Oracle sql query : implementing an equation into a select group by -
i have following weighted average equation i'm trying put select clause
(( operating_hrsa * component counta ) + ( operating_hrsc * component countb ) + ( operating_hrsc * component countc )) / total compont_countabc
the select i'm trying put is:
select reporting_date_from, reporting_date_to, b_name, oflag, component_type, sum (component_count) component_count, --avg (average_operating_hours) average_operating_hours, sum((average_operating_hours * component_count) / sum(component_count)) average_operating_hours device reporting_date_from = '01-jan-2017' , b_name '430%' group reporting_date_from, reporting_date_to, b_name, oflag, component_type; error i'm getting :
error @ line 1 ora-00937: not single-group group function
table schema : column | data type | null ? reporting_date_from date n reporting_date_to date n b_name varchar2(100 byte) y oflag varchar2(50 byte) y component_type varchar2(50 byte) y average_operating_hours number y
you use subselect result , perform calculation implies nested sum eg:
select reporting_date_from, reporting_date_to, b_name, oflag, component_type, component_count, average_operating_hours, my_value/component_count average_operating_hours from( select reporting_date_from, reporting_date_to, b_name, oflag, component_type, sum (component_count) component_count, avg (average_operating_hours) average_operating_hours, sum((average_operating_hours * component_count) ) my_value, device reporting_date_from = '01-jan-2017' , b_name '430%' group reporting_date_from, reporting_date_to, b_name, oflag, component_type ) t ; 
Comments
Post a Comment