본문 바로가기

Develop/Database & SQL

오라클 랜덤 확률 가중치

80 대 20의 확률

WITH TEST_TABLE AS
(
    SELECT 'A' TEAM, 20 RATE FROM DUAL UNION ALL
    SELECT 'B' TEAM, 80 RATE FROM DUAL
)

SELECT *
FROM (
    SELECT *
    FROM TEST_TABLE A
    , ( SELECT LEVEL LV FROM dUAL CONNECT BY LEVEL <= 100) B
    WHERE RATE >= LV
    ORDER BY DBMS_RANDOM.VALUE 
)
WHERE ROWNUM <= 1

참조
http://okky.kr/article/240161

- https://alreadyno.tistory.com/entry/%EC%98%A4%EB%9D%BC%ED%81%B4-%EB%9E%9C%EB%8D%A4-%ED%99%95%EB%A5%A0-%EA%B0%80%EC%A4%91%EC%B9%98