def METHOD_NAME(keys):
    params = []
    for key in keys:
        if key == "nothing":
            pass
        elif key in STATS_COLUMN_WHITELIST or key.startswith("star_pu."):
            params.append(key)
        else:
            raise KeysNotValid("%s is not a valid key" % key)
    if keys:
        # `params` might be empty here because the only key supplied was
        # "nothing", but that's fine: the empty IN clause won't match any rows,
        # which is what we want
        where = "name IN ({})".format(",".join("?" * len(params)))
    else:
        # If no keys are supplied we treat this as an implicit "select all"
        where = "1=1"
    query = "SELECT name, value FROM practice_statistic WHERE {}".format(where)
    # The special "nothing" key always evaluates to 1, but to match the
    # previous API we should only return these "nothing" entries where there
    # exist statistics for that organsation and date. So we use the
    # total_list_size matrix, and only return entries where that has a non-zero
    # value
    if "nothing" in keys:
        query += """
            UNION ALL
            SELECT "nothing" AS name, value
            FROM practice_statistic
            WHERE name="total_list_size"
            """
    return query, params