如何对列中的所有值减去相同的金额?

发布于 2024-09-12 23:14:45 字数 185 浏览 1 评论 0原文

我想知道是否可以将相同的值(偏移量)减去表中特定列的所有值。

例如我有:

Col1
------
34
35
36

我想做到:

Col1
------
24
25
26

执行此操作的 SQL 代码是什么?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青瓷清茶倾城歌 2024-09-19 23:14:45

您这样做只是为了显示,还是想用减少的值更新表格?

在第一种情况下:

select (Col1 - 10) from table

在第二种情况下(假设您要更新所有行):

update table set Col1 = (Col1 - 10)

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)
沒落の蓅哖 2024-09-19 23:14:45

怎么样:

 SELECT (MyCol - 10)
 From MyTable

How about:

 SELECT (MyCol - 10)
 From MyTable
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文