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)
 Select X where sum >= Y

Author  Topic 

Dave_Fergy
Starting Member

5 Posts

Posted - 2006-10-31 : 13:08:28
I am trying to select several columns in multiple tables and need to only have the data where a sum is > Y (given number). I have tried using a select within the select without any luck. Not exactly sure what to do here as I have not done a query like this one before.

(Select data1, data2, data3, sum(decimal1)
from table 1
inner join table 2 on 1x = 2x
where ??? (need to have sum >= 600)

Thanks

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-10-31 : 13:11:45
select *
from
(
select data1, data2, data3, sum(decimal1) as decimalSum
from table 1
inner join table 2 on 1x = 2x
) t1
where decimalSum >= 600



Go with the flow & have fun! Else fight the flow
blog thingie: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-10-31 : 13:29:02
What about HAVING SUM(decimal1) >= 600?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

Dave_Fergy
Starting Member

5 Posts

Posted - 2006-10-31 : 14:20:48
Thanks the having is what I was looking for and it worked. i have been out of the SQL loop for a while and thought this was rather easy but I was just brain dead.

Thanks



No Longer Behind the
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-31 : 20:19:57
quote:
Originally posted by spirit1

select *
from
(
select data1, data2, data3, sum(decimal1) as decimalSum
from table 1
inner join table 2 on 1x = 2x
Group by data1, data2, data3
) t1
where decimalSum >= 600



Go with the flow & have fun! Else fight the flow
blog thingie: http://weblogs.sqlteam.com/mladenp



Madhivanan

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

- Advertisement -