【发布时间】:2023-03-17 01:50:02
【问题描述】:
我有以下代码
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 和性别 = 女性的词干行?
谢谢
【问题讨论】:
-
能否请您发布您的示例数据和预期结果?
-
stem属于哪个表? -
@PM77-1 77-1 为样本数据编辑,词干属于注释表
-
您需要计数任意两个的茎吗?我做对了吗?
-
@PM77-1 是的,任何 2 个词干的计数。因此,如果我有另一个用户 id 4 的条目,带有 image/tax,那么计数将为 2,因为用户 id 1 也有这些词干
标签: mysql sql database loops rows