title: #1054 unknown column in on clause error
body: <p>I have the following MySQL query:</p>
  <pre><code>SELECT Ychastok_number AS 'Номер участка',podrazdelenie.Name AS Объект,type.Name AS Машина,avto.Marka AS Марка, avto.Gos_number AS 'Гос.Номер', avto.Invent_num AS 'Инвентарный номер', SUM(OtrabotanoMachine_hours) as 'Часов в рабочих сменах',SUM(sec.Hours) as Простои,SUM(TimeRaboty_dvigatelya)AS 'Отработано времени',TRUNCATE((SUM(sec.Hours)/ SUM(OtrabotanoMachine_hours))*100,1) as 'Процент простоев от часов рабочих смен', TRUNCATE((SUM(TimeRaboty_dvigatelya)/ SUM(OtrabotanoMachine_hours))*100,1) as 'Процент работ', CONVERT(group_concat(concat(prostoy.Prichina,'=',sec.Hours) separator ';') USING 'utf8') as 'Причины простоев'
  FROM
  jos_addRabotyAndProstoyMain main
  INNER JOIN avto ON main.Marka=avto.ID_Avto
  INNER JOIN typeconstructionmechanizm type ON main.Machine = type.ID_TypeConstructionMechanizm
  INNER JOIN podrazdelenie ON main.Ychastok = podrazdelenie.ID_Podrazdelenie
  INNER JOIN prostoy ON jos_addRabotyAndProstoySecond.Prostoy = prostoy.ID_Prosyoy
  INNER JOIN (
     SELECT id_fk, SUM(Hours) AS Hours
     FROM jos_addRabotyAndProstoySecond 
     GROUP BY id_fk) sec ON sec.id_fk = main.id
  GROUP BY  Ychastok_number,podrazdelenie.Name,type.Name,avto.Marka,avto.Gos_number,avto.Invent_num
  </code></pre>
  <p>And I'm getting this error:</p>
  <p><strong>#1054 - Unknown column 'jos_addRabotyAndProstoySecond.Prostoy' in 'on clause'</strong></p>
  <p>after adding this row</p>
  <pre><code>INNER JOIN prostoy ON jos_addRabotyAndProstoySecond.Prostoy = prostoy.ID_Prosyoy
  </code></pre>
  <p>how to fix this error?</p>