我正在尝试选择有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”? 感谢
答案 0 :(得分: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
使用INNER JOIN,我们总是有计数(m。*)> 0
答案 1 :(得分: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;