lundi 17 août 2015

SQLite get AVG(Column_name) returning Integer value. Need result in float

I have a column storing numeric values and i want the average of the column in decimal points.

Query i have used - 1) SELECT AVG(CAST((COL1) as FLOAT)) from TABLE_TEST - return int upto 1 place decimal, for eg - 7.0

2) SELECT CAST(AVG(COL1) AS DECIMAL(10,2)) from TABLE_TEST- again same result with one place of decimal.

3) ROUND(AVG(CAST(column_name AS FLOAT)), 2) from TABLE_TEST - again same result.

I am creating table like below -

String CREATE_RATINGS_TABLE = "CREATE TABLE " + TABLE_RATINGS + "("
            + _RID + " INTEGER PRIMARY KEY," + COL1 + " REAL"+ ")";

I have calculated result by SUM(COL1) and then dividing by total no. of records, the result yields in floating point number.

Is it the limitation of SQLlite AVG command to return INT values or Can I get floating result somehow ?

Aucun commentaire:

Enregistrer un commentaire