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