SQLite:计算问题的参与者
SQLite: Count participants of questions
我有 3 个 table。我目前 运行 以下查询不起作用。
SELECT
a._id,
a.title,
COUNT(DISTINCT user_id)
AS
number_of_participants
FROM
a, b, c
WHERE
a._id=b.fk AND
b._id=c.fk
字段user_id只存在于table c.
说明我想要什么:Table a 包含问题,而 table b 包含问题的参考 fk 的答案。我想统计有多少用户已经为每个问题投票。所以 table c 持有选票。
编辑:
我的数据库方案:
Table a:
_id integer,
title text
Table b:
_id integer,
title text,
fk integer references a._id
Table c:
user_id text,
name text,
fk integer references b._id
自己找到解决方法:
我必须添加
group by a.title
编辑:
为了也支持没有参与者的问题,我不得不将其更改为双 LEFT OUTER JOIN。
我有 3 个 table。我目前 运行 以下查询不起作用。
SELECT
a._id,
a.title,
COUNT(DISTINCT user_id)
AS
number_of_participants
FROM
a, b, c
WHERE
a._id=b.fk AND
b._id=c.fk
字段user_id只存在于table c.
说明我想要什么:Table a 包含问题,而 table b 包含问题的参考 fk 的答案。我想统计有多少用户已经为每个问题投票。所以 table c 持有选票。
编辑: 我的数据库方案:
Table a:
_id integer,
title text
Table b:
_id integer,
title text,
fk integer references a._id
Table c:
user_id text,
name text,
fk integer references b._id
自己找到解决方法:
我必须添加
group by a.title
编辑:
为了也支持没有参与者的问题,我不得不将其更改为双 LEFT OUTER JOIN。