def days_with_errors_query(limit=None):
    """Return an SQL string to qurery for days with many HTTP errors.

    Args:
        limit (int): The maximum number of results to query for.  If
                     ommited, query for all matching results.

    Returns:
        str: An SQL string.  When used in a query, the result will contain
             two columns describing days which had an HTTP response error
             rate of more than 1%:
                 - The date as a string (e.g. "December 31, 2000").
                 - The rate of HTTP requests for that day which did not
                   result in a "200 OK" response (e.g. "1.11% errors").
    """
    return """
        WITH date_errpercent AS (
            SELECT
                    time::date AS date,
                    (
                        -- Count the number of errors on this date
                        sum(CASE WHEN status != '200 OK' THEN 1 ELSE 0 END)
                        -- Calculate percentage compared to the total requests
                        -- Convert from integer so that we get decimal places
                        / count(*)::decimal * 100
                    ) as err_percent
                FROM log
                GROUP BY date
        )
        SELECT
                to_char(date, 'FMMonth FMDD, YYYY') AS date,
                format('%s%% errors', round(err_percent, 2)) AS errors
            FROM date_errpercent
            WHERE err_percent > 1
            ORDER BY err_percent
            LIMIT {number};
    """.format(number=limit or 'ALL')