Update问题(循环替代)?
各位大侠:
问题如下:有表X
date name instead
20070116 a b
20070116 b c
20070116 c d
20070116 d e
20070116 g h
20070116 h i
20070116 i j
20070116 m n
代表意义: a <-b b <-c c <-d d <-e => a <-e
g <-h h <-i i <-j => g <-j
用sql语句select出如下结果:
date name instead
20070116 a e
20070116 g j
20070116 m n
谢谢!!!!
------解决方案--------------------用start with ... connect by...
------解决方案--------------------SQL> select * from x;
MYDATE MYNAME INSTEAD
----------- ------ -------
2007-1-16 a b
2007-1-16 b c
2007-1-16 c d
2007-1-16 d e
2007-1-16 g h
2007-1-16 h i
2007-1-16 i j
2007-1-16 m n
8 rows selected
SQL>
SQL> SELECT mydate, MIN(myname), MAX(INSTEAD)
2 FROM (SELECT * FROM x ORDER BY mydate, myname)
3 GROUP BY mydate, ascii(myname) - rownum
4 /
MYDATE MIN(MYNAME) MAX(INSTEAD)
----------- ----------- ------------
2007-1-16 a e
2007-1-16 g j
2007-1-16 m n
------解决方案--------------------貌似可以写个函数,我用的是oracle