我有5个带数字的INT变量。我想在mysql程序中从五个变量中选择一个随机数。
示例数据:
DECLARE a, b, c, d, e INT;
SET a = 50;
SET B = 22;
SET C = 88;
SET D = 892;
SET E = 367;
现在我想从变量a,b,c,d,e中选择一个随机数。有什么想法怎么做?感谢。
答案 0 :(得分:2)
SELECT * FROM MyTable ORDER BY RAND()LIMIT 1
更新
SELECT * FROM
(
SELECT @A AS Val
UNION ALL
SELECT @B AS Val
UNION ALL
SELECT @C AS Val
UNION ALL
SELECT @D AS Val
UNION ALL
SELECT @E AS Val
)F
ORDER BY RAND()LIMIT 1