Summation and average sql table in java

1

I'm trying to get problems with something I think even simple, but I do not know which command I should run to do this.

Well let's go there: I have a table (let's call it FILMES) ... and this table has 3 columns.

What I need:

I need to add all the values in column 2 of this FILMES table and divide by the total number of values. That is, suppose my second column has 3 values: 2, 3 and 4.

I need to add these 3 values and then divide by 3.

It looks like this: (2 + 3 + 4) / 3.

I even know how to get the sum with the cursor in count. But, I do not know how to retrieve the sum (use SUM) as a value that I might be dividing by the total of numbers.

In short, you would need to add only the items in column 2, whose value in column 3 is 0. But I can see that later, if you help me recover the sum of the columns so that I can divide by the total would already be great help.

    
asked by anonymous 12.07.2016 / 03:53

1 answer

0

It's simple enough to do a projection, in code already with the criterion of the third column to be greater than 0 looks like this:

select 
  SUM(nome_coluna2) / COUNT(*)
from 
  Filmes
where
  nome_coluna3 = 0;

Any doubts can comment on the answer that I clarify.

    
12.07.2016 / 04:09