Skip to content

Instantly share code, notes, and snippets.

@czwen
Created January 16, 2019 09:32
Show Gist options
  • Save czwen/fd60d6e131a41760bb8ae3f074268c9b to your computer and use it in GitHub Desktop.
Save czwen/fd60d6e131a41760bb8ae3f074268c9b to your computer and use it in GitHub Desktop.
mysql 版本字符串比较
-- 获取小于等于12.0.2版本的最新数据
SELECT *, CONCAT(
LPAD(SUBSTRING_INDEX(SUBSTRING_INDEX(version, '.', 1), '.', -1), 5, '0'),
LPAD(SUBSTRING_INDEX(SUBSTRING_INDEX(version, '.', 2), '.', -1), 5, '0'),
LPAD(SUBSTRING_INDEX(SUBSTRING_INDEX(version, '.', 3), '.', -1), 5, '0')) vcode
FROM foo
having vcode <= CONCAT(LPAD(12,5,'0'), LPAD(0,5,'0'), LPAD(2,5,'0'))
order by vcode desc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment