本文介绍了获取表中两组不同行的计数,然后将它们除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MySQL的新手,我想提出一个基本上可以做到的查询:

I'm very new to MySQL and I'm trying to come up with a query that basically does:

select * from tasks where completed = 1;

除以...

select * from tasks where completed = 0; 

我一直在寻找解决方案,但只找到了对两个表或行之间的实际值求平均值的方法,但没有对行项进行计数的方法.任何帮助将不胜感激!

I've searched for a solution to this but have only found ways to average actual values between two tables or rows, but by not counts of row items. Any help would be greatly appreciated!

推荐答案

这应该有效:

select
    (select count(*) from tasks where completed = 1) /
    (select count(*) from tasks where completed = 0)
from dual

这篇关于获取表中两组不同行的计数,然后将它们除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 20:30