sql - Getting non-integer results in Data Explorer -


the stack exchange data explorer allows sql queries against stack exchange database. following query

select   month(creationdate) month,   year(creationdate) year,   sum(case when lower(left(title,2))='wh' 1 else 0 end)/count(*) wh,   (select sum(score)/count(*)    posts u         month(creationdate)=month(t.creationdate) ,      year(creationdate)=year(t.creationdate) ,      lower(left(title,2))='wh' ,      posttypeid=1 -- question   ) wh_score,   sum(score)/count(*) score,   (select sum(answercount)/count(*)    posts u         month(creationdate)=month(t.creationdate) ,      year(creationdate)=year(t.creationdate) ,      lower(left(title,2))='wh' ,      posttypeid=1 -- question   ) wh_answers,   sum(answercount)/count(*) answers posts t posttypeid=1 -- question group month(creationdate), year(creationdate) ; 

courtesy of scorpi0 — yields integer values in results: gets either rounded or truncated (i don't know which). (this annoying in wh column, every value therefore 0.) there way force decimal or values?

like lot of langage, when 1/2, perform division of 1 2 , return quotient, 0 here.

n/m => n = m * q + r 1/2 => 1 = 2 * 0 + 1 

let's pragmatic : multiply decimal, :

(sum(answercount) * 1.0)/count(*) 

and decimal instead of int.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -