你的结果集不为空,当然>0啦.不过你上面的sql语句好像有错吧?mysql的函数要单独用,只能是
select count(*) from city left join othertable on othertable.cityid=city.cityid
where othertable.cityid=city.cityid
group by cityid
执行上面的语句如果你的结果集为空就会返回0.
select count(*) from city left join othertable on othertable.cityid=city.cityid
where othertable.cityid=city.cityid
group by cityid
执行上面的语句如果你的结果集为空就会返回0.
left join othertable on othertable.cityid=city.cityid
where othertable.cityid=city.cityid
group by cityid
我的意思是:
city表里是记录的是全省的所有城市名,othertable表里存的是违法案件(不一定每个城市里都有违法案件),我想统计全省所有城市里的违法案件数量,没有的返回0,两个表之间是用cityid关连的
我想得到类似如下的结果:
城市名 案件数量
东营 10
菏泽 15
济南 0
...........
city | othertable
cityid cityname | 案件id 案件名 cityid
如果是的话,你这样不就行了
mysql>select count(案件id) from city,othertable where city.cityid=othertable.cityid;
这样,一条一条输,很麻烦的哦.