使用相同列的列的算术运算

问题描述 投票:-1回答:1

我有一个列,我想使用相同的列在同一列上执行一些算术运算

Price
---------
10
11
12
12
14
14
14
14

如果我想知道Price = 14的行,那么我可以用where子句编写一个简单的select查询

select * from table_name where Price = 14;

但是Price栏的价值不断变化,如果我想要这样的话

Latest value of Price is 10
select * from table_name where Price = Price + 4;

这应该返回值为14的所有行。我们如何实现这一目标?

mysql sql where arithmetic-expressions
1个回答
0
投票

使用子查询

 select * from table_name where Price = (select min(Price) + 4 from table_name)
© www.soinside.com 2019 - 2024. All rights reserved.