SQL HAVING instance and having usage

Source: Internet
Author: User

The SQL having clause is used to limit the output of a conditional SQL statement. It is used by an SQL statement in the SELECT list of your columns.

You cannot specify an SQL standard for which SQL Aggregate functions are used for column terms in the SELECT list. For example, the following SQL statement produces an error:

SELECT Employee, SUM (Hours)
FROM EmployeeHours
Where sum (Hours)> 24
Group by Employee


The SQL statement of the HAVING clause is used for this purpose. To use the specified aggregation function, use the following conditions in your query:

SELECT Employee, SUM (Hours)
FROM EmployeeHours
Group by Employee
Having sum (Hours)> 24

The preceding SQL statement selects the total time of all employees and their respective time, as long as the number is 24 or more. The SQL HAVING Clause shows the following results:

Employee Hours
John Smith 25
Tina Crown 27

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.