mysql:每月汇总数据更新排序

编程

月数据汇总表:

month_log

id

amount

date_create

sort_index

sort_rate

1

100

2020-07-14

0

0

 

更新语句

SET @crank:=0;

UPDATE month_log as tb

INNER JOIN

(

SELECT ta.id, (@crank:=@crank+1) as rank_sort, CEILING(@crank/{$all_count}*100) as sort_rate_to, ta.date_create as date_create_to

FROM month_log as ta

WHERE ta.date_create like "{$month_date}%"

ORDER BY ta.amount

) as td

ON tb.id=td.id

SET tb.sort_index=td.rank_sort, tb.sort_rate=td.sort_rate_to

WHERE tb.date_create=td.date_create_to;

$all_count: 需要更新的数据条数
$month_date: 更新的年-月

以上是 mysql:每月汇总数据更新排序 的全部内容, 来源链接: utcz.com/z/518304.html

回到顶部