我有以下代码
select count(*)
from (select Annotations.user_id
from Annotations, Users
where Users.gender = 'Female'
and Users.user_id = Annotations.user_id
and image_id = 1
group by Annotations.user_id
having sum(case when stem = 'taxi' then 1 else 0 end) > 0 and
sum(case when stem = 'zebra crossing' then 1 else 0 end) > 0
) Annotations
它会计算有多少女性给了图像 1 的茎“出租车”和“斑马线”。
样本数据
user id, image id, stem
1 1 image
1 1 taxi
1 1 zebra crossing
2 1 person
2 1 zebra crossing
2 1 taxi
3 1 person
3 1 zebra crossing
预期结果(或类似)
stem1, stem2, count
taxi , zebra crossing 2
person, zebra crossing 2
但是,由于有 2000 多个词干,我无法全部指定。
我将如何使用 image_id = 1 和性别 = 女性而不是指定词干字符串来遍历词干行?
谢谢