sql(Count)显示1而不是0 [英] The sql (Count) is displaying 1 in stead of 0

查看:217
本文介绍了sql(Count)显示1而不是0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

select CANDIDATE.Candidate_Party, COUNT(CANDIDATE.Candidate_Number) AS VotesNumber
from CANDIDATE
left outer join VOTE on CANDIDATE.Candidate_Number = VOTE.Candidate_Number
WHERE
CANDIDATE.Candidate_Portfolio = 'Missionvale Representative'

 GROUP BY CANDIDATE.Candidate_Party







我上面的sql,每当它计算数据库中没有数据时显示1,我想要的是如果没有数据,则返回0.



i尝试了大量的查询,但是它们很有效。请帮忙。



当计算它必须显示0




My sql above, everytime when it counting the there is no data in a database is display 1, what i want is to return a 0 if there is no data.

i tryed lot of querys but they ddnt work. Please help.

When m counting it must display 0

推荐答案

我认为这是因为类型你正在使用的加入。左外连接总是会给你每个候选人(因为它是左边的表)然后也会给你他们所做的任何投票。你想要的是一个内连接,它只会给你匹配两个文件的数据。



http://stackoverflow.com/questions/38549/difference-between-inner-and-outer-join [ ^ ]



http://www.google.com/#q= sql +外部+加入+ vs +内部+加入 [ ^ ]
I think it's because of the type of join you are using. A left outer join is ALWAYS going to give you EVERY candidate (because it's the table on the left) and then will also give you any votes they made. What you want is an inner join, which will only give you data that matches both files.

http://stackoverflow.com/questions/38549/difference-between-inner-and-outer-join[^]

http://www.google.com/#q=sql+outer+join+vs+inner+join[^]


这篇关于sql(Count)显示1而不是0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆