Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Help with Query

Author  Topic 

helpme
Posting Yak Master

141 Posts

Posted - 2005-01-09 : 11:37:28
We are trying to write the following oracle query in sql server.

select avg(fld1) from
(select rownum ord1, fld1 from
(select fld1 from tbl1
where fld2 = 2005
order by fld1)
where ord1 between 55 and 60)


How can we do this? Any replies are appreciated.

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2005-01-09 : 12:34:25
maybe something like:

select avg(fld1)
from
(
select top 5 fld1
from
(
select top 60 fld1
from tbl1
order by fld1
) a
order by fld1 desc
) b
Go to Top of Page

helpme
Posting Yak Master

141 Posts

Posted - 2005-01-09 : 12:48:03
I will try this. Thank you.
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2005-01-09 : 13:34:03
select avg(fld1)
from
(
select top 6 fld1
from
(
select top 60 fld1
from tbl1
where fld2 = 2005
order by fld1
) a
order by fld1 desc
) b

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -