def METHOD_NAME(self):
    filters = [self.direction.get_filter_clause("A")]
    if self.exclude_self_calls:
        filters.append("A.subscriber != A.msisdn_counterpart")
    on_filters = make_where(filters)
    sql = f"""
    SELECT
        U.subscriber AS subscriber,
        {self.statistic:D.value} AS value
    FROM
        (
            SELECT A.subscriber, A.location_id AS location_id_from, B.location_id AS location_id_to FROM
            ({self.unioned_from_query.get_query()}) AS A
            JOIN ({self.unioned_to_query.get_query()}) AS B
            ON A.id = B.id AND A.outgoing != B.outgoing {on_filters}
        ) U
    JOIN
        ({self.distance_matrix.get_query()}) D
    USING (location_id_from, location_id_to)
    GROUP BY U.subscriber
    """
    return sql