I need to make a complex mysql query into a Magento collection to present in an admin grid. Query is:
SELECT g.increment_id AS magento_order_number, c.increment_id AS rcs_number, g.created_at AS date_entered, if(o.iorder_salesrep_email IS NOT NULL AND o.iorder_position_id IS NOT NULL, 'iOrder', 'eComm') AS order_system, group_concat(concat(oi.sku,' - ',CAST(oi.qty_ordered AS UNSIGNED))) AS products FROM sales_flat_order_grid g, customer_entity c, sales_flat_order_item oi, sales_flat_order o WHERE g.entity_id = oi.order_id AND c.entity_id = g.customer_id AND o.entity_id = g.entity_id AND o.store_id != 2 GROUP BY g.entity_id;
and i have absolutely no idea how to make it work. So far i have a couple of joins but im pretty far from the expected results. Any suggestions or resources to handle this?