sql求1到100的质数
有人问怎么求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
本文出自 “专注于Oracle性能调优” 博客,转载请与作者联系!
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。