| Aggregate (cost=520.87..520.88 rows=1 width=8) |
| -> Sort (cost=490.90..495.90 rows=1998 width=1018) |
| Sort Key: (COALESCE(curr.erp_revenue, '0'::numeric)) DESC NULLS LAST |
| -> Hash Join (cost=267.13..381.37 rows=1998 width=1018) |
| Hash Cond: (c.id = curr.client_id) |
| -> Seq Scan on tbl_clients c (cost=0.00..108.98 rows=1998 width=12) |
| Filter: (NOT deleted) |
| -> Hash (cost=242.16..242.16 rows=1998 width=36) |
| -> Subquery Scan on curr (cost=177.22..242.16 rows=1998 width=36) |
| -> HashAggregate (cost=177.22..222.18 rows=1998 width=68) |
| Group Key: c_1.id |
| Filter: ((COALESCE(sum(o.outbound_amount), '0'::numeric) + COALESCE(sum(eoi.amount), '0'::numeric)) > '0'::numeric) |
| -> Hash Left Join (cost=32.76..152.25 rows=1998 width=68) |
| Hash Cond: (c_1.id = eoi.client_id) |
| -> Hash Left Join (cost=29.23..143.47 rows=1998 width=36) |
| Hash Cond: (c_1.id = o.client_id) |
| -> Seq Scan on tbl_clients c_1 (cost=0.00..108.98 rows=1998 width=4) |
| Filter: (NOT deleted) |
| -> Hash (cost=28.15..28.15 rows=87 width=36) |
| -> Subquery Scan on o (cost=26.19..28.15 rows=87 width=36) |
| -> HashAggregate (cost=26.19..27.28 rows=87 width=68) |
| Group Key: t.client_id |
| -> Hash Right Join (cost=10.05..24.20 rows=397 width=9) |
| Hash Cond: (eipss.erp_sales_outbound_id = t.id) |
| -> Seq Scan on tbl_erp_inventory_product_spents eipss (cost=0.00..12.65 rows=565 width=9) |
| -> Hash (cost=8.36..8.36 rows=135 width=8) |
| -> Seq Scan on tbl_erp_sales_outbounds t (cost=0.00..8.36 rows=135 width=8) |
| Filter: ((client_id IS NOT NULL) AND (created_at >= '2025-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2025-12-31 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> Hash (cost=3.49..3.49 rows=3 width=36) |
| -> Subquery Scan on eoi (cost=3.42..3.49 rows=3 width=36) |
| -> HashAggregate (cost=3.42..3.46 rows=3 width=36) |
| Group Key: t_1.client_id |
| -> Seq Scan on tbl_erp_other_income_tickets t_1 (cost=0.00..3.40 rows=4 width=10) |
| Filter: ((client_id IS NOT NULL) AND (created_at >= '2025-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2025-12-31 23:59:59+08'::timestamp with time zone) AND (status = 2)) |