mysql - 查询是否返回一致的结果?

标签 mysql sql join

剥掉外层后改题

我正在使用 MySQL 5.1

select s.status, street, m.meterpointid
from meterpoint m inner join account a
     on ( m.accountid = a.accountid) inner join
     meterservice s
     on ( m.meterpointid = s.meterpointid )
where a.citystateid=1 and m.meterpointid=3008 and m.lastupdate is not null 
group by status, street ;

上面的查询返回

1   210 S HWY 3 3008

select s.status, street, m.meterpointid
from meterpoint m inner join account a
     on ( m.accountid = a.accountid) inner join
     meterservice s
     on ( m.meterpointid = s.meterpointid )
where a.citystateid=1 and m.lastupdate is not null 
group by status, street ;

但上面查询的输出与之前没有 m.meterpointid=3008 的查询完全相同,但不包含 1 210 S HWY 3 3008

有什么想法吗?

谢谢 那仁

最佳答案

内部查询的更改正在更改外部查询中的计数,因此 having count(*) = 1 不再为真。我发现诊断这类事情的最佳方法是剥离外层并查看内部查询,直到我弄清楚发生了什么。

关于mysql - 查询是否返回一致的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13711350/

相关文章:

mysql - 如何检索作为集合检索的分层数据

mysql - mysql上需要大于20位的整数怎么办?

c# - 关于生成无法追踪的发票 ID 的想法

mysql - SQL JOIN - 不明白

Rails 的 Mysql 浮点精度问题

sql - array_agg() 函数的返回类型

php - Doctrine :具有多个外键的一对多关系

python - 使用 pandas 对文本字段进行 vlookup

python - 如何使用 join 来填充列的缺失值 - Python Pandas?

mysql - 在 MySql 中访问列名中包含多个点的列数据