Mysql 不显示0结果的计数
我有个问题 我需要此选项,请按Contendor给我计数组的编号Mysql 不显示0结果的计数,mysql,sql,mysql-workbench,bdd,Mysql,Sql,Mysql Workbench,Bdd,我有个问题 我需要此选项,请按Contendor给我计数组的编号 SELECT C.Contenedor, count(DC.Contenedor) as NUM FROM contenedores AS C, det_contenedores as DC WHERE C.Contenedor=DC.Contenedor GROUP BY C.Contenedor 但仅显示“count(DC.contendor)”大于0的“C.contendor” 结果是(例如): 我希望: A->3
SELECT C.Contenedor, count(DC.Contenedor) as NUM
FROM contenedores AS C, det_contenedores as DC
WHERE C.Contenedor=DC.Contenedor
GROUP BY C.Contenedor
但仅显示“count(DC.contendor)”大于0的“C.contendor”
结果是(例如):
我希望:
A->3
B->7
C->0
D->6
E->0
有什么想法吗?谢谢 您需要使用
左连接
而不是连接
:
SELECT C.Contenedor, count(DC.Contenedor) as NUM
FROM
contenedores AS C
LEFT JOIN det_contenedores as DC
ON C.Contenedor=DC.Contenedor
GROUP BY C.Contenedor
读这个:嗯,好的!但如果我想做一个选择,做同样的,但搜索一个contendor??类似这样的内容
选择C.contendor,count(DC.contendor)作为NUM从contendores作为C LEFT加入det_contendores作为DC ON C.contendor=DC.contendor和C.contendores=3按C.contendor分组为什么不出现contendores 3--->0(count)
SELECT C.Contenedor, count(DC.Contenedor) as NUM
FROM
contenedores AS C
LEFT JOIN det_contenedores as DC
ON C.Contenedor=DC.Contenedor
GROUP BY C.Contenedor