In SQLite, division of two integers returns an integer value. This can be an issue when you need to obtain a real-valued result.
Example:
Consider the following query:
SELECT totalUsers/totalBids FROM (SELECT (SELECT COUNT(*) FROM Bids) AS totalBids, (SELECT COUNT(*) FROM Users) AS totalUsers) A;
This query returns 1 as the division result, which is an integer.
Solution:
To obtain a real-valued result, you can explicitly cast one of the numbers to a real number. This can be done by multiplying it by 1.0.
Modified Query:
SELECT something*1.0/total FROM somewhere
This modification ensures that the division operation returns a floating-point result.
The above is the detailed content of How to Get a Real-Valued Result from Integer Division in SQLite?. For more information, please follow other related articles on the PHP Chinese website!