Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Two rows arthimetic

Status
Not open for further replies.

logic4fun1

Programmer
Joined
Jun 29, 2006
Messages
6
Location
US
All,
I am trying to do the following but nothing strikes to me..

Here is the table data

A1,A2,A3,24
A1,A2,A3,30
B1,B2,B3,46
B1,B2,B3,60


How can i subtract two rows and get data like
A1,A2,A3,6
B1,B2,B3,14

Thanks for your help
logic4fun
 
Given your data this works.

create table test(cola char(2), colb char(2), colc char(2), colnum int);
insert into test values('A1','A2','A3',24);
insert into test values('A1','A2','A3',30);
insert into test values('B1','B2','B3',46);
insert into test values('B1','B2','B3',60);

select cola,colb,colc,max(colnum)-min(colnum) from test group by cola,colb,colc

Anyone else got a better/more elegant solution ?

ujb
 
Substr & concat? is this always fixed width?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top