如何在sql中生成多个“or”和“and”

cqoc49vn  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(650)

我一直在尝试从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 (?)

提前谢谢大家。

vtwuwzda

vtwuwzda1#

(SUBJECT_GUID = ? AND TARGET_GUID = ?) 以及 (TARGET_GUID = ? AND SUBJECT_GUID = ?) 因为你总是比较 SUBJECT_GUIDrelGUIDs[0] 以及 TARGET_GUIDrelGUIDs[1] ,还有, todo 应该只有5个值,第五个值应该是数组。
我不知道你想做什么,但我想你在找这样的东西:

let todo = [
    relGUIDs[0], relGUIDs[1],
    relGUIDs[0], relGUIDs[1],
    relIdsArr
]

相关问题