Created
November 30, 2015 05:05
-
-
Save consatan/1161170f796687f9ede5 to your computer and use it in GitHub Desktop.
通过子查询更新或插入固定前缀的递增字段
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 如果前缀要使用年份加月份,第7行需要增加判断条件 | |
UPDATE `table` SET `no`= | |
( | |
SELECT `no` | |
FROM ( | |
SELECT IF( | |
(SELECT 1 FROM `table` WHERE `no` IS NOT NULL AND `no` <> "") IS NULL, | |
"NO1000", | |
( | |
SELECT CONCAT("NO", SUBSTRING(`no`, 3) + 1) | |
FROM `table` | |
WHERE `no` IS NOT NULL AND `no` <> "" ORDER BY `no` DESC LIMIT 1 | |
) | |
) AS `no` | |
) AS `t` | |
) | |
WHERE `uid`=? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment