DELETE FROM {delete_partition_table_name}
WHERE 1=1
    AND IFF(
        '{partition_start_date}' = '{partition_end_date}',
        p_date = '{partition_start_date}' AND p_hour >= {partition_start_hour} AND p_hour < {partition_end_hour},
        (
            (p_date = '{partition_start_date}' AND p_hour >= {partition_start_hour}) OR
            (p_date > '{partition_start_date}' AND p_date < '{partition_end_date}') OR
            (p_date = '{partition_end_date}' AND p_hour < {partition_end_hour})
        )
    )
