sql求1到100的质数
程序员文章站
2022-03-13 12:12:05
...
有人问怎么求1到100的质数,所以就试着用sql写了个
WITH x1 AS
(SELECT LEVEL + 1 AS id FROM dual CONNECT BY LEVEL <= 99),
x2 AS
(SELECT a.id, a.id / b.id AS num FROM x1 a, x1 b WHERE a.id <> b.id)
SELECT DISTINCT id
FROM x2
WHERE id NOT IN (SELECT DISTINCT id FROM x2 WHERE num NOT LIKE '%.%')
ORDER BY 1
ID
----------
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
转载于:https://blog.51cto.com/5073392/1575747
上一篇: Fragment 之间传递数据
下一篇: java泛型