Home  >  Article  >  Database  >  Comprehensive exposure to SQL syntax (4)

Comprehensive exposure to SQL syntax (4)

黄舟
黄舟Original
2016-12-24 17:46:48942browse

HAVING condition clause

 Specifies a specific group record and meets the conditions or status specified by HAVING, but the condition is set for the group.


SELECT fieldlist
FROM table
WHERE selectcriteria
GROUP BY groupfieldlist
HAVING groupcriteria
fieldlist
Displays the queried field name. (Can be combined with ALL, DISTINCT, DISTINCTROW, or TOP)
table
The name of the table to query the data.
selectcriteria
Select criteria.
groupfieldlist
Field names of group records, up to 10 fields. The order of these fields determines the highest to lowest grouping hierarchy.
groupcriteria
Determines what kind of group records should be displayed.
HAVING is quite similar to WHERE in usage. The difference is that HAVING must be used on the grouped data after GROUP.
For example:
SELECT category number, Sum (inventory quantity)
FROM product table
GROUP BY category number
HAVING Sum (inventory quantity) >100 AND product name LIKE "*paper";


 
GROUP BY condition clause

  Based on the specified field, merge records with the same value into one.


SELECT fieldlist
FROM table
WHERE criteria
GROUP BY groupfieldlist
fieldlist
The name of the field to be 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 group record, up to 10 fields, and the order of these fields determines the highest to lowest grouping level.
For example:
SELECT name, Count (name) AS employee name
FROM employee table
WHERE department name = 'Business Department'
GROUP BY name


 
 FROM condition clause

Specify the table name or query, which contains The field data listed in the SELECT statement.


SELECT fieldlist
FROM tableexPRession[IN externaldatabase]
fieldlist
Field names in the table. (Can be combined with ALL, DISTINCT, DISTINCTROW, or TOP)
tableexpression
Table name, or calculations for multiple tables.
externaldatabase
If the table refers to an external database, write down its complete path name.
For example:
Query the data of all name fields from the employee table (only the name field is queried, and the others are not displayed).
SELECT name FROM employee table;


 
  WHERE condition clause

Specify the conditions and restrictions of the query.


SELECT fieldlist
FROM tableexpression
WHERE criteria
fieldlist
field name. (Can be combined with ALL, DISTINCT, DISTINCTROW, or TOP)
tableexpression
Table name, or calculations for multiple tables.
criteria
The results of the query must comply with this restriction.
For example:
To query all the data whose last name is Li in the employee table, you can use the following statement.
SELECT Name
FROM Staff Form
WHERE Last Name='Li';

The above is the content of comprehensive contact with SQL syntax (4). For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn