The COUNT function is used to count the number of rows in the table that meet the conditions. Syntax: COUNT(DISTINCT|ALL expression); where: DISTINCT counts unique values, ALL counts all values. Usage includes counting the number of all rows, the number of non-null values in a specific column, the number of rows that meet the condition, and the number of unique values.
Usage of COUNT function in Oracle
The COUNT function is an important aggregate function in Oracle and is used for statistics The number of rows in the table that meet certain criteria.
Syntax
<code>COUNT(DISTINCT|ALL expression)</code>
Among them:
Usage
The COUNT function is used to count the number of rows under specific conditions, for example:
All statistics in the table Number of rows:
<code>SELECT COUNT(*) FROM table_name;</code>
Count the number of non-null values in a specific column:
<code>SELECT COUNT(column_name) FROM table_name;</code>
Count the number of rows that meet specific conditions:
<code>SELECT COUNT(*) FROM table_name WHERE condition;</code>
Count the number of unique values in a specific column:
<code>SELECT COUNT(DISTINCT column_name) FROM table_name;</code>
Example
Suppose there is a The table named "employees" contains the following data:
<code>| emp_id | name | salary | |---|---|---| | 1 | John Doe | 10000 | | 2 | Jane Smith | 12000 | | 3 | John Green | 10000 | | 4 | Mary Jones | 15000 |</code>
Count the number of all rows in the table:
<code>SELECT COUNT(*) FROM employees;</code>
Result: 4
Count the number of non-null values in the "salary" column:
<code>SELECT COUNT(salary) FROM employees;</code>
Result: 4
Statistics the number of unique values in the "emp_id" column:
<code>SELECT COUNT(DISTINCT emp_id) FROM employees;</code>
Result: 4
Statistics on the number of values greater than 11000 in the "salary" column:
<code>SELECT COUNT(*) FROM employees WHERE salary > 11000;</code>
Result: 2
The above is the detailed content of count usage in oracle. For more information, please follow other related articles on the PHP Chinese website!