def rank_by_bill_count_query(params):
    """
     To obtain SQL query to rank states based on number of bills.

    :param start_year: (str)
    :param end_year: (str)
        The years between which we get all the bills
    :return:
    A string have the SQL query for the task   
    """
    query = f"""
        select st.state_id, state_abbreviation, count(bill_id), ROW_NUMBER() over(
        order by count(bill_id) desc)as rank from
        (select bill_id, b.session_id, state_id, to_char(introduced_date, 'YYYY') as year
        from ml_policy_class.bills b
        join ml_policy_class.sessions s
        on b.session_id = s.session_id
        where to_char(introduced_date, 'YYYY') >= {params['start_year']} and to_char(introduced_date, 'YYYY') <= {params['end_year']}) as table1
        join catalogs.states st
        on table1.state_id = st.state_id
        group by st.state_id,state_abbreviation
        order by count desc;
        """
    return query