当前位置:网站首页>Mysql 生成排序序号
Mysql 生成排序序号
2022-08-03 14:07:00 【InfoQ】
业务场景
SELECT id,user_id,sales_performance,(@i:[email protected]+1) rank from crm_account_user_performance_data,(SELECT @i:=0) t WHERE dept_id=307 ORDER BY sales_performance DESC;
Java业务代码
List<Long> deptlist = accountUserPerformanceDataMapper.selectDeptIdsByAccountTime(date);
if (CollectionUtils.isNotEmpty(deptlist)) {
//遍历为每个部门下人员进行业绩排序
for (Long deptId : deptlist) {
List<AccountUserPerformanceData> list = accountUserPerformanceDataMapper.selectRankByDeptId(deptId);
//批量更新本部门排序
accountUserPerformanceDataMapper.updateRankBatch(list);
}
}<select id="selectDeptIdsByAccountTime" parameterType="Date" resultType="java.lang.Long">
SELECT DISTINCT dept_id FROM crm_account_user_performance_data
WHERE account_time = #{accountTime}
</select><select id="selectRankByDeptId" parameterType="Long" resultMap="AccountUserPerformanceDataResult">
SELECT id,user_id,(@i:[email protected]+1) rank from crm_account_user_performance_data,(SELECT @i:=0) t
WHERE dept_id=#{deptId} ORDER BY sales_performance DESC
</select><update id="updateRankBatch" parameterType="List">
update crm_account_user_performance_data
set rank = case id
<foreach collection="list" item="account" separator=" ">
when #{account.id} then #{account.rank}
</foreach>
end where id in
<foreach collection="list" item="account" open="(" separator="," close=")">
#{account.id}
</foreach>
</update>边栏推荐
- With 1000 lines of code statistics after the xi 'an housing prices, I have a startling discovery...
- 《深度学习》-学习笔记-1-机器学习基础
- 【MATLAB项目实战】基于CNN_SVM的图像花卉识别
- 华云数据张华林:投身数字蓝海 绘就云上强国
- atrace和systrace的基本使用方法
- The difference between servlet and jsp _ the difference between servlet and class
- 如何使用matlab实现分段函数「建议收藏」
- 面试官都震惊,你这“网络基础”可以啊
- 使用百度EasyDL实现施工人员安全装备检测
- LeetCode136:只出现一次的数字
猜你喜欢
随机推荐
APT组织最喜欢的工具 Cobalt Strike (CS) 实战
Php程序员用那个编辑器比较好?
【框架】idea找不到xxx依赖项怎么办
工作流自动化,低代码是解决关键
go map转struct【mapstructure库】
Nature, Cell都在用的Relia Tech 抗原亲和纯化LYVE1抗体
How to connect a VMware virtual machine to the network "recommended collection"
Top 10 free proxy IP software_Domestic static IP proxy software
使用华为HECS云服务器打造Telegraf+Influxdb+Grafana 监控系统【华为云至简致远】
Ansible中的角色使用
Nanoprobes Ni-NTA-Nanogold——用于 His 标签标记和检测
js \n\r 换行失败 :【white-space: pre-line;】${} Template Literals
Day2:面试必考题目
Nanoprobes金脂质偶联物的相关应用
Tao Te: Engine or baggage?
How to use matlab to implement the piecewise function "recommended collection"
UE4 C disk cache solution
15 years of software architect experience summary: In the ML field, 5 pits that beginners have stepped on
Nanoprobes 金纳米颗粒标记试剂丨1.4 nm Nanogold 标记试剂
15年软件架构师经验总结:在ML领域,初学者踩过的5个坑









