QUERY PLAN
Aggregate (cost=149.20..149.21 rows=1 width=32)
-> Nested Loop Anti Join (cost=78.62..149.19 rows=1 width=6)
Join Filter: (t.id = t_1.purchase_contract_id)
-> Seq Scan on tbl_purchase_contracts t (cost=0.00..70.54 rows=1 width=10)
Filter: ((NOT is_draft) AND (NOT is_refuse) AND (created_at >= '2025-12-23 10:37:28+08'::timestamp with time zone))
-> GroupAggregate (cost=78.62..78.63 rows=1 width=12)
Group Key: t_1.purchase_contract_id
-> Sort (cost=78.62..78.62 rows=1 width=4)
Sort Key: t_1.purchase_contract_id
-> Seq Scan on tbl_erp_purchase_orders t_1 (cost=0.00..78.61 rows=1 width=4)
Filter: ((cancel_at >= '2025-12-23 10:37:28+08'::timestamp with time zone) AND (cancel_at <= '2025-12-31 23:59:59+08'::timestamp with time zone) AND (status = 8))