Conditional Calculation

L

Lily

I have a table with 2 fields: Zipcode and Dollar. I want to create a new
field "Relativity" that equals to Dollar/Dollar(when Zipcode=44444).

how do I write it in SQL?

Select ZipCode, Dollar, Relativity as Dollar/(Dollar When Zipcode=44444)
from table1;

Thanks,
Lily
 
L

Lily

This is what I want to get:
Zip Dollar Relativity
44444 1000 =1000/1000=1
44433 2000 =2000/1000=2
44456 2500 =2500/1000=2.5
44457 3000 =3000/1000=3


Thanks,
Lily
 
S

Sylvain Lafontaine

select z1.zipcode, z1.dollar, z1.dollar / z2.dollar as Relativity from
zipcodes z1 cross join zipcodes z2 where (z2.zipcode = 44444)
order by 3
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top