2

I am trying to see statistics of how many passenger passed from my application. After selecting this query;

select count(person_id), person_id from Passenger group by person_id;

count(person_id)    person_id
6                  123
2                  421
1                  542
3                  612
1                  643
2                  876

I see that passenger "123" passed 6 times. "421" passed 2 times. "542" passed 1 times etc.. So I want to make analyze and say that;

>     1 passenger passed 6 times,
>     2 passenger passed 2 times,
>     2 passenger passed 1 times,
>     1 passenger passed 3 times..

Here is sqlFiddle for your better understanding..

3 Answers 3

2

You can use a SELECT with a subquery to obtain the result you want:

SELECT Concat(COUNT(*), ' passenger passed ', table.theCount, ' times,') FROM
(
    SELECT COUNT(person_id) AS theCount, person_id
    FROM Passenger
    GROUP BY person_id
) table
GROUP BY table.theCount
Sign up to request clarification or add additional context in comments.

Comments

1
select cnt, count(person_id)
from
(
  select count(person_id) as cnt, person_id 
  from Passenger 
  group by person_id
) tmp
group by cnt

Comments

0

Is this what you are looking for?

select count(person_id) as "Num passengers", times
from (
  select count(person_id) as times, person_id
from Passenger 
group by person_id
) sub
group by times order by times ASC

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.