select FORMDATE,DEPTNO,POSHEAD,POSBODY,VIPNO,CUSTNAME,COUNTERNO,PARTNO,HUMANSERNO,PARTNAME,PARTTYPE,SIZECODE,COLORNO,PARTSERNO,BILLUNIT,P1,P2,P3,P4,P5,LTDNO,max(UNITPRICE) as UNITP,max(DISCOUNT) as DISC,sum(COUNTS) as SUNIT,sum(SUBPRICE) as SSUB,sum(ACOST) as SCOST,SOURCENO,PARTCODE,sum(ACOST) as SCOST,PACKAGE from DP001 where FORMDATE >'20161231' and ISCONFIRM='Y' group by FORMDATE,DEPTNO,POSHEAD,POSBODY,VIPNO,CUSTNAME,COUNTERNO,PARTNO,HUMANSERNO,PARTNAME,PARTTYPE,SIZECODE,COLORNO,PARTSERNO,BILLUNIT,P1,P2,P3,P4,P5,LTDNO,SOURCENO,PARTCODE,PACKAGE
