Tengo este SQL en Firebird 2.5, y me piden añadir el último precio, pero observo que no existe la instrucción Last.
Código Delphi
[-]procedure TfrPcons1Cli.btAceptarClick(Sender: TObject);
begin
IbDtsV.Close;
IbDtsV.SelectSQL.Clear;
IbDtsV.SelectSQL.Add('Select Max(Codclient) as Codclient, Max(Fecha) as Fecha, ');
IbDtsV.SelectSQL.Add('Producto, Sum(Unidades) as Unidades,');
IbDtsV.SelectSQL.Add('Max(Precio) as Precio, Sum(Subtotal) as Subtotal, ');
IbDtsV.SelectSQL.Add('Avg(Precio) as PMedio, Min(Precio) as MPrecio');
IbDtsV.SelectSQL.Add('from LineasVentas');
IbDtsV.SelectSQL.Add('Where Codclient = :C');
IbDtsV.SelectSQL.Add('And Fecha between :F1 and :F2');
IbDtsV.SelectSQL.Add('Group By Producto');
IbDtsV.SelectSQL.Add('Having Sum(Unidades) <> 0');
IbDtsV.SelectSQL.Add('Order by Producto');
IbDtsV.ParamByName('C').AsString:=IbDTSCliCodigo.Value;
IbDtsV.ParamByName('F1').AsDate:=DateOf(DtpkIni.Date);
IbDtsV.ParamByName('F2').AsDate:=DateOf(DtpkFin.Date);
IbDtsV.open;
end;
Quisiera:
Código Delphi
[-]procedure TfrPcons1Cli.btAceptarClick(Sender: TObject);
begin
IbDtsV.Close;
IbDtsV.SelectSQL.Clear;
IbDtsV.SelectSQL.Add('Select Max(Codclient) as Codclient, Max(Fecha) as Fecha, ');
IbDtsV.SelectSQL.Add('Producto, Sum(Unidades) as Unidades,');
IbDtsV.SelectSQL.Add('Max(Precio) as Precio, Sum(Subtotal) as Subtotal, ');
IbDtsV.SelectSQL.Add('Avg(Precio) as PMedio, Min(Precio) as MPrecio,');
IbDtsV.SelectSQL.Add('Last(Precio) as UltimoP');
IbDtsV.SelectSQL.Add('from LineasVentas');
IbDtsV.SelectSQL.Add('Where Codclient = :C');
IbDtsV.SelectSQL.Add('And Fecha between :F1 and :F2');
IbDtsV.SelectSQL.Add('Group By Producto');
IbDtsV.SelectSQL.Add('Having Sum(Unidades) <> 0');
IbDtsV.SelectSQL.Add('Order by Producto');
IbDtsV.ParamByName('C').AsString:=IbDTSCliCodigo.Value;
IbDtsV.ParamByName('F1').AsDate:=DateOf(DtpkIni.Date);
IbDtsV.ParamByName('F2').AsDate:=DateOf(DtpkFin.Date);
IbDtsV.open;
end;
Un Saludo.