简单3个方面:
1.数据结构设计
2.快速查询上面第几级
3.快速查询下级第几级
快速查询上级:
SELECT * FROM oasis.oasis_user_info where id=(SELECT SPLIT_STR(‘1^.8^.9^.10‘, ‘^.‘,3) AS user_id)
快速查询下级
SELECT * FROM oasis_user_info WHERE layer_tree LIKE ‘1^.8^%‘ AND bind_level = 2
SPLIT_STR函数
CREATE FUNCTION SPLIT_STR( x TEXT,#这里改类型(varchar|char) delim VARCHAR(12), pos INT ) RETURNS VARCHAR(255) RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos), LENGTH(SUBSTRING_INDEX(x, delim, pos -1)) + 1), delim, ‘‘);
原文地址:https://www.cnblogs.com/light-zhang/p/11722056.html
时间: 2024-10-22 18:10:13