我有这样的查询:
SELECT Id, Name, image, price, view FROM estore.product ORDER BY view DESC LIMIT 9
我想在该查询中随机选择 5 条记录。我试过了,但这段代码不起作用:
SELECT Id, Name, Image, Price, View FROM (
SELECT Id, Name, Image, Price, View FROM estore.product ORDER BY View DESC LIMIT 9)
ORDER BY RAND() LIMIT 5
我该怎么办?感谢收看?
最佳答案
子查询必须命名。尝试:
LIMIT 9) as SubQueryAlias ORDER BY RAND()
^^^^^^^^^^^^^^^^^^
关于php - MySQL - 如何在选择顶部后选择随机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17150888/