如何在 SQL 中制作多个 `OR` 和 `AND`
How to make multiple `OR` and `AND` in SQL
我一直在尝试从 MySQL 数据库中检索数据。以下查询没有产生任何结果:
SELECT *
FROM ENTITY_RELATIONSHIPS_TABLE
WHERE ((SUBJECT_GUID = ? AND TARGET_GUID = ?)
OR (TARGET_GUID = ? AND SUBJECT_GUID = ?))
AND RELATIONSHIP_TYPE_VALUE_ID IN (?)
删除 ((SUBJECT_GUID = ? AND TARGET_GUID = ?) OR (TARGET_GUID = ? AND SUBJECT_GUID = ?))
使查询工作意味着它是错误的部分。
这个有效:
SELECT *
FROM ENTITY_RELATIONSHIPS_TABLE
WHERE RELATIONSHIP_TYPE_VALUE_ID IN (?)
这是我附加准备好的数据值的方式:
let todo = [
relGUIDs[0], relGUIDs[1],
relGUIDs[1], relGUIDs[0],
]
for (let i = 0; i < relIdsArr.length; i++) todo.push(relIdsArr[i]);
我怎样才能使查询(如下)起作用?
SELECT *
FROM ENTITY_RELATIONSHIPS_TABLE
WHERE ((SUBJECT_GUID = ? AND TARGET_GUID = ?)
OR (TARGET_GUID = ? AND SUBJECT_GUID = ?))
AND RELATIONSHIP_TYPE_VALUE_ID IN (?)
提前谢谢大家。
(SUBJECT_GUID = ? AND TARGET_GUID = ?)
和 (TARGET_GUID = ? AND SUBJECT_GUID = ?)
是同一件事,因为您总是将 SUBJECT_GUID
与 relGUIDs[0]
以及 TARGET_GUID
与 relGUIDs[1]
进行比较,此外, todo
应该只有 5 个值,第五个值应该是一个数组。
我不确定您要做什么,但我认为您正在寻找这样的东西:
let todo = [
relGUIDs[0], relGUIDs[1],
relGUIDs[0], relGUIDs[1],
relIdsArr
]
我一直在尝试从 MySQL 数据库中检索数据。以下查询没有产生任何结果:
SELECT *
FROM ENTITY_RELATIONSHIPS_TABLE
WHERE ((SUBJECT_GUID = ? AND TARGET_GUID = ?)
OR (TARGET_GUID = ? AND SUBJECT_GUID = ?))
AND RELATIONSHIP_TYPE_VALUE_ID IN (?)
删除 ((SUBJECT_GUID = ? AND TARGET_GUID = ?) OR (TARGET_GUID = ? AND SUBJECT_GUID = ?))
使查询工作意味着它是错误的部分。
这个有效:
SELECT *
FROM ENTITY_RELATIONSHIPS_TABLE
WHERE RELATIONSHIP_TYPE_VALUE_ID IN (?)
这是我附加准备好的数据值的方式:
let todo = [
relGUIDs[0], relGUIDs[1],
relGUIDs[1], relGUIDs[0],
]
for (let i = 0; i < relIdsArr.length; i++) todo.push(relIdsArr[i]);
我怎样才能使查询(如下)起作用?
SELECT *
FROM ENTITY_RELATIONSHIPS_TABLE
WHERE ((SUBJECT_GUID = ? AND TARGET_GUID = ?)
OR (TARGET_GUID = ? AND SUBJECT_GUID = ?))
AND RELATIONSHIP_TYPE_VALUE_ID IN (?)
提前谢谢大家。
(SUBJECT_GUID = ? AND TARGET_GUID = ?)
和 (TARGET_GUID = ? AND SUBJECT_GUID = ?)
是同一件事,因为您总是将 SUBJECT_GUID
与 relGUIDs[0]
以及 TARGET_GUID
与 relGUIDs[1]
进行比较,此外, todo
应该只有 5 个值,第五个值应该是一个数组。
我不确定您要做什么,但我认为您正在寻找这样的东西:
let todo = [
relGUIDs[0], relGUIDs[1],
relGUIDs[0], relGUIDs[1],
relIdsArr
]