SELECT AccNum as Account, max(date) as Date, Type, 'CHEQUENO' as Subtype, count(*) as Total_No, sum(Amount) as AmountFROM transaction where chequeno is not null GROUP BY AccNum, TypeunionSELECT AccNum as Account, max(date) as Date, Type, 'DDNO' as Subtype, count(*) as Total_No, sum(Amount) as AmountFROM transaction where DDNO is not null GROUP BY AccNum, Type;