Search code examples
sqlhiveaggregate-functionshuebigdata

Average function on different columns in HIVE


I want to find the average of 3 columns using hive query. Consider the below data: Sample Data

I need to find the average marks scored by each student and then the average of total marks in each school: NULL should be ignored.

My output should look like this:

enter image description here

Can you guys help me out here


Solution

  • Hive should automatically ignore NULL values on aggregates as reported here.

    For readability, I suggest using COALESCE instead of IF IS NULL statements such as: COALESCE(Math,0) as Math