can someone help me how to convert this to query builder . I am confuse why does Cakephp remove this features . I cant change my database structure because of thousand of records .
SELECT * FROM (
SELECT Saving.id, Saving.code, Saving.ssa, Saving.saving_type_id, SavingSub.code as holder, SavingSub.rate, Saving.terms, CONCAT(Member.lastName, ', ', Member.firstName,',', IFNULL(CONCAT(' ',Member.middleName), '')) as name, Member.code as member_code, TotalAmount.total as amount, Saving.joint_member_id as member2, Member.address FROM savings as Saving LEFT JOIN saving_subs as SavingSub on SavingSub.saving_id = Saving.id LEFT JOIN members as Member on Member.id = Saving.member_id LEFT JOIN ( SELECT Saving.id, SUM(IFNULL(Saving.interest,0)) + SUM(IFNULL(CASE SavingSub.type when '1' AND SavingSub.interest <= 0 then SavingSub.amount else 0 end,0)) + SUM(IFNULL(CASE SavingSub.type when '1' AND SavingSub.interest > 0 then SavingSub.interest else 0 end,0)) - SUM(IFNULL(CASE SavingSub.type when '0' then SavingSub.amount else 0 end,0)) - SUM(IFNULL(Saving.interest,0)) as total FROM savings as Saving left join saving_subs as SavingSub On SavingSub.saving_id = Saving.id where Saving.visible = true and SavingSub.visible = true group by Saving.id ) as TotalAmount on TotalAmount.id = Saving.id WHERE Saving.visible = true and SavingSub.visible = true and Member.visible = true and group by Saving.id ) as Member