SQL计算1000的阶乘

htl258_Tony 2009-04-12 07:47:10
加精
今天看到C++的和JAVA的都写出来了,SQL的还没写出来,大家一起看看。
...全文
59070 181 打赏 收藏 转发到动态 举报
写回复
用AI写文章
181 条回复
切换为时间正序
请发表友善的回复…
发表回复
w3329307 2010-08-23
  • 打赏
  • 举报
回复
sql有这么大的数吗
wangyuchen97 2010-08-15
  • 打赏
  • 举报
回复
花费0.09秒。[Quote=引用 107 楼 raokaichuan 的回复:]
create table tb(id int IDENTITY(1,1) PRIMARY KEY,factor bigint)
insert into tb(factor) values(1)
go
declare @i int,@factormax int
set @i=2
while @i <=1000
begin
update tb set factor=facto……
[/Quote]
老黎 2010-04-10
  • 打赏
  • 举报
回复
up..
wu222w 2009-05-12
  • 打赏
  • 举报
回复

还是MatLab在大整数计算方面好用
woniu033 2009-04-28
  • 打赏
  • 举报
回复
1000应该一般的计算机达不到吧
没那么大
我只做到13!
xmczq 2009-04-24
  • 打赏
  • 举报
回复
up
mislrb 2009-04-23
  • 打赏
  • 举报
回复
几年没来,看到这个标题,进来学习下,
woniu033 2009-04-23
  • 打赏
  • 举报
回复
declare @i int
declare @j int
set @j=1
set @i=1
while(@i <=10)
begin
set @j=@i*@j
set @i=@i+1
end
print '10!='+STR(@j )

用这个吧
wdj010 2009-04-22
  • 打赏
  • 举报
回复
顶,向高手学习
天马冰河 2009-04-16
  • 打赏
  • 举报
回复
顶!!!学习学习!!!
ljycszmsdn 2009-04-16
  • 打赏
  • 举报
回复
MARK
paual779 2009-04-15
  • 打赏
  • 举报
回复
强!
龙宜坡 2009-04-15
  • 打赏
  • 举报
回复
原来SQL可以这样强悍
chenyonghui1988 2009-04-15
  • 打赏
  • 举报
回复
服务器: 消息 206,级别 16,状态 2,行 16
操作数类型冲突: bigint 与 void type 不兼容
服务器: 消息 8117,级别 16,状态 1,行 16
操作数数据类型 numeric 无效(运算符 modulo)。
我复制了你的代码 出现这个错误怎么办?
chenyonghui1988 2009-04-15
  • 打赏
  • 举报
回复
create table tb(id int IDENTITY(1,1) PRIMARY KEY,factor bigint)
insert into tb(factor) values(1)
go
SET NOCOUNT ON;
declare @i int,@factormax int
set @i=2
while @i<=1000
begin
update tb set factor=factor*@i
update tb set factor=factor+isnull((select floor(factor/1000000000000000) from tb where id=a.id-1),0) from tb a
select @factormax=floor(factor/1000000000000000) from tb where id=(select top 1 id from tb order by id desc)
if @factormax >0
insert into tb(factor) values(@factormax)
update tb set factor=factor % 1000000000000000
set @i=@i+1
end
select right('000000000000000'+convert(varchar,factor),15) from tb order by id desc
go
drop table tb
哥们你这个代码 放查询分析器 里面怎么运行 不了啊:编译 成功了 就是运行出现:所影响的行数为 1 行)

服务器: 消息 206,级别 16,状态 2,行 11
操作数类型冲突: bigint 与 void type
strongge 2009-04-15
  • 打赏
  • 举报
回复
[Quote=引用 57 楼 qianjin036a 的回复:]
SQL codecreate table tb(id int IDENTITY(1,1) PRIMARY KEY,factor bigint,charfactor varchar(15))
insert into tb(factor) values(1)
go
SET NOCOUNT ON;
declare @i int,@factormax int
set @i=2
while @i<=1000
begin
update tb set factor=factor*@i
update tb set factor=factor+isnull((select floor(factor/1000000000000000) from tb where id=a.id-1),0) from tb a
select @factormax=floor(…
[/Quote]


晕,Ctrl+C,Ctrl+V你的代码,


出现!

(所影响的行数为 1 行)

服务器: 消息 206,级别 16,状态 2,行 11
操作数类型冲突: bigint 与 void type 不兼容
服务器: 消息 8117,级别 16,状态 1,行 11
操作数数据类型 numeric 无效(运算符 modulo)。
fellatioyzx 2009-04-15
  • 打赏
  • 举报
回复
[Quote=引用 18 楼 happyflystone 的回复:]
SQL codedeclare @t int
set @T = 40 --计算40的阶乘
SET NOCOUNT ON
declare @ta table(id int identity(1,1),col bigint)
insert @ta(col) select 1



declare @n int,@i int,@c bigint,@len int,@tmp bigint,@tp bigint

set @len=1;
set @n = @t
while (@n >=1)
begin
select @c = 0 ,@i = 1
select @tmp = col from @ta where id = @i
while (@i <= @len)
begin
set @tmp…
[/Quote]

牛人~~,学习了
ViewStates 2009-04-15
  • 打赏
  • 举报
回复
这个帖子要顶
hujun_zero 2009-04-15
  • 打赏
  • 举报
回复
接分,学习
ouyang3857116 2009-04-15
  • 打赏
  • 举报
回复
28的正解只是建立他取的基数很大的基础上而已(1000000000000000),改小的话(如10000),是个错误的算法!
因为每次运算不一定只是最后一行要向前进位,希望改善一下!
加载更多回复(161)

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧