Question : Write a Query to print numbers in sequence from 1 to 100
Conditions : if Number is divided by 3 or 5 Print NULL else print number
SQL Query :
SELECT CASE WHEN MOD(rownum,3) = 0 THEN NULL
WHEN MOD(rownum,5) = 0 THEN NULL
ELSE rownum
END NUM
FROM (SELECT 1 FROM dual GROUP BY CUBE (1,2,3,4,5,6,7))
WHERE rownum <= 100;
Result:
1
2
4
7
8
11
13
14
16
17
19
22
23
26
28
29
31
32
34
37
38
41
43
44
46
47
49
52
53
56
58
59
61
62
64
67
68
71
73
74
76
77
79
82
83
86
88
89
91
92
94
97
98
0 Comments