我現在有這個解決方案隨機條目:選擇從MySQL與where子句
rs = lState.executeQuery("SELECT FLOOR(RAND() * COUNT(*))
FROM bases
WHERE user_id = " + userId + " AND is_valid = 1");
rs.next();
count = rs.getInt(1);
rs = lState.executeQuery("SELECT id, server, server_port, server_ssl,
server_starttls, server_auth, email, password, auth_wholemail
FROM bases LIMIT " + count + ", 1");
但它不工作,因爲FLOOR(RAND() * COUNT(*))
不與is_valid = 1
返回ID。 那麼如何從MySQL whith where子句(其中is_valid = 1)快速選擇隨機條目?