MySQL 随机 id 受列限制
MySQL random id restricted by column
我有一个 table,其 id 从 1 到 300 排序,其中有更多列(A、B、C、D 等)
如何获取受C列信息限制的随机id
示例
ID column C
1 teacher
2 student
3 teacher
4 student
etc...
想象一下,我只想要 C 列中 "students" 中的 id 随机(在此示例中它只能是 2 或 4)
谢谢
这是一种方法:
select id
from table t
where c = 'student'
order by rand()
limit 1;
table 中只有 300 行,性能应该没问题。
我有一个 table,其 id 从 1 到 300 排序,其中有更多列(A、B、C、D 等)
如何获取受C列信息限制的随机id
示例
ID column C
1 teacher
2 student
3 teacher
4 student
etc...
想象一下,我只想要 C 列中 "students" 中的 id 随机(在此示例中它只能是 2 或 4)
谢谢
这是一种方法:
select id
from table t
where c = 'student'
order by rand()
limit 1;
table 中只有 300 行,性能应该没问题。