繁体   English   中英

如何使用 select 计数(不同的 x)来计算同一个表中的两个值并在我的 output 中获取两个不同的值?

[英]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) 来计算同一个表中两个不同值的不同值的数量。 我试图获得的 output 应该将两个不同的值作为两个单独的列。 我一直在尝试不同的方法,但我不断收到语法错误。 我可以毫无问题地只计算其中一个值,但我无法弄清楚两个值的语法。

例如,我可以通过执行来数一个:

select count(distinct origin) as distinctOrigin
from flights;

但我想做一些类似的事情:

select count(distinct origin) as distinctOrigin and
select count(distinct dest) as distinctDestination
from flights;

并获得两个 output 值作为两个单独的列。

你不能在select中只有两个表达式吗?

select count(distinct origin) as distinctOrigin,
       count(distinct dest) as distinctDest
from flights ;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM