gpt4 book ai didi

ios - sqlite 加入查询 iPad

转载 作者:行者123 更新时间:2023-11-30 13:03:22 26 4
gpt4 key购买 nike

我有三张 table

Personal_video
+------------------------------+
|presonal_video_id | title |
----------------------------
1 | test1|
2 | test2|
3 | test3|
4 | test4|

personal_video_tags
+------------------------------+
|tag_id | tag_title |
----------------------------
1 | august|
2 | 2016 |
3 | 2015 |
4 | 2014 |


personal_video_tag_mapping
+------------------------------+
|tag_id | presonal_video_id |
----------------------------
1 | 1 |
2 | 2 |
3 | 3 |
4 | 1 |

现在我想编写一个查询,该查询将根据常见标签返回视频,例如如果用户选择标签“8 月”和“2014 年”,则查询应返回连接到这两个标签的视频。

目前我的查询是

 SELECT presonal_video_id,title 
FROM personal_video
WHERE presonal_video_id IN
(
SELECT personal_video_id AS PID
FROM personal_video_tag_mapping
WHERE tag_id IN ("1","2") AND privacy_level != 2
GROUP BY personal_video_id
HAVING COUNT( PID ) > 1
)

它给了我写入结果,但是当数据很大时,需要很长时间。有人可以告诉我编写此查询的正确方法

提前谢谢您

最佳答案

尝试这个查询:

SELECT t1.presonal_video_id, t1.title 
FROM personal_video AS t1
JOIN personal_video_tag_mapping AS t2
ON t1.presonal_video_id = t2.presonal_video_id
JOIN personal_video_tags AS t3
ON t2.tag_id = t3.tag_id
WHERE t3.tag_title IN ('august', '2014')
GROUP BY t1.presonal_video_id, t1.title
HAVING COUNT(*) = 2

关于ios - sqlite 加入查询 iPad,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39653576/

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