Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql选择count where count>;0_Mysql - Fatal编程技术网

Mysql选择count where count>;0

Mysql选择count where count>;0,mysql,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

我正在尝试在此查询中选择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 c.id, c.nom, c.photo, count(m.*) AS nbre
FROM touist_materiel_cat c
INNER JOIN touist_materiel m
  ON m.cat=c.id AND m.marque=7 AND m.actif=1
GROUP BY m.cat
ORDER BY c.nom

使用内部连接时,我们总是有count(m.*)>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;