gpt4 book ai didi

mysql - 如何加入 ON IN ALL 关系

转载 作者:行者123 更新时间:2023-11-29 07:08:01 25 4
gpt4 key购买 nike

标签表

| id | label |
| 1 | test1 |
| 2 | test2 |
| 3 | test3 |

图像表

| id |  data |
| 1 | data1 |
| 2 | data2 |
| 3 | data3 |

映射表

| id | tagId | imageId |
| 1 | 1 | 1 |
| 2 | 1 | 2 |
| 3 | 2 | 2 |
| 4 | 3 | 2 |
| 5 | 3 | 3 |

我正在尝试查找具有所有共同标签的图像 (image.id = 2)。

当提供标签 ID 1、2 和 3 时,如何查询?

(抱歉问题标题不好)

最佳答案

这是一种方法:

select m.imageId
from mapping m
where tagId in (1, 2, 3)
group by m.imageId
having count(*) = 3; -- needs to match the number of tags in the `where` clause

关于mysql - 如何加入 ON IN ALL 关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40898064/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com