aneuryzm
aneuryzm

Reputation: 64844

How to subtract the same amounts to all values in a column?

I was wondering if I can subtract the same value (offset) to all values of a specific column in my table.

For example I have:

Col1
------
34
35
36

I want to make it:

Col1
------
24
25
26

What's the SQL code for doing it ?

Upvotes: 2

Views: 2424

Answers (2)

p.campbell
p.campbell

Reputation: 100607

How about:

 SELECT (MyCol - 10)
 From MyTable

Upvotes: 3

Dan J
Dan J

Reputation: 16708

Are you just doing this for display, or do you want to update the table with the reduced values?

In the first case:

select (Col1 - 10) from table

In the second (assuming you want to update ALL rows):

update table set Col1 = (Col1 - 10)

Upvotes: 10

Related Questions