seaswalker / posts

0 stars 0 forks source link

PostgreSQL查询字符串中字符(子串)出现的次数 #28

Open seaswalker opened 3 years ago

seaswalker commented 3 years ago
SELECT
    *
FROM
    (
        SELECT
            category,
            (
                length(path) - length(replace(path, '.', ''))
            ) AS level
        FROM
            category_info
    ) _inner
ORDER BY
    _inner.level DESC
LIMIT
    2;

path是以.分隔的字符串,代表层级。