我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

MySQL随机id受列限制

I have a table with id's ordered from 1 to 300 which have more columns (A,B,C,D,etc)

How to get a random id restricted by the info in column C for example

Example

ID   column C
1    teacher
2    student
3    teacher
4    student
etc...

Imagine i only want id random from "students" in column C (in this example it can only be 2 or 4)

Thanks

Here is one way:

select id
from table t
where c = 'student'
order by rand()
limit 1;

With only 300 rows in the table, the performance should be fine.

近期文章

  • 运行behat输出烦人的PHP严格标准错误/通知
  • 如何在PHP中对此数组进行排序?
  • 使用从服务定义的链提供程序
  • 如何在登录Symfony后进行不同的重定向
  • 在外部PHP文件中使用PDO连接mysql数据库[重复]
  • 如何在JSON.parsed responseText上保留hasOwnProperty?
  • 查找日期的日期范围
  • Strtotime功能
  • 从网页顶部删除PHP日志
  • Php使用单选按钮id更新数据库列
  • 根据我的单选按钮选择显示mysql表结果
  • PHP:“致命错误:在不在对象上下文中时使用$ this”[重复]
  • 在Yii2中为单个请求设置全局可用代码
  • yii2:索引页面(带搜索),用于显示所有字段的一对多关系
  • Yii 2.0中的初始登录页面
  • too long
  • 拉最后两个日期PHP / MySQL
  • isset不适用于带有撇号的变量
  • 调试网页时未反映Javascript的变化
  • 我如何才允许require_once的东西取决于哪个页面'需要'呢?

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华