如何解决加入两个计数查询没有给出正确的结果
我试图加入两个查询来比较计数
SELECT count(customer_id),customer_id
FROM `blog_post`
group by customer_id
第二个查询是
SELECT count(customer_id)
FROM `blog_comment`
WHERE `is_admin` IS NOT NULL
group by customer_id
我创建的联合查询是
SELECT count(post.customer_id) as post_count,post.customer_id,count(comment.customer_id)
FROM `blog_post` as post
left join blog_comment as comment on post.customer_id = comment.customer_id
WHERE `is_admin` IS NOT NULL
GROUP BY post.customer_id
我没有得到与单独运行它们相同的结果,我做错了什么
解决方法
根据您的要求,您需要 2 个查询中的 refreshTable() {
if (this.gridColumnApi.columnController && this.gridColumnApi.columnController.bodyWidthDirty) {
this.gridApi.sizeColumnsToFit();
if (this.refreshAttempts) {
this.refreshAttempts--;
setTimeout(() => {
this.refreshTable();
},100);
}
} else {
this.refreshAttempts = 0;
}
}
,MySql 不支持该查询,只能使用 FULL OUTER JOIN
连接和 LEFT/RIGHT
进行模拟。
>
另一种方法是对 2 个查询使用 UNION ALL
并聚合结果:
UNION ALL
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。