WITH T AS ( SELECT 8 COL1 , 'A' COL2 FROM DUAL UNION ALL SELECT 5 , 'B' FROM DUAL ) , COPY_T AS ( SELECT LEVEL LV FROM DUAL CONNECT BY LEVEL <= 10 ) SELECT COL2 , COUNT(*) CNT FROM (SELECT ROWNUM RN , COL2 , NTILE(3) OVER(PARTITION BY COL2 ORDER BY ROWNUM ) GRP FROM T , COPY_T WHERE LV <= COL1 ) GROUP BY COL2 , GRP ORDER BY COL2 , MAX(RN)