我有以下MySQL查询:
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
我收到了这个错误:
#1054 - 'on clause'中的未知列'jos_addRabotyAndProstoySecond.Prostoy'
添加此行后
INNER JOIN prostoy ON jos_addRabotyAndProstoySecond.Prostoy = prostoy.ID_Prosyoy
如何解决此错误?
答案 0 :(得分:1)
您没有包含别名或名称jos_addRabotyAndProstoySecond
的表格。因此该栏目未知。
事实上,除了子查询之外,查询中根本没有此表的证据。你可以:
FROM
子句join
放入子查询目前还不清楚你想要完成什么;所以很难提出具体的建议。