我需要从表中获取所有行中的所有行,其中所有行中的question_id <> target
和question_type <> target_type
例如
+----+-------------+---------------+-------------+--------+-------+
| id | question_id | question_type | target_type | target | start |
+----+-------------+---------------+-------------+--------+-------+
| 1 | 3 | 0 | 2 | 1 | 1 |
| 3 | 1 | 1 | 2 | 3 | 0 |
| 5 | 3 | 0 | 1 | 3 | 0 |
+----+-------------+---------------+-------------+--------+-------+
我的结果应该是ID为3的第二行
+----+-------------+---------------+-------------+--------+-------+
| id | question_id | question_type | target_type | target | start |
+----+-------------+---------------+-------------+--------+-------+
| 3 | 1 | 1 | 2 | 3 | 0 |
我需要在第一行中同时使用question_id
和question_type
并将它们与所有行中的target
和target_type
进行比较
当question_id
和question_type
不等于target
且target_type where start = 1
和question_id
和question_type when start = 1
不出现在结果中时,获得行< / p>
因为我的第1行有start = 1
,并且它的question_id = 3
和question_type = 0
是,所以我想排除任何带有(question_id = 3
和question_type = 0
)的行根据我的结果
第2行:question_id = 1
和question_type = 1
在所有行中都不等于target
和target_type
这是我尝试过的:
SELECT s.*
FROM assign s
JOIN assign l1
ON s.question_id <> l1.target
JOIN assign l2
ON s.question_type <> l2.target_type
和
SELECT *
FROM assign`
WHERE (question_id NOT IN (SELECT target from assign) )
AND question_type <> target_type
AND scenario_id = 3
AND start = 0
预先感谢