Home  >  Article  >  Backend Development  >  sql+mysql 随机数据读取-进阶有关问题

sql+mysql 随机数据读取-进阶有关问题

WBOY
WBOYOriginal
2016-06-13 10:11:27803browse

sql+mysql 随机数据读取---进阶问题
比如有一个表 class , 里面的数据是一个花名册, 比如姓名,年龄,性别,籍贯
我现在想得到这么一个随机的结果: 按照籍贯,每个省份随机列出一条记录. 花名册里有的省份都要读取到.
请问这 SQL 语句该怎么写?

------解决方案--------------------
select m.* from (select * from user order by rand()) m group by m.area_id

user是你的表名,area_id是籍贯

问题解决。

如果对你有帮助,麻烦帮我点一下我网站的广告,谢谢。
网址:http://blog.72-web.com

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn