The SQL HAVING clause is used to restrict conditionally the output of a SQL statement, by a SQL aggregate function used in your SELECT list of columns.
You can't specify criteria in a SQL WHERE clause against a column in the SELECT list for which SQL aggregate function is used. For example the following SQL statement will generate an error:
SELECT Employee, SUM (Hours)
FROM EmployeeHours
WHERE SUM (Hours) > 24
GROUP BY Employee
The SQL HAVING clause is used to do exactly this, to specify a condition for an aggregate function which is used in your query:
SELECT Employee, SUM (Hours)
FROM EmployeeHours
GROUP BY Employee
HAVING SUM (Hours) > 24
The above SQL statement will select all employees and the sum of their respective hours, as long as this sum is greater than 24. The result of the SQL HAVING clause can be seen below:
Employee Hours
John Smith 25
Tina Crown 27
Popular Posts
-
Now I will show you how to retrieve the data posted from a HTML file in a JSP page. Consider an html page that prompts the user to enter his...
-
SYMBOLIC CONSTANTS OR MACRO: In this #define is a macro used for a constant value to be assigned in the program. for example: pi its value i...
-
SQL aliases can be used with database tables and with database table columns, depending on task you are performing. SQL column aliases are u...
-
SQL Replication term describes a group of technologies allowing information distribution and mirroring between different databases. SQL repl...
-
JSP pages are high level extension of servlet and it enable the developers to embed java code in html pages. JSP files are finally compiled ...
-
Preprocessor directives Preprocessor directives are lines included in the code of our programs that are not program statements but directive...
-
ADO .NET Most applications need data access at one point of time making it a crucial component when working with applications. Data access i...
-
The Command Button's KeyPress, KeyDown and KeyUp Events The events that will be mentioned in the following pages are commonly used, and ...
-
Getting Started (Continue) Look at the form with the title bar Form1. This is how your program will look like. Everything you will place on ...
-
Advantages of MS Access MS Access is a light weight database managements system. Also, it provides it's own designer so that you can gen...
No comments:
Post a Comment