怎样用T-SQL语言编程输出3~100之内的素数?

2024-12-28 17:03:33
推荐回答(1个)
回答1:

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 行受影响)