从具有列ID,IDofParent和Flavor的SQLite表中,如何使用max。效率我可以返回任何父母有Flavor = Lemon的记录吗?
答案 0 :(得分:1)
如果你有SQLite 3.8.3或更高版本,可以通过递归common table expression来完成:
WITH RECURSIVE LemonsAndChildren AS (
SELECT * FROM ATable WHERE Flavour = 'Lemon'
UNION ALL
SELECT Child.* FROM ATable AS Child
JOIN LemonsAndChildren AS Parent ON Child.IDofParent = Parent.ID
)
SELECT * FROM LemonsAndChildren