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)
 Ordering a query by a derived value

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-08-17 : 08:16:18
Peter writes "What if you have a table, for example States, with population, square miles, etc. and you want to query the table and order the query by a derived value, such as populationDensity = pop/squareMiles, or anything like that, which isn't a column in the table but can be derived from the information in two columns. Is it possible in SQL to write something like
SELECT * FROM States ORDER BY (pop/squareMiles)?
Thanks
Peter"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-17 : 08:21:54
Have a seperate column in the query

Select * from (
Select columns,(pop/squareMiles) as mycol from yourtable)
T order by mycol


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

mmarovic
Aged Yak Warrior

518 Posts

Posted - 2005-08-18 : 06:17:02
Yes, it is. Why didn't you just run that and saw if it worked?
Go to Top of Page
   

- Advertisement -