---
title: "SQL SERVER 中一些聚合函数的一些小常识"
author: "prodigy2008"
date: "2009-09-25T10:27:44Z"
tags: []
slug: "sql-server"
draft: false
lastmod: "2009-09-25T10:27:44Z"
id: 477047
url: "https://prodigy2008.iteye.com/blog/477047"
---

聚合函数:

SUM、AVG、COUNT、MAX 和 MIN 忽略空值，而 COUNT(*) 不忽略。
可选关键字 DISTINCT 可以与 SUM、AVG 和 COUNT 一同使用，以便在应用聚合函数之前消除重复值（默认为 ALL）。
SUM 和 AVG 只能对数字列使用，例如 int、smallint、tinyint、decimal、numeric、float、real、money 和 smallmoney 数据类型。MIN 和 MAX 不能对 bit 数据类型使用。除 COUNT(*) 外，其它聚合函数均不能对 text 和 image 数据类型使用。
除了上述例外情况，聚合函数可以对任何类型的列使用。