if someone could help to add some statement in this query that would eliminate duplicate if their status are both canceled. Highligted in the image below of the sample that i don't want to appear in my query results.
with cte0 AS
(
SELECT * FROM efleet_copy AS e1
INNER JOIN
(SELECT mta_id, COUNT(mta_id) FROM efleet_copy WHERE EXTRACT(MONTH FROM service_date) = 02 AND mta_id LIKE '_________'
GROUP BY mta_id HAVING COUNT(mta_id) > 1) AS e2
ON e1.mta_id = e2.mta_id
WHERE EXTRACT(MONTH FROM service_date) = 02
ORDER BY e1.mta_id ASC, e1.ride_id ASC, e1.trip_number ASC
)
SELECT * FROM cte0 c
WHERE NOT EXISTS (
SELECT 1 FROM cte0 ci
WHERE c.ride_id = ci.ride_id
AND status = 'Approved'
GROUP BY ride_id
HAVING SUM(trip_total_amount) = 0::money
)
order number
,order status
, ...