我有一张这样的表:
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
任何帮助将不胜感激!
答案 0 :(得分:3)
你可以这样做:
SELECT question, answer, category
FROM records
WHERE category=2 ORDER BY RANDOM() LIMIT 1;