php - 从 MYSQL 表中选择 10+ num_rows 结果

标签 php mysql

有人能告诉我这个 mysql 查询有什么问题吗?

$p = mysql_query("SELECT name,subname FROM brands GROUP BY name WHERE 
having count(*) > 10 ORDER BY RAND() LIMIT 1")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 'WHERE having count(*) > 10 ORDER BY RAND() LIMIT 1' at line 1

最佳答案

HAVING 不使用 WHERE 子句,将其删除。

$p = mysql_query("SELECT name,subname FROM brands GROUP BY name  
having count(*) > 10 ORDER BY RAND() LIMIT 1")or die(mysql_error()); 

咨询:

您应该考虑切换到 PDOprepared statementsmysqli_* with prepared statements ,因为 mysql_* 函数已弃用。

关于php - 从 MYSQL 表中选择 10+ num_rows 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28647051/

相关文章:

php - 从Flash发送JSON到PHP

python - mysql 中的同一行(nginx+tornado+mysqldb)

java - 使用标准(Hibernate)仅获取最后的条目

mysql - 获取每个订单的成本和时间

php - 另类反帧破坏者

php - 如何阻止直接下载文件

c# - 根据 ComboBox 选择动态进行查询

c++ - 传感器数据收集 C 守护进程困境

php - Jenkins 无法识别 Composer 命令

php - 将 if 与希伯来字母进行比较