title: Views SELECT contains a subquery in the FROM clause need assistance
body: <p>Hello I've tried making a view but i have this problem, I've researched and found out that i needed to separate the views first, but I found it really hard, and i would gladly need some assistance. </p>
  
  <p>Thanks</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>    SELECT
      coalesce((`rawmat_pallet_ag`.`sheets_pallet` * `rawmat_pallet_ag`.`outs_pallet`),0) AS agpcs,
      coalesce(((`rawmat_pallet`.`no_pallet` * `rawmat_pallet`.`sheets_pallet`) * `rawmat_pallet`.`out_pallet`),0) AS printedpcs,
      coalesce(`rawmat_pcs`.`quantity`,0) AS rawpcs,
      ((coalesce((`rawmat_pallet_ag`.`sheets_pallet` * `rawmat_pallet_ag`.`outs_pallet`),0) + coalesce(((`rawmat_pallet`.`no_pallet` * `rawmat_pallet`.`sheets_pallet`) * `rawmat_pallet`.`out_pallet`),0)) + coalesce(`rawmat_pcs`.`quantity`,0)) AS total,
      rawmaterial.rawmaterial_code AS rawmaterial_code,
      rawmaterial.rawmaterial_desc AS rawmaterial_desc,
      rawmaterial.rawmaterial_id AS raw_id,
      second_view.pending_total,
      COALESCE(total - second_view.pending_total) as available_qty
      FROM
      rawmat_pallet_ag
      RIGHT JOIN rawmaterial
      ON rawmat_pallet_ag.raw_id = rawmaterial.rawmaterial_id 
      LEFT JOIN rawmat_pallet
      ON rawmat_pallet.raw_id = rawmaterial.rawmaterial_id 
      LEFT JOIN rawmat_pcs
      ON rawmat_pcs.raw_id = rawmaterial.rawmaterial_id
      LEFT JOIN (select rawid,sum(first_view.total) as pending_total FROM
      assignedraw LEFT JOIN
      (SELECT 
      jo_main.item_id,
      sum(jo_main.qty) as total
      FROM
      jo_main
      JOIN so_jo
      ON jo_main.jomain_id = so_jo.jomain_id 
      JOIN somain
      ON so_jo.somain_id = somain.salesorder_id
      where somain.`status` = 1
      group by jo_main.item_id) AS first_view 
      ON assignedraw.itemid = first_view.item_id
      group by assignedraw.rawid) as second_view 
      ON rawmaterial.rawmaterial_id = second_view.rawid
      GROUP BY
      `rawmaterial`.`rawmaterial_id`
      ORDER BY
      raw_id ASC</code></pre>
  </div>
  </div>
  </p>