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 |
kavi12345
Starting Member
19 Posts |
Posted - 2012-03-14 : 07:04:17
|
Why the following queries are like this?1st format: SELECT Employee, SUM (Hours)FROM EmployeeHoursWHERE SUM (Hours) > 10GROUP BY Employee 2nd FormatSELECT Employee, SUM (Hours)FROM EmployeeHoursGROUP BY EmployeeHAVING SUM (Hours) > 10This among formats,why the 2nd format only is accepetable? perhaps while using GROUP BY,we shouldnot use WHERE clause or what?? otherwise, Should we use HAVING clause while using GROUP BY only??.. kavichakravarthi.R |
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2012-03-14 : 10:31:22
|
WHERE is to filter before grouping, HAVING is to filter after grouping.An easy way to think of it is HAVING is a where clause for a GROUP BY. |
|
|
kavi12345
Starting Member
19 Posts |
Posted - 2012-03-15 : 03:02:43
|
@russel...thanks dear..kavichakravarthi.R |
|
|
|
|
|