我有两个看起来像这样的数据库:
| idElement | idClient | idSubClient | idSport | idCategory | idTeam | idParent |
|-----------|----------|-------------|---------|------------|--------|----------|
| 1 | 1 | -1 | (null) | (null) | (null) | (null) |
| 2 | 1 | -1 | 30 | (null) | (null) | 1 |
| 3 | 1 | -1 | (null) | 100 | (null) | 2 |
| 4 | 1 | -1 | 31 | (null) | (null) | 1 |
| 5 | 1 | -1 | (null) | (null) | 150 | 3 |
| 6 | 1 | -1 | (null) | (null) | 151 | 3 |
| 7 | 1 | -1 | (null) | 101 | (null) | 4 |
| 8 | 1 | -1 | (null) | 101 | (null) | 2 |
| 9 | 1 | -1 | (null) | (null) | 152 | 7 |
| 10 | 1 | -1 | (null) | (null) | 153 | 7 |
| idRef | idElement | idUser |
|-------|-----------|--------|
| 1 | 1 | 2000 |
| 2 | 1 | 2001 |
| 3 | 1 | 2002 |
| 4 | 1 | 2003 |
| 5 | 2 | 2004 |
| 6 | 2 | 2005 |
| 7 | 3 | 2001 |
| 8 | 4 | 2003 |
| 9 | 9 | 2004 |
我想用 idUser、idClient、idSubclient 创建反向递归查询,如果元素的父级是运动则返回。
例如:
在我的情况下,具有 id 的 User2004
被分配给2
元素是 sport,但也被分配给 element 9
。带有 id 的元素9
是一个挂在带有 id 的类别上的团队,7
在这种情况下它不是一项运动,那么我需要咨询他的父母以检查是否是运动......
我的期望
| id元素 | |-----------| | 2 | | 4 |