How to convert a string type data to int (float) and get an average?

0

I have a query that gives me results of type string, that data is converted to an integer type (I clarify that I can also convert it to float) and then I want it to give me the averaged result about it.

I hope and you can help me.

this is the Query

select cedis,
           convert(int, (count(clientes_con_rechazo))) Totales
        from tmpcalculo
        group by cedis 

This is the result that currently throws me

cedis   Totales
Celaya  1437

Example of how I would throw it.

cedis   Totales
Celaya  10.45
    
asked by Ric_hc 03.05.2017 в 17:29
source

1 answer

0

Let's see if I understood what you want.

You have a table with two fields of type string. In the field customers_with_refree you have stored an integer value in string format. You want to take the average of the values of this field grouped by the value of the cedis field.

If so, and you want the result to come out with decimals, you should convert the value of the column to float and calculate the average with the AVG function grouping by the cedis field:

SELECT cedis, AVG(CONVERT(float, clientes_con_rechazo))
FROM tmpcalculo
GROUP BY cedis
    
answered by 03.05.2017 / 17:40
source