| Author: Natarajan.M 02 Sep 2007 | Member Level: Gold | Rating:  Points: 2 |
What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?
Specifies a search condition for a group or an aggregate. HAVING can be used only with the SELECT statement. HAVING is typically used in a GROUP BY clause. When GROUP BY is not used, HAVING behaves like a WHERE clause. Having Clause is basically used only with the GROUP BY function in a query. WHERE Clause is applied to each row before they are part of the GROUP BY function in a query. HAVING criteria is applied after the the grouping of rows has occurred
ORDER BY Clause : Specifies the sort for the result set. The ORDER BY clause is invalid in views, inline functions, derived tables, and subqueries, unless TOP is also specified.
COMPUTE Clause : Generates totals that appear as additional summary columns at the end of the result set. When used with BY, the COMPUTE clause generates control-breaks and subtotals in the result set. You can specify COMPUTE BY and COMPUTE in the same query.
In the following example, the SELECT statement uses a simple COMPUTE clause to produce a grand total of the sum of the SubTotal and TotalDue from the SalesOrderHeader table.
SELECT CustomerID, OrderDate, SubTotal, TotalDue FROM Sales.SalesOrderHeader WHERE SalesPersonID = 35 ORDER BY OrderDate COMPUTE SUM(SubTotal), SUM(TotalDue);
|
| Author: sathiyasivam 02 Sep 2007 | Member Level: Diamond | Rating:  Points: 2 |
hi varma
I suggest this blog
http://blog.sqlauthority.com/2007/04/17/sql-server-interview-questions-part-3/
Regards Sathiya
|