Wednesday, January 26, 2011

SQL: Where clause with group By..

We can use where clause with group by.

In that case first the where clause will apply to the statement and after filtering it Group by will grouped it. And further if we want to use Having to further filter it we can use.

here is small snippet for the same :

Select employee_ID , Max(sale)from Employee_Sale where Sale > 10000 group by employee_ID

Now the above statement with Having clause :

Select employee_ID , Max(sale)from Employee_Sale where sale > 10000 group by employee_ID having sum(sale) > 50000

Cheers

No comments:

Post a Comment