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 |
|
duhaas
Constraint Violating Yak Guru
310 Posts |
Posted - 2007-01-25 : 14:14:02
|
| I have the following:SELECT s.babr, isnull(s.SicDescription,'Non-Inst and/or not coded') as sicdescription, SUM(s.AccountMV) AS mv, SUM(s.AccountMV) / q.ps AS PercentileFROM SnapsRaw s INNER JOIN (SELECT babr, SUM(accountmv) ps FROM snapsraw WHERE monthend = '12-1-2006' GROUP BY babr) q ON q.babr = s.babrWHERE s.MonthEnd = '12-1-2006'GROUP BY s.Babr, s.SicDescription, q.ps, q.babrorder by sicdescriptionI want to be able to add into the where clause something like this, but am unsure how:WHERE s.MonthEnd = '12-1-2006' and SUM(s.AccountMV) / q.ps > '0.00' |
|
|
snSQL
Master Smack Fu Yak Hacker
1837 Posts |
Posted - 2007-01-25 : 15:00:02
|
| You need to put any expressions that contain aggregates in the HAVING clause instead of the WHERE clause. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-25 : 15:18:31
|
| [code]SELECT s.babr, isnull(s.SicDescription, 'Non-Inst and/or not coded') as sicdescription, SUM(s.AccountMV) AS mv, SUM(s.AccountMV) / q.ps AS PercentileFROM SnapsRaw as sINNER JOIN ( SELECT babr, SUM(accountmv) as ps FROM snapsraw WHERE monthend = '12-1-2006' GROUP BY babr ) as q ON q.babr = s.babrWHERE s.MonthEnd = '12-1-2006'GROUP BY s.Babr, s.SicDescriptionhaving SUM(s.AccountMV) / q.ps > 0.0order by s.sicdescription[/code]Peter LarssonHelsingborg, Sweden |
 |
|
|
duhaas
Constraint Violating Yak Guru
310 Posts |
Posted - 2007-01-25 : 16:08:11
|
| i cant thank you two enough |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-25 : 16:11:07
|
| Don't thank us, thank Books Online.Peter LarssonHelsingborg, Sweden |
 |
|
|
|
|
|
|
|