Home  >  Article  >  Database  >  count usage in oracle

count usage in oracle

下次还敢
下次还敢Original
2024-05-02 23:48:58947browse

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.

count usage in oracle

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:

  • DISTINCT: Indicates that only non-duplicate values ​​are counted.
  • ALL: Indicates counting all values, including duplicate values.
  • expression: The expression or column to be counted.

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!

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