QUERY PLAN
HashAggregate (cost=149.10..152.37 rows=218 width=76)
Group Key: gb.id
-> Hash Left Join (cost=130.87..146.47 rows=263 width=21)
Hash Cond: (prod.product_brand = gb.id)
-> Hash Join (cost=122.97..137.86 rows=263 width=13)
Hash Cond: (sp.product_id = prod.id)
-> Hash Join (cost=24.25..38.45 rows=263 width=13)
Hash Cond: (eipss.erp_sales_outbound_spent_product_id = sp.id)
-> Hash Join (cost=11.00..24.51 rows=263 width=13)
Hash Cond: (eipss.erp_sales_outbound_id = t.id)
-> Seq Scan on tbl_erp_inventory_product_spents eipss (cost=0.00..12.51 rows=374 width=17)
Filter: (erp_sales_outbound_spent_product_id IS NOT NULL)
-> Hash (cost=9.66..9.66 rows=107 width=4)
-> Seq Scan on tbl_erp_sales_outbounds t (cost=0.00..9.66 rows=107 width=4)
Filter: ((created_at >= '2025-08-05 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=8.11..8.11 rows=411 width=8)
-> Seq Scan on tbl_erp_sales_outbound_spent_products sp (cost=0.00..8.11 rows=411 width=8)
-> Hash (cost=72.21..72.21 rows=2121 width=8)
-> Seq Scan on tbl_products prod (cost=0.00..72.21 rows=2121 width=8)
-> Hash (cost=5.18..5.18 rows=218 width=12)
-> Seq Scan on tbl_product_brands gb (cost=0.00..5.18 rows=218 width=12)