当前位置:网站首页>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>
边栏推荐
- The Chinese Embassy in Nigeria issued an emergency safety warning for the area near Zuma Rock in Abuja
- 游戏版号“地下交易”,一个版号能卖上千万?
- 金立前高管团队再战手机市场,创立新品牌“FreeYond”
- [A summary of the sorting and use of activation functions in deep learning]
- 162_Power Query 快速合并文件夹中表格之自定义函数 TableXlsxCsv_2.0
- 保健用品行业B2B电子商务系统:供采交易全链路数字化,助推企业管理精细化
- MMA安装及使用优化
- LeetCode169:多数元素
- Controller层代码这么写,简洁又优雅!
- 面试官都震惊,你这“网络基础”可以啊
猜你喜欢
随机推荐
微服务的快速开始(nacos)最全快速配置图解
数据科学家 Agnis Liukis :在ML领域,初学者踩过的5个坑
面试官都震惊,你这“网络基础”可以啊
Left index of all anagrams in leetcode/string (some permutation of s1 string is a substring of s2)
豪威集团发布新款5000万像素图像传感器OV50E
552个元宇宙App,70个搞社交,哪款真能交到朋友?
用1000行代码统计西安新房价格后,我有一个惊人的发现……
你把 vite打包 玩明白
CVPR 2022 | Predicting Skeletons from Human Meshes, True Physiological Skeletons!
【web渗透】CSRF漏洞详细讲解
GMapping principle analysis/easy to understand
IDO代币预售dapp开发及NFT模式
Petri网-2、有向网
有哪些好用的IT资产管理平台?
The embassy in Iceland reminds Chinese citizens in Iceland to strengthen safety protection
English语法_介词 - 概述
Nanoprobes EnzMet - 酶金相相关介绍及应用
Tao Te: Engine or baggage?
1, introduction to petri net
线程的状态