This?declare @sample table (acno int, status char(2), amount decimal(12,2))insert @sampleselect 111, 'cr', 1000 union allselect 111, 'db', 2000 union allselect 111, 'db', 1000 union allselect 111, 'cr', 1000 union allselect 222, 'cr', 500 union allselect 222, 'db', 100selectacno,sum(case when status='cr' then amount else 0 end) - sum(case when status='db' then amount else 0 end) as balfrom@samplegroup by acno
Too old to Rock'n'Roll too young to die.