使用SQL编写程序,输出100以内所有的素数

使用SQL编写程序,输出100以内所有的素数,第1张

05以后可以这样写

with temp1(col1) as

(select 1 col1

 union all

 select col1+2 col1

 from temp1

 where col1+2<=100

)

select sum(col1) from temp1

没测试,有问题你再追问吧,

***************************好吧,忘记素数是什么了,,写成了1,3,5,7这样的和了,,,

select sum(a.number)

from master..spt_values a

where a.number between 2 and 100 and a.type='p'

and not exists(select * from  master..spt_values b 

                    where b.number between 2 and 100 and b.type='p'

                        and a.number>b.number

                        and a.number%b.number=0)

create

procedure

p_1(@参数1

类型,@参数2

类型)

as来定义带参数的存储过程,这样存储过程里面就可以使用你传递过来的参数了。跟平时写但参数的函数是一样的。

然后你调用的时候

exec

p1(参数1,参数2)


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/7856975.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-10
下一篇2023-04-10

发表评论

登录后才能评论

评论列表(0条)

    保存