본문 바로가기

DB/MySQL

1 ~ 30까지 번호가 반복적으로 나타나도록.

반응형

select level as no, mod(level, 30) as no30
from dual
connect by level <= 90;


select no, decode(no30, 0, 30, no30) as no30
from (select level as no, mod(level, 30) as no30
         from dual
         connect by level <= 90);

 

        NO       NO30
---------- ----------
         1          1
         2          2
         3          3
         4          4
         5          5
         6          6
         7          7
         8          8
         9          9
        10         10
        11         11
        12         12
        13         13
        14         14
        15         15
        16         16
        17         17
        18         18
        19         19
        20         20
        21         21
        22         22
        23         23
        24         24
        25         25
        26         26
        27         27
        28         28
        29         29
        30         30
        31          1
        32          2

        ... 생략 ...

 

        88         28
        89         29
        90         30

 

 90 rows selected.1 ~ 30까지 번호가 반복적으로 나타나도록.

반응형