标签:
SELECT * from humor ORDER BY rand() limit 1
SELECT * FROM `user`
WHERE USER_ID >= (SELECT floor(RAND() * (SELECT MAX(USER_ID) FROM `user`)))
ORDER BY USER_ID LIMIT 1 ;
Hibernate中,需要使用SQLQuery对象
String sql = "SELECT * from humor ORDER BY rand() limit 1";
// 使用会话获得对象
SQLQuery query = session.createSQLQuery(sql);
query.addEntity(Humor.class);
humor = (Humor) query.list().get(0);
标签:
原文地址:http://www.cnblogs.com/shabi-ef/p/4220592.html