回覆列表
  • 1 # 使用者3953534701789

    今天也碰到這個問題啦,開始上網找了個,是這麼寫的;

    select * from "table" order by rand()*"level" LIMIT 1;rand()是隨機產生0,1之間的浮點數,按從大到小來就是select * from "table" order by rand()*"level" desc LIMIT 1;不過rand()會有效率問題,數量大的時候會很慢又去查了一下,改了一下可以這麼寫:SELECT * FROM tablewhere level>= (SELECT floor(RAND() * (SELECT MAX(level) FROM table))) order BY overplus LIMIT 1 ;大概不捨去小數也沒啥大影響,或者SELECT * FROM tablewhere level>= (SELECT RAND() * (SELECT MAX(level) FROM table)) order BY overplus LIMIT 1 ;這樣子可以解決效率問題;

  • 中秋節和大豐收的關聯?
  • 家裡出現的蟲子哪來的?是什麼蟲子?