You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- Each row of this table contains the name of a person and their phone number.
13
+
-- Phone number will be in the form 'xxx-yyyyyyy' where xxx is the country code (3 characters) and yyyyyyy is the
14
+
-- phone number (7 characters) where x and y are digits. Both can contain leading zeros.
15
+
-- Table Country:
16
+
17
+
-- +----------------+---------+
18
+
-- | Column Name | Type |
19
+
-- +----------------+---------+
20
+
-- | name | varchar |
21
+
-- | country_code | varchar |
22
+
-- +----------------+---------+
23
+
-- country_code is the primary key for this table.
24
+
-- Each row of this table contains the country name and its code. country_code will be in the form 'xxx' where x is digits.
25
+
26
+
27
+
-- Table Calls:
28
+
29
+
-- +-------------+------+
30
+
-- | Column Name | Type |
31
+
-- +-------------+------+
32
+
-- | caller_id | int |
33
+
-- | callee_id | int |
34
+
-- | duration | int |
35
+
-- +-------------+------+
36
+
-- There is no primary key for this table, it may contain duplicates.
37
+
-- Each row of this table contains the caller id, callee id and the duration of the call in minutes. caller_id != callee_id
38
+
-- A telecommunications company wants to invest in new countries. The country intends to invest in the countries where the average call duration of the calls in this country is strictly greater than the global average call duration.
39
+
40
+
-- Write an SQL query to find the countries where this company can invest.
41
+
42
+
-- Return the result table in any order.
43
+
44
+
-- The query result format is in the following example.
45
+
46
+
-- Person table:
47
+
-- +----+----------+--------------+
48
+
-- | id | name | phone_number |
49
+
-- +----+----------+--------------+
50
+
-- | 3 | Jonathan | 051-1234567 |
51
+
-- | 12 | Elvis | 051-7654321 |
52
+
-- | 1 | Moncef | 212-1234567 |
53
+
-- | 2 | Maroua | 212-6523651 |
54
+
-- | 7 | Meir | 972-1234567 |
55
+
-- | 9 | Rachel | 972-0011100 |
56
+
-- +----+----------+--------------+
57
+
58
+
-- Country table:
59
+
-- +----------+--------------+
60
+
-- | name | country_code |
61
+
-- +----------+--------------+
62
+
-- | Peru | 051 |
63
+
-- | Israel | 972 |
64
+
-- | Morocco | 212 |
65
+
-- | Germany | 049 |
66
+
-- | Ethiopia | 251 |
67
+
-- +----------+--------------+
68
+
69
+
-- Calls table:
70
+
-- +-----------+-----------+----------+
71
+
-- | caller_id | callee_id | duration |
72
+
-- +-----------+-----------+----------+
73
+
-- | 1 | 9 | 33 |
74
+
-- | 2 | 9 | 4 |
75
+
-- | 1 | 2 | 59 |
76
+
-- | 3 | 12 | 102 |
77
+
-- | 3 | 12 | 330 |
78
+
-- | 12 | 3 | 5 |
79
+
-- | 7 | 9 | 13 |
80
+
-- | 7 | 1 | 3 |
81
+
-- | 9 | 7 | 1 |
82
+
-- | 1 | 7 | 7 |
83
+
-- +-----------+-----------+----------+
84
+
85
+
-- Result table:
86
+
-- +----------+
87
+
-- | country |
88
+
-- +----------+
89
+
-- | Peru |
90
+
-- +----------+
91
+
-- The average call duration for Peru is (102 + 102 + 330 + 330 + 5 + 5) / 6 = 145.666667
92
+
-- The average call duration for Israel is (33 + 4 + 13 + 13 + 3 + 1 + 1 + 7) / 8 = 9.37500
93
+
-- The average call duration for Morocco is (33 + 4 + 59 + 59 + 3 + 7) / 6 = 27.5000
0 commit comments