-1
我使用PostgreSQL 有两个表:图层和图像Postgres的SQL递归查询
LAYERS (layer_id varchar PRIMARY KEY,
parent_id varchar REFERENCES LAYERS(layer_id))
IMAGES (image_id varchar UNIQUE, REFERENCES LAYERS(layer_id))
in LAYERS table: 1->2->3->4->5->6 (1 is the parent of 2)
in IMAGES table: 1,2,5,6
现在我想知道,这是图像图像5的最近的父的形象?
答案是图片2
如何编写这样的SQL查询?
非常感谢!
参见[Postgres的教程](https://www.postgresql.org/docs/current/static/queries-with.html)和[这里](https://stackoverflow.com/questions/标记/ PostgreSQL的+递归查询) –