1

I have a table as below

   Art      PP No        ArtDate     ArtQty OPDate       OPQTY

   102844   1100023223   02-09-2015  0      31-08-2015      0
   102844   1100023766   03-11-2015  0      05-11-2015      1
   102844   1100023766   03-11-2015  1      05-11-2015      149
   102844   1100023766   03-11-2015  149    05-11-2015      1

I need to group by and expected answer

 Art    PP No       ArtDate         ArtQty  OPDate       OPQTY

102844  1100023223  02-09-2015      0       31-08-2015   0
102844  1100023766  03-11-2015      150     05-11-2015  151

How to achieve this?

bmsqldev
  • 2,627
  • 10
  • 31
  • 65
CHANDRU
  • 37
  • 1
  • 5

2 Answers2

0
SELECT Art , PPNo  , ArtDate , SUM(ArtQty) ArtQty , OPDate, SUM(OPQTY) OPQTY
FROM
YOUR_TABLE
GROUP BY Art,PPNO, ArtDate, OPDate
bmsqldev
  • 2,627
  • 10
  • 31
  • 65
0

You can first group by in subquery and then get a result if you need all in above order, or the subquery will work for the sake of output you want.

   Select Art, PPNo, ArtDate, ArtQty, OPDate, OPQTY 
    FROM 
    (
    SELECT Art, PPNo, ArtDate, OPDate, SUM(OPQTY) AS OPQTY, SUM(ArtQty) as ArtQty FROM TABLENAME
    GROUP BY Art, PPNo, ArtDate, OPDate
    )
Maulik Modi
  • 1,205
  • 12
  • 22