declare @t table ( id int, value int )insert @t select 1,40 union all select 2,50 union all select 3,60declare @i int select @i=min(value) from @t while exists ( select 1 from @t where value % @i <> 0 ) set @i = @i -1 select @i as 最大公约数 declare @t table ( id int, value int )insert @t select 1,5 union all select 2,6 union all select 3,15declare @max int select @max=max(value) from @t declare @i int set @i =1 while exists ( select 1 from @t where @i*@max % value <> 0 ) set @i = @i + 1 select @i*@max as 最小公倍数
给你一个最小公倍数的。 --思路原创:Haiwer。 declare @t table (id int,value int)insert @t select 1,5 union all select 2,6 union all select 3,15declare @max int select @max=max(value) from @t declare @i int set @i =1 while exists (select 1 from @t where @i*@max % value <> 0) set @i = @i + 1 select @i*@max as 最小公倍数
id int,
value int
)insert @t select
1,40
union all select
2,50
union all select
3,60declare @i int
select @i=min(value) from @t
while exists (
select 1
from @t
where value % @i <> 0
)
set @i = @i -1
select @i as 最大公约数
declare @t table (
id int,
value int
)insert @t select
1,5
union all select
2,6
union all select
3,15declare @max int
select @max=max(value) from @t
declare @i int
set @i =1
while exists (
select 1
from @t
where @i*@max % value <> 0
)
set @i = @i + 1
select @i*@max as 最小公倍数
--思路原创:Haiwer。
declare @t table (id int,value int)insert @t select 1,5 union all select 2,6 union all select 3,15declare @max int
select @max=max(value) from @t
declare @i int
set @i =1
while exists (select 1 from @t where @i*@max % value <> 0)
set @i = @i + 1
select @i*@max as 最小公倍数