当前位置: 代码迷 >> Sql Server >> 找出含有某个字符的最大id,该怎么解决
  详细解决方案

找出含有某个字符的最大id,该怎么解决

热度:57   发布时间:2016-04-27 14:56:30.0
找出含有某个字符的最大id
数据库中有字段
id pathcode
1 null
2 /1
3 /1/2
4 /1/2
5 /1/2
6 /1/2/4
7 /1/2/4
8 /1/2/4/5

找出数据库中含有2个 "/" 最大id,此数据中最大id=5 ,请问Sql语句怎么写?

------解决方案--------------------
SQL code
create table tb(id int, pathcode varchar(50))insert into tb values(1,'')insert into tb values(2,'/1')insert into tb values(3,'/1/2')insert into tb values(4,'/1/2')insert into tb values(5,'/1/2')insert into tb values(6,'/1/2/4')insert into tb values(7,'7 /1/2/4')insert into tb values(8,'/1/2/4/5') select max(id)    from tb where   len(pathcode) - len(replace(pathcode,'/',''))  =2 -----------5(1 行受影响)
  相关解决方案