QUERY PLAN
Sort (cost=0.21..0.21 rows=1 width=567)
Sort Key: (CASE WHEN (c.sales_rep IS NULL) THEN 0 ELSE 1 END) DESC
-> HashAggregate (cost=0.00..0.20 rows=1 width=567)
Group Key: c.id, cl.id, CASE WHEN (p.client_id IS NULL) THEN false ELSE true END, sl.lost_contact_days, sl.last_contact
-> Result (cost=0.00..0.00 rows=0 width=571)
One-Time Filter: false