DBILITY

oracle 입찰시 기준율을 적용 업체별 순위 표시 본문

database/sql

oracle 입찰시 기준율을 적용 업체별 순위 표시

DBILITY 2016. 10. 13. 09:01
반응형

전년도(2015)에 database.sarang.net에 답변해 드린 내용입니다.

지금보니 내가 한게 맞는지 의문이 들고 있음.


11G부터는 PIVOT을 지원합니다.

WITH
A(NO,COUNT,LOWER_BND)
AS
(
	SELECT 'A001',1,80 FROM DUAL
),
B(NO,COUNT,I_NO,AMT)
AS
(
	SELECT 'A001',1,1,1000 FROM DUAL UNION ALL
	SELECT 'A001',1,2,3000 FROM DUAL
),
C(NO	,COUNT,SEQ,VENDOR,AMT)
AS
(
	SELECT 'A001',1,1,'A1',	3000 FROM DUAL UNION ALL
	SELECT 'A001',1,1,'A2',1000 FROM DUAL UNION ALL
	SELECT 'A001',1,1,'A3',4000 FROM DUAL UNION ALL
	SELECT 'A001',1,1,'A4',3500 FROM DUAL UNION ALL
	SELECT 'A001',1,1,'A5',4200 FROM DUAL UNION ALL		
	SELECT 'A001',1,1,'A6',4200 FROM DUAL UNION ALL		
	SELECT 'A001',1,1,'A7',4200 FROM DUAL UNION ALL		
	SELECT 'A001',1,1,'A8',4200 FROM DUAL UNION ALL		
	SELECT 'A001',1,1,'A9',4200 FROM DUAL UNION ALL		
	SELECT 'A001',1,1,'A10',4200 FROM DUAL UNION ALL		
	SELECT 'A001',1,1,'A11',4200 FROM DUAL UNION ALL			
	SELECT 'A001',1,2,'A1',	3201 FROM DUAL UNION ALL
	SELECT 'A001',1,2,'A2',1200 FROM DUAL UNION ALL
	SELECT 'A001',1,2,'A3',3400 FROM DUAL
)
SELECT
	F.RN,F.NO,
	MIN(DECODE(F.SEQ,1,F.SEQ))SEQ1,
	MIN(DECODE(F.SEQ,1,F.RANK))RANK1,
	MIN(DECODE(F.SEQ,1,F.VENDOR))VENDOR1,
	MIN(DECODE(F.SEQ,1,F.AMT))AMT1,
	MIN(DECODE(F.SEQ,2,F.SEQ))SEQ2,
	MIN(DECODE(F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Q10,
	MIN(DECODE(F.SEQ,10,F.RANK))RANK10,
	MIN(DECODE(F.SEQ,10,F.VENDOR))VENDOR10,
	MIN(DECODE(F.SEQ,10,F.AMT))AMT10
FROM
(
	SELECT
		C.NO,C.COUNT,C.SEQ,C.VENDOR,C.AMT,E.LOWER_BND,
		CASE WHEN C.AMT <= E.LOWER_BND THEN RANK() OVER(PARTITION BY C.NO,C.COUNT,C.SEQ ORDER BY C.NO,C.COUNT,C.SEQ,C.AMT)||'' 
		ELSE '탈락' END RANK,
		ROW_NUMBER() OVER(PARTITION BY C.NO,C.COUNT,C.SEQ ORDER BY C.NO,C.COUNT,C.SEQ,C.AMT) RN
	FROM
	(
	SELECT
		D.NO,D.COUNT,(D.AMT*A.LOWER_BND*0.01) LOWER_BND
	FROM (SELECT B.NO,B.COUNT,SUM(B.AMT) AMT FROM B GROUP BY B.NO,B.COUNT) D,A
	WHERE D.NO=A.NO AND D.COUNT=A.COUNT
	) E,C
	WHERE 
		E.NO=C.NO AND E.COUNT=C.COUNT
) F 
GROUP BY F.NO,F.RN ORDER BY F.NO,F.RN

 

반응형
Comments