D
D
des1roer2015-01-26 13:32:50
PostgreSQL
des1roer, 2015-01-26 13:32:50

PostgreSQL average per row?

maybe the question is simple, but Google is desperately trying to send me to find the average by column, but I need by row.

SELECT 
                "FH_09_Q" ,								
                "FH_10_Q" ,								
                "FH_11_Q" ,
              ("FH_09_Q" + "FH_10_Q" + "FH_11_Q"),
                ("FH_09_Q" + "FH_10_Q"+ "FH_11_Q")/3		
                FROM 
                "SC_Wonder"."TMining_New" 
                where "FMineObj_ID" = 16
                and "FDate" ='2015-01-26'

in general there is a line with the data. how to find the sum and average, provided that there are empty fields7
-----------
UPD
#
SELECT 
            "FH_09_Q" ,                             
            "FH_10_Q" ,                             
            "FH_11_Q" ,
        (COALESCE("FH_09_Q",0) + COALESCE("FH_10_Q",0) + COALESCE("FH_11_Q",0)) as sum,
            (COALESCE("FH_09_Q",0) + COALESCE("FH_10_Q",0) + COALESCE("FH_11_Q",0))/3 as avg
       
            FROM 
            "SC_Wonder"."TMining_New" 
            where "FMineObj_ID" = 16
            and "FDate" ='2015-01-26'

8rm8fBK.png
but in this case, how to find out the number of non-empty fields?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Y
yttrium, 2015-01-26
@yttrium

use COALESCE www.postgresql.org/docs/9.4/static/functions-condi...

A
Armenian Radio, 2015-01-26
@gbg

You have serious architectural problems if you have built such a nightmare. This should be in a column of the attached table, not in 9000 columns.

S
Swartalf, 2015-01-26
@Swartalf

Use procedures. PL/pgSQL or whatever.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question