如何从sqlite中的列请求随机值? [英] How to request a random value from a column in sqlite?
本文介绍了如何从sqlite中的列请求随机值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有10列或字段
s.no ans1 ans2 ans3 ... ans10
1 abcx
i想要一个sqlite代码来选择一个随机列
我尝试了什么: < br $>
i am having 10 columns or fields
s.no ans1 ans2 ans3 ... ans10
1 a b c x
i want a sqlite code to select a random column
What I have tried:
SELECT column FROM table
ORDER BY RAND()
LIMIT 1
推荐答案
使用rand()*方法获取1到10之间的随机值。通过将数字连接到基本列id来创建SELECT子句,并将其传递给数据库。类似于:
Use the rand()* method to get a random value between 1 and 10 inclusive. Create a SELECT clause by concatenating the number to the base column id, and pass that to the database. Something like:
column = rand(1..10)
string select = "SELECT ans" + column + "remainder of select clause"
*您还没有提到您使用的语言,因此以上只是伪代码。
* you have not mentioned what language you are using so the above is only pseudocode.
It是
It is
SELECT column FROM table
ORDER BY RANDOM()
LIMIT 1
见 SQLite Random [ ^ ]。
这篇关于如何从sqlite中的列请求随机值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文