search

Home  >  Q&A  >  body text

java - sql语句是否可以随机选择制定的数据

PHPzPHPz2902 days ago629

reply all(3)I'll reply

  • 巴扎黑

    巴扎黑2017-04-18 10:10:21

    SELECT *, rand() '_RAND' FROM XXX_TABLE ORDER BY _RAND LIMIT 0,200;
    使用rand()Generate random number sorting and take out the first 200 items.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 10:10:21

    Then you choose 200, but it can’t be random. You can use the same idea of ​​paging mysql limit x,x+200 oralce where rownum<x+200 ) where rownum>x;

    reply
    0
  • 阿神

    阿神2017-04-18 10:10:21

    Try something like this

    SELECT * FROM users WHERE userId >= ((SELECT MAX(userId) FROM users)-(SELECT MIN(userId) FROM users)) * RAND() + (SELECT MIN(userId) FROM users)  LIMIT 200

    reply
    0
  • Cancelreply