Home > Database > Oracle > How to use count function in oracle

How to use count function in oracle

下次还敢
Release: 2024-04-30 07:39:13
Original
896 people have browsed it

The COUNT function in Oracle is used to count non-null values ​​in a specified column or expression. The syntax is COUNT(DISTINCT ) or COUNT(*), which calculates unique values ​​and all non-null values ​​respectively. number.

How to use count function in oracle

Usage of COUNT function in Oracle

The COUNT function is used to calculate non-null values ​​in the specified column or expression. number. The syntax is as follows:

<code class="sql">COUNT(DISTINCT <column_name>)
COUNT(*)</code>
Copy after login

Parameter description:

  • DISTINCT : Only count the unique values ​​in the specified column number.
  • *: Count the number of all non-null values.

Usage example:

  • Count the number of non-null values ​​in a specific column:
<code class="sql">SELECT COUNT(DISTINCT employee_id)
FROM employees;</code>
Copy after login
  • Calculate the number of all non-null values ​​in the table:
<code class="sql">SELECT COUNT(*)
FROM employees;</code>
Copy after login
  • Calculate the number of non-null values ​​for specific conditions :
<code class="sql">SELECT COUNT(DISTINCT employee_id)
FROM employees
WHERE salary > 50000;</code>
Copy after login

Note:

  • The COUNT function ignores NULL values.
  • COUNT(*) counts all non-null values, including duplicates.
  • COUNT(DISTINCT ) will only count unique values.
  • The COUNT function can be used with other aggregate functions such as SUM, AVG.

The above is the detailed content of How to use count function in oracle. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template