在我的数据库中,我有以下列BreadCrumb,每行有条目:
Root->Music by Artist->Kylie Root->Music by Artist->Beyonce->2009 Root->Music by Artist->Beyonce->2008 Root->TrashCan Root2->Demo Content->Building 1
如何执行查询以向我提供仅包含“艺术家音乐”和“演示内容”(不重复)的列?
答案 0 :(得分:2)
Postgres有许多不错的字符串函数(http://www.postgresql.org/docs/current/static/functions-string.html):
SELECT DISTINCT split_part(crumbs,'->',2)
FROM table1
WHERE split_part(crumbs,'->',3)<>'';