我的表格设置如下:
Parent
------
id, ...
Child
-----
id, parent_id, x, y
我想找到父母,或者不同的parent_id,如果allChild 中包含给定parent_id 的行满足涉及x 和y 的条件(在我的例子中x = y)。
例如:
Parent
------
id
1
2
3
Child
id, parent_id, x, y
1, 1, 2, 3
2, 1, 3, 4
3, 2, 5, 5
4, 2, 6, 7
5, 3, 8, 8
6, 3, 9, 9
将导致 3。目前,我有一个查询可以找到parent_idsany的孩子符合标准。然后,我用它来检索这些记录,并在代码中检查它们是否所有孩子都符合条件。通过示例数据,我获取了parent_id 2和3,获取了包含所有子项的两条父记录,并进行了评估。如果可能的话,我想通过单个查询来完成此操作。