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 ?
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)
How about:
SELECT (MyCol - 10)
From MyTable
精彩评论