Home Forums SQL Server 7,2000 T-SQL excluding fields in my SELECT from the GROUP BY clause RE: excluding fields in my SELECT from the GROUP BY clause

  • Hello

    Replie for Antares686 as requested :

     

    Ndoc Nmdoc Codigo Qt Pv Valor Valor_custo Desc Margem Comissão
    1 Factura              20180ANB-1         1256 8,35 10487,6 7787,2 0+0                   25,7486
    1 Factura              20180ANB-2         2400 8,35 20040 14880 0+0                   25,7486
    1 Factura              22520ANB-1         1500 8,25 12375 8572,5495 0+0                   30,7269
    1 Factura              22520ANB-2         1500 8,25 12375 8580 0+0                   30,6667
    1 Factura              24020ANB-1         2500 5 12500 8581,8525 0+0                   31,3452
    1 Factura              24020ANB-1         3100 5,5 17050 10641,4971 0+0                   37,5866
    1 Factura              24040ANB-1         1300 8 10400 6290,6701 0+0                   39,5128
    1 Factura              24040ANB-2         1200 8 9600 6120 0+0                   36,25
    1 Factura              24040ANB-3         860 8 6880 4162,4 0+0                   39,5
    1 Factura              24040ANB-4         1500 8 12000 7650 0+0                   36,25
    1 Factura              24520ANB01-04      3100 6 18600 11791,0701 0+0                   36,6072
    1 Factura              27640ANB-1         420 6 2520 1377,6 0+0                   45,3334
    1 Factura              27640ANB-2         1290 6 7740 4231,2 0+0                   45,3334
    1 Factura              27670ANB-1         3200 6 19200 9123,9296 0+0                   52,4796
    1 Factura              27670ANB-2         2200 6 13200 7026,5514 0+0                   46,7686
    1 Factura              27670ANB-2         2400 6 14400 7665,3288 0+0                   46,7686
    1 Factura              27730ANB-1         1080 5,4 5832 3186 0+0                   45,3704
    1 Factura              27730ANB-2         820 5,4 4428 2419 0+0                   45,3704
    1 Factura              PRV108-1           3510 7 24570 18145,31004 0+0                   26,1486
    1 Factura              PRV108-2           4800 7,9 37920 27888 0+0                   26,4557
    1 Factura              PRV108-3           7000 7,9 55300 41006,882 0+0                   25,8466
    4 Nota de Crédito      NSINDEMNIZ         1 12000 -12000 -0,65287 0+0                   0 -480
    4 Nota de Crédito      NSRAPPEL           1 41217,49 -41217,49 0 0+0                   0 -1648,6996
    0                                         0 0 0 0                       0 0
    29                                         46938 53362,79 274200,11 217126,3883                       775,8179 -2128,6996

    that is the result , but i need the result like this :

    for this Client i need only one line with the SUM of "Valor" ; "Valor_custo";"Comissões"and "Margem" , where "Valor" as Sails;"Valor_custo" as Cost; "comissões" as comissions and "margem" as benefits.

    I hope you understand better what i want to do.

    Best regards

    Luis Santos