表TB的PATH字段如下
- SQL code
path-------------11-21-2-31-2-3-4aa-ba-b-ca-b-da-e我要的结果/*path-------------1-2-3-4a-ea-b-ca-b-d*/
提示:
其实就是取一个树形结构的最后路径 - -|| 一下子想不出了 谢谢各位
*
1 a
2 b e
3 c d
4
上面是树形结构 就是取这里的终极路径
------解决方案--------------------
- SQL code
--> 测试数据:@tbdeclare @tb table([path] varchar(7))insert @tbselect '1' union allselect '1-2' union allselect '1-2-3' union allselect '1-2-3-4' union allselect 'a' union allselect 'a-b' union allselect 'a-b-c' union allselect 'a-b-d' union allselect 'a-e'select * from @tb AS AWHERE NOT EXISTS(SELECT * FROM @tb WHERE path LIKE A.path + '_%')