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.
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 = 2xwhere ??? (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 decimalSumfrom table 1 inner join table 2 on 1x = 2x) t1where decimalSum >= 600Go with the flow & have fun! Else fight the flow blog thingie: http://weblogs.sqlteam.com/mladenp |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-31 : 13:29:02
|
What about HAVING SUM(decimal1) >= 600?Peter LarssonHelsingborg, Sweden |
 |
|
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 |
 |
|
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 decimalSumfrom table 1 inner join table 2 on 1x = 2xGroup by data1, data2, data3) t1where decimalSum >= 600Go with the flow & have fun! Else fight the flow blog thingie: http://weblogs.sqlteam.com/mladenp
MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|