在同一个字段内如何查询不同位置的值?

 现在[b]部门关系存到了同一个字段内[/b],共有6层,分别用[b]逗号隔开[/b],部门的层级依次降低,能根据前一个值查询后一个值吗?

[img]http://dl.iteye.com/upload/attachment/0073/1149/ac09aec9-ad02-3974-80d3-5b788181b206.png[/img]

[code="sql"]
select column_SecondValue from table_name where column_firstValue ='参数'
[/code]

个人建议,该字段不该这么设计,关系应该拉出来作为实体。
我很疑惑,关系数据在更新的时候,你们是怎么做的。

我的理解是:一个字段存放很多值,都以逗号形式分割
如果能查询到这条记录,那么还有什么查询不到的
例如:
select column_SecondValue from table_name where column_firstValue like'123123415646123%'
这样查询到所有 column_firstValue like 和传入值匹配的字段了

String sql="select column_SecondValue from table_name where column_SecondValue like'123123415646123%' ";
Listlist=方法返回上个sql的结果级
for循环遍历这个字段
后台代码做split(",");分割这个字段的值,
split(",")[0]部门第1个
split(",")[1]部门第2个

如果你要根据这个列的第一个值去查第二个值的话,sql里面可以用字符串截取的。

比如oracle里面可以用substr和instr结合实现,
1.column_firstValue可以这样截取
[code="sql"]
substr(t.col1, 0, instr(t.col1, ',') - 1)
[/code]
2.column_SecondValue就要截第一个逗号和第二个逗号之间的,所以要从第一个逗号之后的那个位置instr(t.col1, ',') + 1开始截,截第二个和第一个之间的那个长度instr(t.col1, ',', 1, 2) - instr(t.col1, ',') - 1,所以最后可以这样截取
[code="sql"]
substr(t.col1,
instr(t.col1, ',') + 1,
instr(t.col1, ',', 1, 2) - instr(t.col1, ',') - 1)
[/code]

3.所以最后由第一个值去查第二个值可以这样:
[code="sql"]
select t.col1,
substr(t.col1,
instr(t.col1, ',') + 1,
instr(t.col1, ',', 1, 2) - instr(t.col1, ',') - 1) column_SecondValue。
from table_name t
where substr(t.col1, 0, instr(t.col1, ',') - 1) = '参数';
[/code]

其他的也可以依此类推。。。

这谁设计的狗屎表。这样设计一点层次感也没有。怎么搜索?