怎样用T-SQL语言编程输出3~100之内的素数?
展开全部
SELECT
main.number
FROM
master..spt_values AS main
WHERE
type='P'
AND number BETWEEN 3 AND 100
AND NOT EXISTS (
SELECT
1
FROM
master..spt_values AS sub
WHERE
type='P'
AND sub.number BETWEEN 2 AND main.number - 1
AND main.number % sub.number = 0
);
number
-----------
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
(24 行受影响)
main.number
FROM
master..spt_values AS main
WHERE
type='P'
AND number BETWEEN 3 AND 100
AND NOT EXISTS (
SELECT
1
FROM
master..spt_values AS sub
WHERE
type='P'
AND sub.number BETWEEN 2 AND main.number - 1
AND main.number % sub.number = 0
);
number
-----------
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
(24 行受影响)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询