def antenna_interactions_query(table_name='%(table_name)s'):
    """
    Per each antenna pair which had at least one event occurring, three
    features are being created. Counts of all sms and calls as well as
    the summed up seconds of all calls.

    Inputs
    ------
    table_name : name of the table the query is supposed to run on,
                 defaulting to '%(table_name)s', i.e. no substitution

    Output
    ------
    Dataframe which holds information about interactions between
    each pair of antennas. No more user ids.
    """
    query = """
        SELECT
          antenna_id1,
          antenna_id2,
          SUM(IF(interaction = 'text', 1, NULL)) as sms_count,
          SUM(IF(interaction = 'call', 1, NULL)) as call_count,
          SUM(call_duration) as vol_sum
        FROM
        (
          SELECT
            caller_id,
            correspondent_id,
            uha1.antenna_id as antenna_id1,
            uha2.antenna_id as antenna_id2,
            interaction,
            call_duration
          FROM %(table_name)s rd
          JOIN table_user_home_antenna_df uha1
          -- get home antenna antenna for caller
          ON rd.caller_id = uha1.user_id
          JOIN table_user_home_antenna_df uha2
          -- get home antenna for recipient
          ON rd.correspondent_id = uha2.user_id
        )
        GROUP BY antenna_id1, antenna_id2
    """
    return query % {'table_name': table_name}
