Mysql 选择计数,其中计数 > 0

标签 mysql

我正在尝试选择此查询中 nbre > 0 的项目:

SELECT c.id, c.nom, c.photo,
    (SELECT count(*) 
     FROM touist_materiel 
     WHERE cat=c.id AND marque=7 AND actif=1
    ) as nbre
FROM touist_materiel_cat c
INNER JOIN touist_materiel m ON m.cat=c.id 
WHERE nbre > 0 
GROUP BY m.cat 
ORDER BY c.nom

此查询不起作用,如何让“where nbre > 0”起作用? 谢谢

最佳答案

SELECT tmc.id, tmc.nom, tmc.photo, count(tm.*) AS nbre
  FROM touist_materiel_cat tmc
  INNER JOIN touist_materiel tm
    ON tm.cat=tmc.id 
  WHERE nbre > 0 
    AND tm.marque=7 
    AND tm.actif=1
  GROUP BY tm.cat 
  ORDER BY tmc.nom;

关于Mysql 选择计数,其中计数 > 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19611370/

相关文章:

java - 不使用 int onebyte 将字符串写入 OutputStream

php - 组合框不会显示来自 MySQL 的值

mysql - MySQL 是如何实现 "group by"的?

mysql - 如何在mysql数据库中搜索并替换带有换行符的空html表行

mysql - CakePHP 3 patchEntity SQL日期失败

mysql - 在 MySQL 中转换日期时间

java - MySQLIntegrityConstraintViolationException : column "question_id" cannot be null error

php - 运行插入查询最多 5 分钟 MySql

mysql - 不循环引用 MYSQL 结果集

php - 如果添加了更多项目,则使用 foreach 循环