我如何使用 select count (distinct x) 来计算同一个 table 中的两个值并在我的输出中得到这两个不同的值?
How can I use select count (distinct x) in order to count two values in the same table and get the the two distinct values in my output?
我正在尝试使用 count (distinct) 来计算同一 table 中两个不同值的不同值的数量。我试图获得的输出应该将两个不同的值作为两个单独的列。我一直在尝试不同的方法,但我不断收到语法错误。我可以毫无问题地计算其中一个值,但我无法弄清楚两个值的语法。
例如,我可以通过执行来数一:
select count(distinct origin) as distinctOrigin
from flights;
但我想按照以下方式做一些事情:
select count(distinct origin) as distinctOrigin and
select count(distinct dest) as distinctDestination
from flights;
并将两个输出值作为两个单独的列。
你不能在 select
中只使用两个表达式吗?
select count(distinct origin) as distinctOrigin,
count(distinct dest) as distinctDest
from flights ;
我正在尝试使用 count (distinct) 来计算同一 table 中两个不同值的不同值的数量。我试图获得的输出应该将两个不同的值作为两个单独的列。我一直在尝试不同的方法,但我不断收到语法错误。我可以毫无问题地计算其中一个值,但我无法弄清楚两个值的语法。
例如,我可以通过执行来数一:
select count(distinct origin) as distinctOrigin
from flights;
但我想按照以下方式做一些事情:
select count(distinct origin) as distinctOrigin and
select count(distinct dest) as distinctDestination
from flights;
并将两个输出值作为两个单独的列。
你不能在 select
中只使用两个表达式吗?
select count(distinct origin) as distinctOrigin,
count(distinct dest) as distinctDest
from flights ;