gpt4 book ai didi

MySQL 保留 JOIN 超过 3 个表,并使用不允许的用户 ID 策略

转载 作者:行者123 更新时间:2023-11-30 00:55:12 24 4
gpt4 key购买 nike

我有 3 个表,应该与左连接结合使用,到目前为止还可以。但现在我只想要一些信息,例如只有性别是男性,那也没关系。还显示性别为空的所有行,也可以。但现在我只想显示允许的行。在例如之前澄清谁被允许。不要显示 ID 为 1 的行。这就是问题所在。例如

table1 
id | tab2_id | gender_id | bla

table2
id | name | bla | blub

table3
id | tabl_id | gender_id | allowed
1 | 1 | 1 | 1
2 | 2 | 1 | 2

到目前为止的查询:

Select table1. gender_id, table1.bla, table2.name, table2.bla 
From table1
Left Join table2 ON table1.tab2_id = table2.id
LEFT Join table3 on table1.tab2_id = table3.tab1_id
Where table1.gender_id = '1'
OR table1.gender_id IS NULL
AND table3.allowed <> 1

我希望这只是一个例子。主要问题是允许的问题。我可以选择性别 1 的所有行,但我不想选择 Pollicy Table3 中某些用户不允许的这些行

最佳答案

试试这个方法

SELECT table1.gender_id, table1.bla, table2.name, table2.bla 
FROM table1 LEFT JOIN table2
ON table1.tab2_id = table2.id LEFT JOIN table3
ON table1.tab2_id = table3.tab1_id
AND table3.allowed <> 1
WHERE table1.gender_id = 1
OR table1.gender_id IS NULL

关于MySQL 保留 JOIN 超过 3 个表,并使用不允许的用户 ID 策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20631449/

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