table1
personcode personame
1 张三
2 李四table2
personcode chyear
1 2006年
1 2007年
2 2005年
2 2006年结果用sql 语言 :
personname chyear
张三 2006 年,2007年
李四 2005 年,2006年
personcode personame
1 张三
2 李四table2
personcode chyear
1 2006年
1 2007年
2 2005年
2 2006年结果用sql 语言 :
personname chyear
张三 2006 年,2007年
李四 2005 年,2006年
FROM (
SELECT personcode,personame, chyear,
ROW_NUMBER() OVER(PARTITION BY personcode ORDER BY chyear) as CURR,
ROW_NUMBER() OVER(PARTITION BY personcode ORDER BY chyear) - 1 as PREV
FROM (
SELECT A.personcode, A.personame, B.chyear
FROM table1 A INNER JOIN table2 B ON A.personcode = B.personcode
)
)
START WITH CURR = 1
CONNECT BY PREV = PRIOR CURR and personcode = PRIOR personcode
GROUP BY personame