Error en la consulta: select distinct a.ARTICULO PADRE, a.ARTICULO , a.CODIGO, a.DESCRIPCIONWEB, ifnull(g.IMG1, '') IMAGEN , a.FABRICANTE, a.MARCA, ifnull(a.PESO, 0) PESO, a.TIPODEIVA , i.IVA PORCIVA, i.RECARGO PORCRECARGO, i.CODIGO CODIGOIVA, a.FLAG2, a.FLAG4 , a.PUNTOVERDE, a.MER , ifnull(g.ABRIRCAJAS, 'F') ABRIRCAJAS, ifnull(a.UNIDADESPORCAJA, 0) UNIDADESPORCAJA , (a.flag2 & 1 > 0) TIENEDESGLOSE , zf.DESCRIPCION FABRICANTEDESC , fda.ALIAS FABRICANTESDESCALIAS , fda.IMAGEN FABRICANTESIMAGEN , zm.DESCRIPCION MARCADESC , mda.ALIAS MARCADESCALIAS , clsfdrArticulo.FAMILIA, clsfdrArticulo.FAMILIAD, clsfdrArticulo.RAMA, clsfdrArticulo.RAMAD , clsfdrArticulo.CATEGORIA, clsfdrArticulo.CATEGORIAD, clsfdrArticulo.SUBCATEGORIA, clsfdrArticulo.SUBCATEGORIAD , (IFNULL(h.PRECIOBASE, 0)) PRECIO , (IFNULL(h.PRECIOBASE, 0)) PRECIOBASE , (IFNULL(h.PRECIOBASE, 0)) PRECIOINTACTO , IFNULL(h.PRECIOBASE, 0) PRECIOBASEINTACTO , 0 PRECIOCAJA , (IFNULL(hdto.DESCUENTO, 0)) DTOTARIFA , (ifnull(OI.FLAG, 0) & 8 > 0) PREDOMINARATING , case when OD.TIPOOFERTA > 0 then case when OD.TIPOOFERTA = 4 then (IFNULL(TOF.PRECIOBASE, 0) * IFNULL(1-(OD.DESCUENTO/100), 0)) else (IFNULL(OD.PRECIOBASE, 0)) end else 0 end as PRECIOPROMOCION , case when OD.TIPOOFERTA > 0 then case when OD.TIPOOFERTA = 4 then (IFNULL(TOF.PRECIOBASE, 0) * IFNULL(1-(OD.DESCUENTO/100), 0)) else (IFNULL(OD.PRECIOBASE, 0)) end else 0 end as PRECIOBASEPROMOCION ,0 DTORATINGCLIART, 0 PRECIORATINGCLIART ,0 PRECIOBASERATINGCLIART ,0 DTORATINGRAMOART, 0 PRECIORATINGRAMOART ,0 PRECIOBASERATINGRAMOART ,0 DTORATINGCLIGRUPO ,0 DTORATINGRAMOGRUPOTARIFA , 0 STOCK ,1 CANTIDAD from articulos a join ( select temp_clsfdrs.* from articulos temp_a join ( select a.articulo, f.codigo familia, f.descripcion familiaD, 0 rama, '' ramaD, 0 categoria, '' categoriaD, 0 subcategoria, '' subcategoriaD, f.nivel, f.orden from articulosclasificadores a join clasificadores f on a.CLASIFICADOR = f.CODIGO join datoswebclasificadores fa on fa.CLASIFICADOR = f.CODIGO and fa.VER = 'T' where f.nivel = 1 UNION select a.articulo, f.codigo familia, f.descripcion familiaD, r.codigo rama, r.descripcion ramaD, 0 categoria, '' categoriaD, 0 subcategoria, '' subcategoriaD, r.nivel, r.orden from articulosclasificadores a join clasificadores r on a.clasificador = r.codigo join datoswebclasificadores ra on ra.clasificador = r.codigo and ra.ver = 'T' join clasificadores f on f.codigo = r.padre join datoswebclasificadores fa on fa.clasificador = f.codigo and fa.ver = 'T' where r.nivel = 2 UNION select a.articulo, f.codigo familia, f.descripcion familiaD, r.codigo rama, r.descripcion ramaD, c.codigo categoria, c.descripcion categoriaD, 0 subcategoria, '' subcategoriaD, c.nivel, c.orden from articulosclasificadores a join clasificadores c on a.clasificador = c.codigo join datoswebclasificadores ca on ca.clasificador = c.codigo and ca.ver = 'T' join clasificadores r on r.codigo = c.padre join datoswebclasificadores ra on ra.clasificador = r.codigo and ra.ver = 'T' join clasificadores f on f.codigo = r.padre join datoswebclasificadores fa on fa.clasificador = f.codigo and fa.ver = 'T' where c.nivel = 3 UNION select a.articulo, f.codigo familia, f.descripcion familiaD, r.codigo rama, r.descripcion ramaD, c.codigo categoria, c.descripcion categoriaD, s.codigo subcategoria, s.descripcion subcategoriaD, s.nivel, s.orden from articulosclasificadores a join clasificadores s on a.clasificador = s.codigo join datoswebclasificadores sa on sa.clasificador = s.codigo and sa.ver = 'T' join clasificadores c on c.codigo = s.padre join datoswebclasificadores ca on ca.clasificador = c.codigo and ca.ver = 'T' join clasificadores r on r.codigo = c.padre join datoswebclasificadores ra on ra.clasificador = r.codigo and ra.ver = 'T' join clasificadores f on f.codigo = r.padre join datoswebclasificadores fa on fa.clasificador = f.codigo and fa.ver = 'T' where s.nivel = 4 ) as temp_clsfdrs on temp_clsfdrs.articulo = temp_a.articulo group by temp_a.articulo ) clsfdrArticulo on clsfdrArticulo.ARTICULO = a.ARTICULO left join articulosdatosweb g on a.ARTICULO = g.articulo left join tarifas hdto on a.ARTICULO = hdto.articulo and hdto.tarifa = 11 and ( (a.flag2 & 1 <= 0) or ( (a.flag2 & 1 > 0) and (a.flag2 & 2 > 0) ) ) left join tarifas h on a.ARTICULO = h.articulo and h.tarifa = 1 and ( (a.flag2 & 1 <= 0) or ( (a.flag2 & 1 > 0) and (a.flag2 & 2 > 0) ) ) join ivasyrecargos i on a.tipodeiva = i.tipo left join ofertasdesglose OD on OD.ARTICULO = a.ARTICULO and OD.EMPRESA = 0 and OD.ALMACENOFERTA = 999 and OD.TARIFA=1 and OD.FECHAINICIO <= '2019-09-30' and OD.FECHAFINAL >= '2019-09-30' left join ofertasindice OI on OI.ALMACEN = OD.ALMACEN and OI.CODIGO = OD.CODIGO and OI.FECHAINICIO <= '2019-09-30' and OI.FECHAFINAL >= '2019-09-30' left join tarifas TOF on TOF.articulo = OD.ARTICULO and TOF.TARIFA = OD.TARIFA left join vistastocks v on v.articulo = a.articulo and v.empresa = 0 and v.almacen = 0 LEFT JOIN varios zf ON a.FABRICANTE = zf.CODIGO AND zf.GRUPO = 1 LEFT JOIN fabricantesdatosadicionales fda ON fda.CODIGO = zf.CODIGO LEFT JOIN varios zm ON a.MARCA = zm.CODIGO AND zm.GRUPO = 22 LEFT JOIN marcasdatosadicionales mda ON mda.CODIGO = zm.CODIGO where 1 = 1 and articulosRelacionados.RELACION = 1 and ( ( ((IFNULL(h.PRECIOBASE, 0)) > 0) and (CAST(h.PRECIOBASE AS DECIMAL(10, 2)) > 0) and (a.flag2 & 1 = 0) ) or ( a.flag2 & 1 > 0 and (select count(tdes.articulo) from tarifas tdes join desgloses des on tdes.articulo = des.desglose and tdes.preciobase > 0 and tdes.tarifa = 1 where des.articulo = a.articulo) > 0 ) ) and (a.flag1 & 8 = 0) order by ARTICULO desc limit 0, 10000