在以下查询中,1/2的答案始终为零,而应为0.5.你能告诉我如何将两个int列转换为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;
谢谢.
将两个除数中的一个作为一个实数:
原文链接:https://www.f2er.com/sqlite/197728.htmlSELECT 1 / CAST(2 AS REAL),...
示例交互式Python会话:
>>> import sqlite3 >>> c = sqlite3.connect(':memory:') >>> c.execute("create table t (a int,b int);") <sqlite3.Cursor object at 0x7f9b0e9539d0> >>> c.execute("insert into t values (1,2)") <sqlite3.Cursor object at 0x7f9b0e953ad8> >>> conn.execute("select a / cast(b as real) from t").fetchone() (0.5,)