简体   繁体   中英

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?

I am trying to use count (distinct) in order to count the number of distinct values for two different values in the same table. The output I am trying to get should have both of the distinct values as two separate columns. I have been trying different methods but I keep on getting syntax errors. I am able to to count just one of the values without any problem, but I can not figure out the syntax for two.

For example, I can count one by executing:

select count(distinct origin) as distinctOrigin
from flights;

But I want to do something along the lines of this:

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

And get two output values as two separate columns.

Can't you just have two expressions in the select ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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