MySQL 一些查询语句及技巧

生成唯一随机数

# 非补0版本
SELECT FLOOR(100000 + RAND() * 899999) AS random_number
FROM target_table
WHERE "unique_field" NOT IN (SELECT unique_field FROM target_table)
LIMIT 1 # 补0版本
SELECT LPAD(FLOOR(RAND() * 999999), 6, 0) AS random_number
FROM target_table
WHERE "unique_field" NOT IN (SELECT unique_field FROM target_table)
LIMIT 1
上一篇:Android Handler leak 分析及解决办法


下一篇:Android Handler练习