表结构是下面这种 :
我现在已经得到的是第四条数据的father_id 我想得到第一条数据的内容 怎么写啊
select * from grammar left join (select father_id from grammar where grammar_id = '"+father_id+"' ) a on a.father_id = grammar_id 这么写不对啊~~~
id grammar_id name father_id level
1172 01 名词 00 1
1173 01.01 名词在句子中 01 2
1174 01.02 名词的特征 01 2
1175 01.02.01 可数名词 01.02 3
.........
我现在已经得到的是第四条数据的father_id 我想得到第一条数据的内容 怎么写啊
select * from grammar left join (select father_id from grammar where grammar_id = '"+father_id+"' ) a on a.father_id = grammar_id 这么写不对啊~~~
id grammar_id name father_id level
1172 01 名词 00 1
1173 01.01 名词在句子中 01 2
1174 01.02 名词的特征 01 2
1175 01.02.01 可数名词 01.02 3
.........
id grammar_id name father_id level
1172 01 名词 00 1
1173 01.01 名词在句子中 01 2
1174 01.02 名词的特征 01 2
1175 01.02.01 可数名词 01.02 3
(select g.*,rownum as lineNum from grammar g)tempG
WHERE exists(
select * from
(select g.*,rownum as lineNum from grammar g)tempG1
where tempG1.lineNum = tempG.lineNum + 3
and tempG1.grammar_id = '"+father_id+"'
)
select * from grammar
where grammar_id = '01.02' --第四条的father_id
那要一层层往上找,看看mysql里有没有相应的函数
1175 01.02.01 可数名词 01.02 3
select * from grammar where grammar_id = (select substring(grammar_id,0,2) from grammar where father_id=“第四条”)这个数据你看好了就行了 它可只针对你这个数据表 别的不OK 我没测试 但是应该是OK的