1

I have a table with following structure.

Flight_ID      |     Source_city    |    DestinatinCity
    1                  NYC                  LONDON
    2                 LONDON                TOKYO
    3                 LONDON                 NYC

I want to found city count i.e cities involved in source and destination,

city      | count
LONDON        3
NYC           2
TOKYO         1

How can I solve it using basic SQL features(Without PL).

2
  • What's meany by PL? Commented Mar 22, 2017 at 15:22
  • 1
    @RajasubaSubramanian May be Stored Procedures Commented Mar 22, 2017 at 15:48

2 Answers 2

3

Use union all and aggregation.

select city,count(*) as cnt
from (
select flight_Id,source_city as city from t
union all 
select flight_Id,destination_city from t
) x
group by city
Sign up to request clarification or add additional context in comments.

Comments

0

You can achieve it with union all

select source_city as city, count(*) from table_name union all select dest_city,count(*) from table_name group by source_city;

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.