Full access to SQL syntax (4)

Source: Internet
Author: User
SQL syntax having conditional clause

Specifies a specific grouping record that satisfies the condition or state specified by the having, provided that the condition is set for the grouping.


SELECT FieldList
From table
WHERE Selectcriteria
GROUP by Groupfieldlist
Having GroupCriteria
FieldList
Displays the name of the field being queried. (Can be combined with all,distinct,distinctrow, or top)
Table
The name of the table you want to query for data.
Selectcriteria
Select the criteria.
Groupfieldlist
The field name of the grouped record to 10 more fields. The order of these fields determines the highest to the lowest grouping class.
GroupCriteria
Decide what group records to be displayed.
Having is quite similar to the usage of a where, except that the having must be used on grouped data after the group.
For example:
SELECT Category series, Sum (inventory quantity)
From Product table
GROUP by category number
Having Sum (quantity in stock) >100 and product name like "* paper";


 
GROUP by condition clause

Merges records with the same number into one, based on the specified field.


SELECT FieldList
From table
WHERE criteria
GROUP by Groupfieldlist
FieldList
The name of the field you want to read. (can be used in combination with All,distinct,distinctrow, or top)
Table
The name of the table being queried.
Groupfieldlist
The field name of the grouped record to 10 more fields, and the order of these fields determines the highest to lowest grouping level.
For example:
SELECT name, Count (name) as Employee name
From staff form
WHERE Department name = ' Business unit '
GROUP by name


 
From condition clause

Specifies the table name or query that contains the field data that is listed in the SELECT statement.


SELECT FieldList
From Tableexpression[in Externaldatabase]
FieldList
The name of the field in the table. (Can be combined with all,distinct,distinctrow, or top)
Tableexpression
Table name, or multiple table formulas.
Externaldatabase
If the form is referenced to an external database, write down the full path name.
For example:
From the staff form, query all the data for all last name fields (only the Last Name field is queried, others are not displayed).
SELECT name from staff form;


 
WHERE condition clause

Specify the criteria and restrictions for the query.


SELECT FieldList
From Tableexpression
WHERE criteria
FieldList
The field name. (Can be combined with all,distinct,distinctrow, or top)
Tableexpression
Table name, or multiple table formulas.
Criteria
The results of the query must be in accordance with this limit.
For example:
To query out the employee table, all last names are Li's data, you can use the following statement.
SELECT Name
From staff form
WHERE surname = ' Lee ';

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.