0% found this document useful (0 votes)
927 views2 pages

Uber Analytics Test Q1 & Q3

The document describes several SQL queries to analyze data from tables containing information about continents and countries, including their populations, and about customer trips, including the date and time. It includes queries to calculate the total population per continent, list the top 10 countries by population, identify continents where every country has a population below 300 million, calculate the average number of trips per customer per month and number of unique customers per month, and count the number of trips by the same customer in the last 24 hours for each trip.

Uploaded by

Manas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
927 views2 pages

Uber Analytics Test Q1 & Q3

The document describes several SQL queries to analyze data from tables containing information about continents and countries, including their populations, and about customer trips, including the date and time. It includes queries to calculate the total population per continent, list the top 10 countries by population, identify continents where every country has a population below 300 million, calculate the average number of trips per customer per month and number of unique customers per month, and count the number of trips by the same customer in the last 24 hours for each trip.

Uploaded by

Manas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

You have a dataset with following columns:

a. Continent

b. Country

c. Population

The table has a row for each country in the world

Continent {Text} Country {Text} Population {Number}


Asia India 1.2 Billion
Asia China 1.3 Billion

• Write a SQL query to find total population of each continent? [2]

• Ans: Select Continent, sum(Population) as Total_Count from Table1 group by


Continent ;

• Print the top 10 countries by population [2]

• Ans: Select Country, sum(Population) as Total_Count from Table1 group by


Country order by Total_Count DESC LIMIT 10 ;

• Write queries to output the name of all continents where every country in that 

continent has population below 300 Mn {eg Antarctica, Europe etc.} [4]

• Ans: Create Table Table2 as select *, Case when Population < 300 Mn then 0 else
1 end as Pop_indicator from Table1;

• Select distinct Continent, sum(Pop_indicator) as Continent_Pop_ind from Table2


group by Continent having Continent_Pop_ind =0;

• Write just 1 query to execute task 3 [4]

• Ans: Select Distinct Continent from Table1 where Continent not in (select distinct
Continent from Table1 where population > 300 Mn) ;
3. A table T1 has 3 columns: TripID, CustomerID, Date Time of trip 

TripID is unique for every trip while customerID is unique to a customer. A customer can have
multiple trips.

TripID {Text} CustomerID {Text} Datetime {Datetime}


AB77sjsjjs ijahsdvdhe 1-Jan 2018 00:23:32
nekjwfiwuf nlPCEkhkh 1-Jan 2018 04:18:16

• What is the average trips/customer monthly number (SQL Query to calculate) [2]

• Ans: Create Table Table2 as select *, (case when DATEPART(month, Datetime) <
10 then concat(DATEPART(year, Datetime),0,DATEPART(month, Datetime)) else
concat(DATEPART(year, Datetime),DATEPART(month,Datetime)) end) AS Month
from Table1;

• Ans: Select Month, Count(TripID)/Count(distinct CustomerID) as


Avg_Monthly_trip_count from Table2 group by Month;

• Monthly unique customers (SQL Query) [2]

• Ans: Select Month, count(distinct CustomerID) as Unq_Cust from Table2 group by


Month;

• Create a table with same columns as T1 + an additional column that counts Trips 

by same customer in last 24 hrs ( for each TripID, count the number of trips by same
customerID in 24 hour from datetime of that tripID) [4]

• Ans: Create Table Table3 as Select a.TripID, a.CustomerID, a.Datetime,


count(*) as Trip_Count24 from table1 as a left join table1 as b on
a.CustomerID=b.CustomerID where 0 < DATEDIFF(hour, a.Datetime,
b.Datetime) <=24 group by a.TripID, a.CustomerID, a.Datetime;

You might also like