Convert MySQL SELECT query containing JOINed subqueries into CodeIgniter's query builder
03:02 01 Feb 2018

How can I convert this MySQL query into a CodeIgniter query builde script?

SELECT
    p.*,
    s.product_id,
    sum(s.quantity) as st,
    sumq,
    sum(s.quantity) - sumq as a,
    concat (prod_desc,' ',brand_name) as names
from stocks s
join (
    select product_id, sum(quantity) sumq 
    from order_details
    group by product_id
) o on s.product_id = o.product_id
join (
    select * from products
) p on p.prod_id = s.product_id 
join (
    select * from brand
) b on b.brand_id = p.brand_id
group by product_id having a >= 1
php codeigniter join subquery query-builder