java - SQL Order String Primary Key -


i wondering how sort sql primary keys varchar composed of 3 parts. generate new key need find largest number current year.

mc-#year-#number
e.g. mc-2014-1

order in database table:

mc-2013-5  mc-2014-1 mc-2014-2 mc-2014-11 

something

order cast(replace(substring(mc-2014-11,4),'_','') signed) 

however, linked java programme alo retrieve , sort keys.

the maximum number current year

select max(cast(substring(code,9) int)) mytable code concat('mc-', year(now()), '%'); 

but agree others must think locking, if retrieve maximum number way make insert.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -