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
 General SQL Server Forums
 New to SQL Server Programming
 Query like this ?

Author  Topic 

andrewcw
Posting Yak Master

133 Posts

Posted - 2011-04-28 : 15:43:04
Example - I have a data that is row based. Fortunately each set I know the approx max & min values. If I do a query though of something like above X Or less Y, the values will still be on different rows.
I could settle for one of the desired outcomes below to later calculate range or to directly do it. Ideas... ??? Thanks

ItemName Degrees
item1 35
item1 3
item1 -25
item2 45
item2 3
item2 -25

Desired outcomes either
ItemName DegreesMin DegreesMax
item1 -25 35
item2 -25 45

or better yet

ItemName DegreesRange
item1 60
item2 40



andrewcw

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-04-28 : 17:36:27
Can you calculate it as:

select
ItemName,
min(Degrees) as DegreesMin,
max(Degrees) as DegreesMax,
max(Degrees)-min(Degrees) as DegreesRange
from
yourTable
group by
ItemName

Or, are you concerned about something more such as picking up only principal values?
Go to Top of Page

andrewcw
Posting Yak Master

133 Posts

Posted - 2011-04-28 : 20:55:56
Oh that's excellent Exactly what was needed !Thank you !!!!

andrewcw
Go to Top of Page
   

- Advertisement -