-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweather-dql.sql
71 lines (66 loc) · 2.28 KB
/
weather-dql.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
-- weather-dql.sql
-- 1.
SELECT
wi.details ->> 'name' name,
wi.details ->> 'weather' weather_description,
wi.details ->> 'wind' wind,
wi.createdon,
wi.id
FROM weather.info wi
ORDER BY name, id;
-- 2.
SELECT DISTINCT
wi.details ->> 'name' AS city_name,
wi.details ->> 'weather' AS weather_description,
wi.details -> 'main' ->> 'temp' AS temp_deg_C,
wi.details -> 'main' ->> 'humidity' AS humd_percent,
wi.details -> 'main' ->> 'pressure' AS press_hPa,
wi.details -> 'wind' ->> 'deg' AS wind_direc_deg,
wi.details -> 'wind' ->> 'gust' AS wind_gust_meter_p_sec,
wi.details -> 'wind' ->> 'speed' AS wind_speed_meter_p_sec,
wi.createdon,
wi.id
FROM weather.info wi
ORDER BY name, id;
-- 3.
SELECT
wi.details ->> 'name' AS city_name,
wi.details -> 'weather' ->0 ->> 'description' AS weather_description,
wi.details -> 'main' ->> 'temp' AS temp_deg_C,
wi.details -> 'main' ->> 'humidity' AS humd_percent,
wi.details -> 'main' ->> 'pressure' AS press_hPa,
wi.details -> 'wind' ->> 'deg' AS wind_direc_deg,
wi.details -> 'wind' ->> 'gust' AS wind_gust_meter_p_sec,
wi.details -> 'wind' ->> 'speed' AS wind_speed_meter_p_sec,
wi.createdon,
wi.id
FROM weather.info wi
WHERE details ->> 'name' IN (
'Gaborone', 'Abuja', 'Akure', 'Cairo', 'Dubai',
'Muscat', 'Lagos', 'Katy', 'Houston', 'Tokyo',
'Delhi', 'Austin', 'London', 'Moscow', 'Taipei',
'Edmonton', 'San Rafael', 'Helsinki', 'New York',
'Los Angeles', 'San Antonio', 'Sydney', 'Rijswijk',
'Bahir Dar', 'Casablanca', 'Toronto', 'Dhaka',
'Bangui', 'Cape Town', 'Beijing'
)
AND details -> 'main' ->> 'temp' > '10'
ORDER BY city_name ASC, id;
-- 4.
SELECT COUNT(*) FROM weather.info;
-- 5.
SELECT
wi.details ->> 'name' AS name,
wi.details -> 'weather' ->0 ->> 'description' AS weather_description,
wi.details -> 'main' ->> 'temp' AS temp_deg_C,
wi.details -> 'main' ->> 'humidity' AS humd_percent,
wi.details -> 'main' ->> 'pressure' AS press_hPa,
wi.details -> 'wind' ->> 'deg' AS wind_direc_deg,
wi.details -> 'wind' ->> 'gust' AS wind_gust_meter_p_sec,
wi.details -> 'wind' ->> 'speed' AS wind_speed_meter_p_sec,
wi.createdon,
wi.id
FROM weather.info wi
WHERE details ->> 'name' IN ('Abuja', 'Akure', 'Austin')
AND details -> 'main' ->> 'temp' > '10'
ORDER BY name ASC, id;