开发者

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

开发者 https://www.devze.com 2023-01-09 11:13 出处:网络
I was wondering 开发者_如何学编程if I can subtract the same value (offset) to all values of a specific column in my table.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消