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

# `cube` 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

Creates a multi-dimensional cube using the specified expression columns.

## Syntax

```
cube (expr1 [, ...] )
```

## Arguments

* `exprN`: Any expression that can be grouped.

## Returns

The function must be the only grouping expression in the GROUP BY clause.
See [GROUP BY clause](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-qry-select-groupby.md) for details.

## Examples

```sql
> SELECT name, age, count(*) FROM VALUES (2, 'Alice'), (5, 'Bob') people(age, name) GROUP BY cube(name, age);
  Bob   5       1
  Alice 2       1
  Alice NULL    1
  NULL  2       1
  NULL  NULL    2
  Bob   NULL    1
  NULL  5       1
```

## Related functions

* [GROUP BY clause](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-qry-select-groupby.md)
