简单问题实现(18,10,19) 100分,
SHOKUIN_NO KINMU_YMD TOKKIN_CODE UPDATE_YMD INSERT_YMD
000001 20070207 10 20070214130723 2007/02/11 13:07:23
000001 20070207 18 20070213130723 2007/02/12 13:07:23
000001 20070207 19 20070215130723 2007/02/12 13:07:23
--------------------------------------------
上面的数据如何实现下面的结果:注(TOKKIN_CODE,要按照ORDER BY UPDATE_YMD,INSERT_YMD 升序排序)
结果如下
000001 20070207 18,10,19
------解决方案--------------------用函数实现:
CREATE OR REPLACE FUNCTION get_code(IS_SHOKUIN_NO VARCHAR2,IS_KINMU_YMD VARCHAR2)
RETURN VARCHAR2
IS
col_code VARCHAR2(4000);
BEGIN
FOR cur IN (SELECT TOKKIN_CODE FROM t WHERE SHOKUIN_NO=IS_SHOKUIN_NO AND KINMU_YMD=IS_KINMU_YMD ORDER BY UPDATE_YMD,INSERT_YMD) LOOP
col_code := col_code|| ', '||cur.TOKKIN_CODE;
END LOOP;
col_code := ltrim(col_code, ', ');
RETURN col_code;
END;
/
SELECT DISTINCT SHOKUIN_NO,KINMU_YMD,get_code(SHOKUIN_NO,KINMU_YMD) TOKKIN_CODE FROM TABLENAME;
------解决方案--------------------用程序实现吧