&gname> > select * from t;
ID NAME FLIGHTID
---------- ------------------------------ ------------------------------
3 zhou 101
3 zhou 101
4 li 105
5 wang 104
5 wang 104
5 wang 106
ORACLE10G及以上:
&gname> > SELECT NAME ,ID ,wm_concat(flightid) from t GROUP BY NAME ,ID ;
NAME ID WM_CONCAT(FLIGHTID)
------------------------------ ---------- --------------------------------------------------------------------------------
li 4 105
wang 5 104,106,104
zhou 3 101,101
oracle9I 及以下:
&gname> > SELECT NAME, ID, ltrim(max(SYS_CONNECT_BY_PATH(FLIGHTID, ',')),',')
2 FROM (SELECT T.*,
3 ROW_NUMBER() OVER(PARTITION BY NAME, ID ORDER BY FLIGHTID DESC) RN
4 FROM T)
5 CONNECT BY NAME = PRIOR NAME
6 AND ID = PRIOR ID
7 AND RN = PRIOR RN + 1
8 GROUP BY NAME ,ID ;
NAME ID LTRIM(MAX(SYS_CONNECT_BY_PATH(
------------------------------ ---------- --------------------------------------------------------------------------------
li 4 105
wang 5 106,104,104
zhou 3 101,101
看不懂