sql - I need to build multitable sqlite query
问题描述
I really can't find a way to build the right request. That's my database design:
I need to find the number of albums that the user tagged in when my input is USER_ID. for example:
user Keni with ID 203 tagged in pictures with id 101, 103, 104 all these pictures located in different albums, so if i have the id 203, my output should be 3.
解决方案
You can try this:
SELECT COUNT(DISTINCT ALBUM_ID) FROM PICTURES WHERE ID IN (SELECT PICTURE_ID FROM TAGS WHERE USER_ID = 201);
replace the 201 with the desired ID.
推荐阅读
- parquet - 如何使用 Pyarrow 更改镶木地板文件中列的名称?
- python - 使用 Sanic 和 Redis 时遇到问题
- java - 二叉树的垂直顺序遍历中具有相同垂直高度的相同级别元素的问题
- objective-c - 如何翻转两个视图Objective C iOS 13
- c# - 如果文件类型没有关联程序,如何使用 Process.Start 打开文件?
- if-statement - 什么是可以通过参考当前时间来计算约会时间是否超过两个小时的工作公式
- javascript - 删除最多一个字符的所有文本
- javascript - 有没有办法上传、重命名,然后下载 HTML 文件?
- javascript - 如何访问多个上传文件中第一个的值
- arrays - 从 PS 运行 sql 查询,并在 where 子句中循环输入条件