def count_unique(conn, table_name, *columns):
    """Count each unique combination of column values.

    For example, for columns = ["a", "b"] and data
    a  b  c  d
    ----------
    1  1  1  0
    1  1  2  0
    1  1  3  0
    1  2  4  0
    1  2  5  0
    2  2  6  0
    result = [
        # a, b, count
        [1, 1, 3],
        [1, 2, 2],
        [2, 2, 1]
    ]
    """
    return [list(row) for row in conn.execute(
        "SELECT {cols}, count(*) FROM {table_name} GROUP BY {cols}".format(
            cols=", ".join(f"\"{col}\"" for col in columns),
            table_name=table_name,
        )
    ).fetchall()]