常规取最大值 desc + top
SELECT top 1 *
FROM 未来之窗东方仙盟教学
WHERE 日期 = '2025 - 05 - 28 00:00:00' ORDER BY 序号 DESC
经过运算去除 序号 最大为8
复杂字符串去除最大编号
由于字符串很难进行数字比大小,并混入其他字符。
例如上图:我们今天的接下来的的单号是 MC202505280020006
这个6 来源与5+1
问题怎么得到5呢
SELECT top 1 *
FROM 未来之窗东方仙盟教学
WHERE 日期= '2025 - 05 - 28 00:00:00' ORDER BY CAST(SUBSTRING(单号, LEN(单号) - 3, 4) AS INT) DESC
代码解释
取得字符串中编号数字系列
SUBSTRING(单号, LEN(单号) - 3, 4)
取得字符串后四位
转换为数字
序列排序
系统实践-安全
系统一般不会直接拼接sql
以为仙盟为例
->order(CAST(SUBSTRING(单号, LEN(单号) - 3, 4) AS INT) DESC);
阿雪技术观
让我们积极投身于技术共享的浪潮中,不仅仅是作为受益者,更要成为贡献者。无论是分享自己的代码、撰写技术博客,还是参与开源项目的维护和改进,每一个小小的举动都可能成为推动技术进步的巨大力量
Embrace open source and sharing, witness the miracle of technological progress, and enjoy the happy times of humanity! Let's actively join the wave of technology sharing. Not only as beneficiaries, but also as contributors. Whether sharing our own code, writing technical blogs, or participating in the maintenance and improvement of open source projects, every small action may become a huge force driving technological progress.