我遇到了一个大查询的问题,但试图简化它并发现了类似的奇怪行为:
select concat(a.col1,a.col2) as b,
count(a.id) as c
from test as a
group by a.id
having b = "644591"
order by b
相同的查询在 5.6 InnoDB 上不返回任何结果,但 5.5 MyISAM 返回一个正确的匹配项。
如果您删除“order by b”,它也会在 InnoDB 上返回正确的结果。
表格:
CREATE TABLE `test` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`col1` varchar(100) NOT NULL DEFAULT '',
`col2` varchar(100) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB
id|col1 |col2
1| |644591
2|70083531|1226109
最佳答案
怎么样...
select concat(a.col1,a.col2) as b,
count(a.id) as c
from test a
where concat(a.col1,a.col2) = '644591'
group by concat(a.col1,a.col2)
order by b;
关于MySQL 5.6 InnoDB count、group by、having 和 order by 返回错误结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28344343/