The mysql random retrieval optimization statement finds a random fetch statement on the Internet, which combines its own needs to run an error,
I haven't found any errors for a long time. please advise.
$str="select * from dizhi where shijiancuo>'$times' GROUP BY user HAVING COUNT(user) > 4 AS t1 JOIN (SELECT ROUND(RAND() * (SELECT MAX(id) FROM dizhi)) AS id) AS t2 WHERE t1.id >= t2.id ORDER BY t1.id ASC LIMIT 1" ;
Reply to discussion (solution)
What is the error message?
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\www\AppServ\www\tuijianshuchu.php on line 23
23 The code is as follows:
$ Result = mysql_query ($ str, $ con); // send a query? $ Rows = mysql_num_rows ($ result); // 23 rows
Because an error occurs in your SQL statement, you can print the $ str statement to see what it is.
$ Str posted on the first floor
$ Result = mysql_query ($ str, $ con) or die (mysql_error ());
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS t1 JOIN (SELECT ROUND(RAND() * (SELECT MAX(id) FROM dizhi)) AS id) AS t2 ' at line 1
Select * from
(Select * from dizhi where shijiancuo> '$ times' group by user having count (user)> 4) AS t1
JOIN
(Select round (RAND () * (select max (id) FROM dizhi) AS id) AS t2
WHERE t1.id> = t2.id
Order by t1.id asc limit 1
JOIN (select round (RAND () * (select max (id) FROM dizhi) AS id from dizhi) AS t2
The 8th floor is unavailable. the 7th floor is OK. thank you.
I have never understood the meaning of this sentence
(SELECT ROUND(RAND() * (SELECT MAX(id) FROM dizhi)) AS id) AS t2
According to the Internet, the ROUND function is used to ROUND a value field to a specified decimal place, so I don't quite understand what the result of this statement is.
RAND generates a random number less than 1
Select max (id) FROM dizhi to obtain the largest id value in dizhi.
ROUND rounded to an integer
The query command indicates:
Any id value in the table
Understood, 3Q.