mysql-更新百分比更改的SQL语句
作者:互联网
我已经搜索过对于这个答案,已经接近答案,但还不够接近.我想知道MySQL是否具有此功能.
我已经在Perl和MySQL 4中进行了开发,现在在MySQL 4上.
我的桌子看起来像这样…
>符号varchar(25)
>今天日期
>利息诠释(11)
我的问题是…..这些符号(大约200,000个)每天都会更新以关注领域的新数字.
一个例子就是这个……
symbol | todayDate | interest
-------------------------------
A202015 | 2010-10-26 | 150
A202015 | 2010-10-25 | 100
理想情况下,我将能够做的是在最后一个字段上更新另一个字段,并从上一个记录中更改一个百分比.上面看起来像这样…
symbol | todayDate | interest | change
-----------------------------------------
A202015 | 2010-10-26 | 150 | 50
A202015 | 2010-10-25 | 100
我认为在MySQL中无法实现此功能.我得出的结论是,我只需要获取先前的记录信息,进行数学运算,然后使用百分比信息更新最新的记录.我只是想我会仔细检查一下,看看是否有任何MySQL才华横溢的人有智慧.
解决方法:
与Wilkie女士进行电子邮件对话后,事实证明她希望进行如下更改:
update t_test_1 as t1
set chng = (t1.interest - (
select interest from (
select *
from t_test_1 as t11
) as x
where x.symbol = t1.symbol and x.todayDate < t1.todayDate
order by x.todayDate desc
limit 1
)) /
(
select interest from (
select *
from t_test_1 as t11
) as x2
where x2.symbol = t1.symbol and x2.todayDate < t1.todayDate
order by x2.todayDate desc
limit 1
) * 100 ;
标签:sql-update,sql,mysql 来源: https://codeday.me/bug/20191209/2095892.html