List:Spanish« Previous MessageNext Message »
From:Juan Vallini Date:November 15 2011 3:43am
Subject:SubQuery en View
View as plain text  
Foro:

        Estoy tratando de hacer un left join con un select en MySQL, desde el Query
Browser y anda perfecto, pero cuando lo quiero llevar a un View me da error:

        Como que no esta permitido un Subquery desde el FROM.

        Aqui dejo la consulta.    

        El que tenga una idea mejor, sera agradecido.

SELEC
  f.idFactura AS idFactura,f.Fecha AS Fecha,f.idTipoDocumentos AS IDTipoDocumentos,
  td.TipoDocumento AS TipoDocumento, td.NombreInterno AS NombreInterno, f.Letra AS Letra,
  f.PuntoDeVenta AS PuntoDeVenta, f.NroComprobante AS NroComprobante,  f.idClientes AS
idClientes,
  f.NombreParaImprimir AS NombreParaImprimir, c.Direccion AS Direccion,
  c.Telefono AS Telefono, c.CodigoPostal AS CodigoPostal, c.Localidad AS Localidad,
c.`E-Mail` AS Email,
  c.idTipoIva AS idTipoIva, ti.TipoIva AS TipodeIva, def.Porcentaje1 AS Porcentaje1, 
def.Descuento1 AS Descuento1,
  ifv.Iva105 AS Iva105,
  ifv.Iva210 AS Iva210,
  ifv.Iva270 AS Iva270,
  f.Subtotal AS SubTotal,
  FDetalleTotal.TotalIvaDetalle as TotalDelDetalle,
#  if((def.Porcentaje1 > 0),(f.Subtotal - def.Descuento1),f.Subtotal) AS
SubTotalCDescuento,
#  if((def.Porcentaje1 > 0),(TotalPorDetalle.TotalFDetalle -
def.Descuento1),f.Subtotal) AS SubTotalCDescuento,
  if((ifv.Iva105 > 0),(ifv.Iva105),0) AS SubTotalCIva105,
  if((ifv.Iva210 > 0),(ifv.Iva210),0) AS SubTotalCIva210,
  if((ifv.Iva270 > 0),(ifv.Iva270),0) AS SubTotalCIva270,
  if((def.Porcentaje1 > 0),(f.Subtotal - def.Descuento1),f.Subtotal) +   if((ifv.Iva105
> 0),(ifv.Iva105),0) + if((ifv.Iva105 > 0),(ifv.Iva105),0) + if((ifv.Iva105 >
0),(ifv.Iva105),0) AS TotalCIva,
  f.Total AS Total
  FROM Factura f
    INNER JOIN clientes c on F.idClientes = c.idClientes
    INNER JOIN tipodocumentos td on F.idTipoDocumentos=td.idTipoDocumentos
    LEFT JOIN tipoiva ti on c.idTipoIva=ti.idTipoIva
    LEFT JOIN Descuentoenfactura def on f.idFactura=def.idFactura
    LEFT JOIN ivafacturaventa ifv on f.idFactura = ifv.idFactura
    LEFT JOIN (SELECT FD.idFactura, SUM(FD.TotalIva) TotalIvaDetalle FROM FDetalle FD
GROUP BY FD.idFactura) AS FDetalleTotal ON F.idFactura=FDetalleTotal.idFactura;
Thread
SubQuery en ViewJuan Vallini15 Nov