create table tb_04(f1 int) insert into tb_04 select 18 union all select 12--类似游标行不行 declare @t table(id int identity(1,1),f1 int) insert into @t select f1 from tb_04 select (select f1 from @t where id=1)*1.0/(select f1 from @t where id=2) /* 1.500000000000 */
create table tb_04(f1 int) insert into tb_04 select 18 union all select 12declare @s varchar(8000) set @s='' select @s=@s+cast(f1 as varchar(200))+',' from tb_04 select @s=left(@s,len(@s)-1) select cast(left(@s,charindex(',',@s)-1) as int)*1.0/cast(substring(@s,charindex(',',@s)+1,len(@s)) as int) /* 1.500000000000 */
--> 测试数据: #T if object_id('tempdb.dbo.#T') is not null drop table #T create table #T (f1 int) insert into #T select 18 union all select 12select id=identity(int,1,1),* into # from #Tselect a.f1*1.0/b.f1 from # a join # b on a.id=b.id-1 and b.id%2=0
我没想出来 order by 对象该是啥
SELECT (SELECT TOP 1 f1 FROM t) / (SELECT TOP 1 f1 FROM t ORDER BY f1 DESC)
SELECT TOP 1 f1 FROM t是18 SELECT TOP 1 f1 FROM t ORDER BY f1 DES 也是18
在大家的帮助下,有了标准答案: declare @x numeric(9,2) select @x=max(f1)/min(f1) from (select f1 from tb) a 哈哈
玩游戏,表都用了舍不得给字段 declare @a int,@b int select @a=(select top 1 f1 from #t),@b=@a select @b=f1 from #t where f1<>@a select @b*1.0/@a
伟大的光荣的正确的ASP千岁千岁千千岁 --小心被拉下来打80大板
不怎么样 如果是 f1 12 18 呢?你的这个写法完全是已经知道数据了,才这么写的,与其这样,你还不如select 18*1.0/12呢
也是好办法。 就是select @b*1.0/@a写反了,应该是select @a*1.0/@b
那你提前也没说啊 ~ ~ 那直接就 select max(f1)*1.0/min(f1) from tb 不就行了
select max(f1)*1.0/min(f1) from tb嗯..这个 是楼主的问题.让大家都去猜了
insert into tb_04 select 18 union all select 12--类似游标行不行
declare @t table(id int identity(1,1),f1 int)
insert into @t select f1 from tb_04
select (select f1 from @t where id=1)*1.0/(select f1 from @t where id=2)
/*
1.500000000000
*/
insert into tb_04 select 18 union all select 12declare @s varchar(8000) set @s=''
select @s=@s+cast(f1 as varchar(200))+',' from tb_04
select @s=left(@s,len(@s)-1)
select cast(left(@s,charindex(',',@s)-1) as int)*1.0/cast(substring(@s,charindex(',',@s)+1,len(@s)) as int)
/*
1.500000000000
*/
if object_id('tempdb.dbo.#T') is not null drop table #T
create table #T (f1 int)
insert into #T
select 18 union all
select 12select id=identity(int,1,1),* into # from #Tselect a.f1*1.0/b.f1
from # a
join # b
on a.id=b.id-1 and b.id%2=0
我没想出来 order by 对象该是啥
FROM t) /
(SELECT TOP 1 f1
FROM t
ORDER BY f1 DESC)
SELECT TOP 1 f1
FROM t是18
SELECT TOP 1 f1
FROM t
ORDER BY f1 DES
也是18
declare @x numeric(9,2)
select @x=max(f1)/min(f1) from (select f1 from tb) a
哈哈
declare @a int,@b int
select @a=(select top 1 f1 from #t),@b=@a
select @b=f1 from #t where f1<>@a
select @b*1.0/@a
不怎么样
如果是
f1
12
18
呢?你的这个写法完全是已经知道数据了,才这么写的,与其这样,你还不如select 18*1.0/12呢
也是好办法。
就是select @b*1.0/@a写反了,应该是select @a*1.0/@b
那直接就
select max(f1)*1.0/min(f1) from tb
不就行了