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 |
|
argon007
Starting Member
38 Posts |
Posted - 2008-06-03 : 23:46:23
|
[code]SELECT name = SUBSTRING(name, 1, 1), total = COUNT(SUBSTRING(name, 1, 1))FROM productsGROUP BY SUBSTRING(name, 1, 1)[/code]the assignment said that, quote: "Do not display the letter and count unless at least three product names begin with the letter."
but i got the errors when I try following.[code]WHERE total >= 3[/code] quote: Msg 207, Level 16, State 1, Line 4Invalid column name 'total'.
[code]WHERE COUNT(SUBSTRING(name, 1, 1)) >= 3[/code] quote: Msg 147, Level 15, State 1, Line 1An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.
so what should I do? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-03 : 23:49:40
|
| SELECT name = SUBSTRING(name, 1, 1), total = COUNT(SUBSTRING(name, 1, 1))FROM productsGROUP BY SUBSTRING(name, 1, 1)HAVING COUNT(SUBSTRING(name, 1, 1)) >= 3 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-03 : 23:50:53
|
| The error message clearly suggested the use of HAVING |
 |
|
|
argon007
Starting Member
38 Posts |
Posted - 2008-06-03 : 23:56:33
|
| thank you. |
 |
|
|
|
|
|
|
|