Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从SQLite表中选择一个随机行,在哪里?_Sqlite - Fatal编程技术网

从SQLite表中选择一个随机行,在哪里?

从SQLite表中选择一个随机行,在哪里?,sqlite,Sqlite,我有一张这样的桌子: CREATE TABLE records (_id INTEGER PRIMARY KEY, question TEXT, answer TEXT, category INTEGER) 给定一个特定的类别值(比如2),我想从该类别中随机选择一行。这就是我想象的解决方案: Select question, answer, category //I think there is something missing From

我有一张这样的桌子:

CREATE TABLE records (_id INTEGER PRIMARY KEY,
                    question TEXT, answer TEXT, category INTEGER)
给定一个特定的类别值(比如2),我想从该类别中随机选择一行。这就是我想象的解决方案:

Select   question, answer, category //I think there is something missing
From     records
Where    category=2

任何帮助都将不胜感激

你可以这样做:

SELECT question, answer, category
FROM records
WHERE category=2 ORDER BY RANDOM() LIMIT 1;

你可以这样做:

SELECT question, answer, category
FROM records
WHERE category=2 ORDER BY RANDOM() LIMIT 1;