views:

33

answers:

2

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 ?

+6  A: 

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)
djacobson
+1: Faster than me
OMG Ponies
+3  A: 

How about:

 SELECT (MyCol - 10)
 From MyTable
p.campbell
+1: Faster than I
OMG Ponies
Thanks Ponies. That's twice now, but you've beaten me a handful of times ;)
p.campbell
But slower than me, and with less content.In fact, UPDATE p.campbell SET posttime = djacobson's post time + 10;)
djacobson
You forgot the WHERE clause. Now all hell will break lose.
strager