你的结果集不为空,当然>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.
解决方案 »
- MySQL5.5 错误1045
- mysql导入问题
- windows平台下drop table时出现'ODBC'@'localhost'错误信息
- 创建外键怎么总是报ERROR 1005的错?
- mysqldump不能 忽略多个表
- 求一SQL语句!急!!!!!!!!!
- 菜鸟问题,我装了mysql 4.0.21后,怎么看不到mysql这个数据库
- mysql实现层级查询,类似oracle里的connect by prior
- 求助:4表跨表SQL查询语句
- 关于mysql无法查询中文问题
- 能不能谈一下MYSQL或POSTGRESQL的一些优缺点,以及性能上和其它小型数据库差异
- mysql4.0.14b的连接错误
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;
这样,一条一条输,很麻烦的哦.