Home > Database > Oracle > body text

The difference between sum and count in oracle

下次还敢
Release: 2024-05-02 23:09:52
Original
532 people have browsed it

Oracle 中的 SUM 用于计算非空数值的总和,而 COUNT 则计入所有数据类型的非空值数量,包括重复值。

The difference between sum and count in oracle

Oracle 中 SUM 和 COUNT 的区别

开门见山

Oracle 中的 SUM 和 COUNT 是两个聚合函数,用于对数据集执行计算,但它们服务于不同的目的。

详细论述

SUM

  • 计算指定列中所有非 NULL 值的总和。
  • 对于数值数据类型(如整数、浮点数)有效。
  • 语法:SUM(column_name)

COUNT

  • 计数指定列中非 NULL 值的数量,包括重复值。
  • 对于所有数据类型有效。
  • 语法:COUNT(column_name)

отличия

  • 目的:SUM 计算总和,COUNT 计数值。
  • 数据类型:SUM 适用于数值数据,而 COUNT 适用于所有数据类型。
  • 重复值:COUNT 计数重复值,而 SUM 只计算非重复值的总和。
  • NULL 值:SUM 忽略 NULL 值,而 COUNT 将它们计数为 0。

举个例子

假设有一个名为 "Invoices" 的表,其中包含以下数据:

<code>| InvoiceNumber | Product | Price |
|---|---|---|
| 1001 | Chair | $100 |
| 1002 | Book | $20 |
| 1003 | Table | $150 |
| 1004 | Chair | $100 |
| 1005 | NULL | $50 |</code>
Copy after login
  • SUM(Price) 返回总价格:$520
  • COUNT(Product) 返回产品数量:5
  • COUNT(InvoiceNumber) 返回发票数量:5(尽管发票 1005 中的 Product 为 NULL)

结论

Oracle 中的 SUM 和 COUNT 函数提供了对数据集的不同聚合视图。SUM 计算总和,而 COUNT 计数值,即使是重复值。了解这两种函数之间的区别对于从 Oracle 数据库中提取有意义的信息至关重要。

The above is the detailed content of The difference between sum and count 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!