Mysql 如何使用select count(distinct x)对同一个表中的两个值进行计数,并在输出中获得两个不同的值?

Mysql 如何使用select count(distinct x)对同一个表中的两个值进行计数,并在输出中获得两个不同的值?,mysql,sql,count,distinct,Mysql,Sql,Count,Distinct,我试图使用count(distinct)来计算同一个表中两个不同值的不同值的数量。我试图获取的输出应该将两个不同的值作为两个单独的列。我一直在尝试不同的方法,但我不断得到语法错误。我能够只计算其中一个值而没有任何问题,但我无法理解两个值的语法 例如,我可以通过执行以下命令来计算一个数: select count(distinct origin) as distinctOrigin from flights; 但我想做一些类似的事情: select count(distinct origin)

我试图使用count(distinct)来计算同一个表中两个不同值的不同值的数量。我试图获取的输出应该将两个不同的值作为两个单独的列。我一直在尝试不同的方法,但我不断得到语法错误。我能够只计算其中一个值而没有任何问题,但我无法理解两个值的语法

例如,我可以通过执行以下命令来计算一个数:

select count(distinct origin) as distinctOrigin
from flights;
但我想做一些类似的事情:

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

并将两个输出值作为两个单独的列获取。

选择中不能有两个表达式吗

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

我会使用join语句吗?我没有试过这个,因为他们在同一张桌子上。是的,这个很有效。我真的以为我试过这个语法。。。一定是忽略了逗号,并尝试在其中插入and。谢谢此处演示: