mysql> select * from student;
+-----------+-----+------------+
| name | sex | student_id |
+-----------+-----+------------+
| a b c d e | F | 1 |
+-----------+-----+------------+
1 row in set (0.00 sec)
select replace(substring(substring_index(name, ' ', 3), length(substring_index(name, ' ', 3 - 1)) + 1), ',', '') as result from student;
+--------+
| result |
+--------+
| c |
+--------+
1 row in set (0.00 sec)
替换 name 为指定的表列,3 为你需要的列序。
这个mysql估计没这个语法吧,可以交给php处理,比如array_rand等很对方法
建议放在业务层处理会比较好吧,这种数据库计算很影响效率
你这需要先用SQL语句查询出每一行整体数值,然后用PHP函数把整体数值分成单个数值组成的数组,然后再用PHP函数随机取出数值中的数值。有点累。。。。
不要在数据库中实现业务的逻辑操作。建议还是按照上述的回答,取出数据交给业务层处理。