Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试图找到孩子最多的父母。我觉得这不应该那么难,但我发现自己在挣扎。
我正在使用 postgresql 和 Ltree。
谢谢
这与任何其他情况的逻辑相同,找到一个可以为您提供父级并按其分组的函数。这应该有效:
SELECT subpath(path,0,1), count(*) FROM test GROUP BY subpath(path,0,1) ORDER BY count(*) DESC limit 1;
http://sqlfiddle.com/#!12/8fb17/5