Exercise 19:1635. Hopper Company Queries I

1.Description

Table: Drivers

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| driver_id   | int     |
| join_date   | date    |
+-------------+---------+
driver_id is the primary key for this table.
Each row of this table contains the driver's ID and the date they joined the Hopper company.

Table: Rides

+--------------+---------+
| Column Name  | Type    |
+--------------+---------+
| ride_id      | int     |
| user_id      | int     |
| requested_at | date    |
+--------------+---------+
ride_id is the primary key for this table.
Each row of this table contains the ID of a ride, the user's ID that requested it, and the day they requested it.
There may be some ride requests in this table that were not accepted.

Table: AcceptedRides

Write an SQL query to report the following statistics for each month of 2020:

  • The number of drivers currently with the Hopper company by the end of the month (active_drivers).

  • The number of accepted rides in that month (accepted_rides).

Return the result table ordered by month in ascending order, where month is the month's number (January is 1, February is 2, etc.).

The query result format is in the following example.

2.Create Table and insert into values

In order to prevent the stability of big data clusters. Similar non-congruent joins (non-inner joins) are forbidden, and SemanticException Cartesian products are disabled.

IF we want non-congruent joins, Add two settings before the query:

set hive.strict.checks.cartesian.product=flase;

set hive.mapred.mode=nonstrict;

Check this link for more detail.

Last updated