问题描述
我希望返回被请求用户(通过对users
的{{1}}值进行硬编码模拟)所组成的teams
成员的所有uid
。我正在尝试通过使用联接表user1
来实现这一点,但是只能以查询结束,而不是返回比我要找的东西还要多的东西。
在查询输出(查询#3)中,我希望不看到teams_members
,因为它们不是user3
或team1
(唯一的)的一部分team2
所属的团队。
设置:
user1
CREATE TABLE users (
uid INT,name TEXT
);
INSERT INTO users (uid,name) VALUES (1,"user1");
INSERT INTO users (uid,name) VALUES (2,"user2");
INSERT INTO users (uid,name) VALUES (3,"user3");
CREATE TABLE teams (
tuid INT,name TEXT
);
INSERT INTO teams (tuid,'team1');
INSERT INTO teams (tuid,'team2');
INSERT INTO teams (tuid,'team3');
CREATE TABLE teams_members (
uid INT,tuid INT,role TEXT
);
INSERT INTO teams_members (uid,tuid,role) VALUES (1,1,'owner');
INSERT INTO teams_members (uid,2,role) VALUES (2,role) VALUES (3,3,'owner');
我如何只退回# Get user
SELECT * FROM users WHERE uid = 1;
# Get teams the user is part of
SELECT t.tuid,t.name FROM teams t
LEFT JOIN teams_members tm ON t.tuid = tm.tuid
WHERE uid = 1;
# Get team members present for all teams <<<<<<< Query in question
SELECT u.uid,u.name FROM users u
LEFT JOIN teams_members tm ON u.uid = tm.uid
LEFT JOIN teams t ON tm.tuid = t.tuid
WHERE tm.uid = u.uid;
所属团队中的 users
?
解决方法
您的第二个查询就是您所需要的。用它来获取表用户的数据:
ffmpeg -i FullScreenVidio.mp4 -i PictureWindow.mp4 -filter_complex "[1]scale=iw/2.15:ih/2.15 [pip]; [0][pip] overlay=25:25" -profile:v main -level 3.1 -b:v 440k -ar 44100 -ab 128k -s 1920x1080 Result.mp4
=vf eq=brightness=0.25:contrast=1.5:saturation=1.5
这是演示:
,
如何只返回出现在user1所在团队中的用户?
一种方法使用exists
:
select u.*
from users u
where exists (select 1
from teams_members tm1 join
teams_members tm2
on tm1.tuid = tm2.tuid -- same team
where tm1.uid = 1 and -- team has user 1
tm2.uid = u.uid -- team has user in outer query
);