Title: Type-casting issue
Tags: sqlite
Question: In the following query, the answer of 1/2 is always zero while it should be 0.5. Can you please tell me how to convert the two int columns into float/double?
SELECT 1/2, total, sb_ondate, likes
FROM (
SELECT sb_ondate, COUNT(*) AS total,
STRFTIME("%w",sb_ondate) AS weekDay,
COUNT(CASE WHEN sb_reaction = 'like' THEN sb_id END) AS likes
FROM diet
GROUP BY weekDay) AS f;
Thanks.

Here is the accepted answer: Cast one of the two divisors as a real:
SELECT 1 / CAST(2 AS REAL),...
Sample interactive Python session:
&gt;&gt;&gt; import sqlite3
&gt;&gt;&gt; c = sqlite3.connect(':memory:')
&gt;&gt;&gt; c.execute("create table t (a int,b int);")
<sqlite3.Cursor object at 0x7f9b0e9539d0&gt;
&gt;&gt;&gt; c.execute("insert into t values (1,2)")
<sqlite3.Cursor object at 0x7f9b0e953ad8&gt;
&gt;&gt;&gt; conn.execute("select a / cast(b as real) from t").fetchone()
(0.5,)
Comment for this answer: Why _unfortunately_? Embrace that Y chromosome, my friend ;D
Comment for this answer: Unfortunately, I am a "SIR" LOL

Here is another answer: Add .0 to one of the constants:
sqlite&gt; select 1/2;
----------
sqlite&gt; select 1.0/2;
----------

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2011:00:05/22/11', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<sqlite>', 'Title': 'Type-casting issue', 'ViewCount': 13449, 'id': 6085424, 'user_AboutMe': '<p><strong>A developer and a wannabe entrepreneur.</strong></p>\n<p>More than <strong>10 years</strong> of development experience on different platforms; Windows,Linux, Mac,Desktop/Web/Mobile. You can read further about me on my <a href="http://adnansiddiqi.me" rel="nofollow noreferrer">home site</a></p>\n', 'user_AccountId': 102447.0, 'user_DisplayName': 'Volatil3', 'user_Reputation': 13322.0, 'user_Views': 2427.0, 'user_id': 275002.0}}