2023-01-10 06:42:39 +00:00
---
slug: /en/sql-reference/aggregate-functions/reference/contingency
2024-06-24 11:52:30 +00:00
sidebar_position: 116
2023-01-10 06:42:39 +00:00
---
# contingency
2023-03-18 02:45:43 +00:00
The `contingency` function calculates the [contingency coefficient ](https://en.wikipedia.org/wiki/Contingency_table#Cram%C3%A9r's_V_and_the_contingency_coefficient_C ), a value that measures the association between two columns in a table. The computation is similar to [the `cramersV` function ](./cramersv.md ) but with a different denominator in the square root.
2023-01-10 06:42:39 +00:00
**Syntax**
``` sql
contingency(column1, column2)
```
**Arguments**
2023-04-19 15:55:29 +00:00
- `column1` and `column2` are the columns to be compared
2023-01-10 06:42:39 +00:00
**Returned value**
2024-02-13 01:10:41 +00:00
- a value between 0 and 1. The larger the result, the closer the association of the two columns.
2023-01-10 06:42:39 +00:00
**Return type** is always [Float64 ](../../../sql-reference/data-types/float.md ).
**Example**
2023-01-10 14:55:59 +00:00
The two columns being compared below have a small association with each other. We have included the result of `cramersV` also (as a comparison):
2023-01-10 06:42:39 +00:00
``` sql
SELECT
cramersV(a, b),
contingency(a ,b)
FROM
(
SELECT
number % 10 AS a,
number % 4 AS b
FROM
numbers(150)
);
```
Result:
```response
┌──────cramersV(a, b)─┬───contingency(a, b)─┐
│ 0.41171788506213564 │ 0.05812725261759165 │
└─────────────────────┴─────────────────────┘
2024-02-13 01:10:41 +00:00
```