gpt4 book ai didi

MySQL 不排除其他查询的查询结果

转载 作者:行者123 更新时间:2023-11-29 22:26:02 25 4
gpt4 key购买 nike

我有一个实验数据库,并尝试获取除参与某一特定实验的参与者之外的所有希望重新联系的参与者。该查询有效,只是它不包括仅参加此实验的参与者,但包括参加该实验和其他实验的参与者。请原谅我的马虎代码!

SELECT DISTINCT t1.`par_name`, t1.`email`, t1.`comment`
FROM `par` AS t1, `exp` AS t2, `pie` AS t3
WHERE t1.`par_id` = t3.`par_id` AND t3.`exp_id` = t2.`exp_id` AND
t1.`ReContact`!= 'N' AND t1.`email`!= " " AND t1.`MotherTounge`
= 'Deu' OR t1.`MotherTounge` = '' AND t1.`age` BETWEEN 18 AND 35

AND t1.`par_name` NOT IN(SELECT t1.`par_name`
FROM `par` AS t1, `exp` AS t2, `pie` AS t3
WHERE t1.`par_id` = t3.`par_id` AND
t3.`exp_id` = t2.`exp_id` AND t3.`exp_id` = '15ET001')
GROUP BY `par_name`;

最佳答案

我不是 100%,但我认为你需要附上一些连接

SELECT DISTINCT t1.`par_name`, t1.`email`, t1.`comment`
FROM `par` AS t1, `exp` AS t2, `pie` AS t3
WHERE (t1.`par_id` = t3.`par_id`) AND (t3.`exp_id` = t2.`exp_id`) AND
(t1.`ReContact`!= 'N') AND (t1.`email`!= " ") AND
// here is the change
(t1.`MotherTounge` = 'Deu' OR t1.`MotherTounge` = '') AND (t1.`age` BETWEEN 18 AND 35)

AND t1.`par_name` NOT IN(SELECT t1.`par_name`
FROM `par` AS t1, `exp` AS t2, `pie` AS t3
WHERE t1.`par_id` = t3.`par_id` AND
t3.`exp_id` = t2.`exp_id` AND t3.`exp_id` = '15ET001')
GROUP BY `par_name`;

由于您有一个 OR ,因此您需要将其用 () 括起来。

尝试一下!

关于MySQL 不排除其他查询的查询结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30259841/

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