---
title: grouping function
description: Learn the syntax of the grouping function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/grouping
---

# `grouping` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime

Indicates whether a specified column in a `GROUPING SET`, `ROLLUP`, or `CUBE` represents a subtotal.

## Syntax

```
grouping(col)
```

## Arguments

* `col`: A column reference identified in a `GROUPING SET`, `ROLLUP`, or `CUBE`.

## Returns

An INTEGER.

The result is 1 for a specified row if the row represents a subtotal over the grouping of `col`, or 0 if it is not.

## Examples

```sql
> SELECT name, grouping(name), sum(age) FROM VALUES (2, 'Alice'), (5, 'Bob') people(age, name) GROUP BY cube(name);
  Alice 0   2
  Bob   0   5
  NULL  1   7
```

## Related functions

* [`grouping_id` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/grouping_id.md)
