admin管理员组文章数量:1023782
This is my query It is meant to return the selectedResponse and its next and previous ids. As you can see, the Where clause currently constrains the results. I tried a nested select and CTE, both resulted in errors. In my previous implementation, I used nested selects with limit one, that resulted in n+1. I can't use joins, due to the issues with the parent ids (it was getting ids from another requests).
@Query("""
SELECT
new code.modules.conversation.data.jpa.projection.ResponseWindow(
res,
LAG(res.id) OVER (PARTITION BY res.request ORDER BY res.created),
LEAD(res.id) OVER (PARTITION BY res.request ORDER BY res.created)
)
FROM ResponseEntity res
WHERE res = :selectedResponse
""")
```
This is my query It is meant to return the selectedResponse and its next and previous ids. As you can see, the Where clause currently constrains the results. I tried a nested select and CTE, both resulted in errors. In my previous implementation, I used nested selects with limit one, that resulted in n+1. I can't use joins, due to the issues with the parent ids (it was getting ids from another requests).
@Query("""
SELECT
new code.modules.conversation.data.jpa.projection.ResponseWindow(
res,
LAG(res.id) OVER (PARTITION BY res.request ORDER BY res.created),
LEAD(res.id) OVER (PARTITION BY res.request ORDER BY res.created)
)
FROM ResponseEntity res
WHERE res = :selectedResponse
""")
```
本文标签: sqlSelect entity and ids of its surrounding entitiesStack Overflow
版权声明:本文标题:sql - Select entity and ids of its surrounding entities - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745596595a2158208.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论