* your DDL with an additional PK field Create Cursor table1 ; (pk Char(10), date d(8),code Char(7),name Char(30), qty n(4), credit N(12), Debit N(12), code2 Char(7)) Insert Into table1 Values (SYS(2015), {^2008-01-15},'1401001','Eric',0,0,100,'3201001') Insert Into table1 Values (SYS(2015), {^2008-01-15},'3201001','Apple',10,100,0,'1401001') Insert Into table1 Values (SYS(2015), {^2008-01-15},'1401001','Eric',0,0,200,'3202001') Insert Into table1 Values (SYS(2015), {^2008-01-15},'3202001','Potato',20,200,0,'1401001') Insert Into table1 Values (SYS(2015), {^2008-02-18},'1401001','Eric',0,0,600,'3202001') Insert Into table1 Values (SYS(2015), {^2008-02-18},'3202001','Potato',40,600,0,'1401001') Insert Into table1 Values (SYS(2015), {^2008-06-17},'1401002','Boris',0,0,300,'3202001') Insert Into table1 Values (SYS(2015), {^2008-06-17},'3202001','Juice',20,300,0,'1401002') *The result must look like this *month---qty---amt1--amt2---total *Jan08---30----100----200-----300 *Feb08---40--------0----600-----600 *Jun08---20--------0----300-----300 * SQL SELECT ; T1.date, ; ( LEFT(CMONTH(T1.date),3) + ; RIGHT(TRANSFORM(YEAR(T1.date)),2) ; ) as month, ; SUM(T1.qty) as qty, ; SUM(T2.credit) as amt1, ; SUM(T3.credit) as amt2, ; SUM( NVL(T2.credit,0)+NVL(T3.credit,0) ) as total ; FROM table1 T1 ; LEFT JOIN table1 T2 ; ON T2.pk = T1.pk AND T2.code Like '3201%' ; LEFT JOIN table1 T3 ; ON T3.pk = T1.pk AND T3.code Like '3202%' ; WHERE T1.code Like '320%' ; GROUP BY 1, 2 ; ORDER BY 1>Dear Experts
>Create Cursor table1 ; >(date d(8),code Char(7),name Char(30), qty n(4), credit N(12), Debit N(12), code2 Char(7)) > >Insert Into table1 Values ({^2008-01-15},'1401001','Eric',0,0,100,'3201001') >Insert Into table1 Values ({^2008-01-15},'3201001','Apple',10,100,0,'1401001') >Insert Into table1 Values ({^2008-01-15},'1401001','Eric',0,0,200,'3202001') >Insert Into table1 Values ({^2008-01-15},'3202001','Potato',20,200,0,'1401001') >Insert Into table1 Values ({^2008-02-18},'1401001','Eric',0,0,600,'3202001') >Insert Into table1 Values ({^2008-02-18},'3202001','Potato',40,600,0,'1401001') >Insert Into table1 Values ({^2008-06-17},'1401002','Boris',0,0,300,'3202001') >Insert Into table1 Values ({^2008-06-17},'3202001','Juice',20,300,0,'1401002') >>A shopkeeper wants to see Product wise monthly sale summary