# contingency (/docs/reference/sql/aggregate-functions/contingency)



This page describes the RawTree engine binary used to generate this reference. It does not define Query API support. Descriptions retain upstream ClickHouse terminology. See [SQL interface scope](/docs/reference/clickhouse-compatibility#service-interfaces).

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`](/reference/functions/aggregate-functions/cramersV) function but with a different denominator in the square root.

**Syntax**

```sql
contingency(column1, column2)
```

**Arguments**

* `column1` — First column to compare. [`Any`](/reference/data-types)
* `column2` — Second column to compare. [`Any`](/reference/data-types)

**Returned value**

Returns a value between 0 and 1. The larger the result, the closer the association of the two columns. [`Float64`](/reference/data-types/float)

**Examples**

**Comparison with cramersV**

```sql title=Query
SELECT
    cramersV(a, b),
    contingency(a, b)
FROM
(
    SELECT
        number % 10 AS a,
        number % 4 AS b
    FROM
        numbers(150)
);
```

```text title=Response
┌─────cramersV(a, b)─┬──contingency(a, b)─┐
│ 0.5798088336225178 │ 0.708607540104077  │
└────────────────────┴────────────────────┘
```

*Introduced in version 22.1.0.*
