converting int to real in sqlite

vaichidrewar picture vaichidrewar · Nov 29, 2011 · Viewed 62.9k times · Source

Division in sqlite return integer value

sqlite> select totalUsers/totalBids from 
(select (select count(*) from Bids) as totalBids , 
(select count(*) from Users) as totalUsers) A;
1

Can we typecast the result to get the real value of division result?

Answer

NullUserException picture NullUserException · Nov 29, 2011

Just multiply one of the numbers by 1.0:

SELECT something*1.0/total FROM somewhere

That will give you floating point division instead of integer division.