This repository was archived by the owner on Feb 10, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathsample_queries.sql
More file actions
91 lines (80 loc) · 2.53 KB
/
Copy pathsample_queries.sql
File metadata and controls
91 lines (80 loc) · 2.53 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
-- Sample SQL Queries for Sustainable Energy Database
-- Database: sustainable_energy.db
-- Table: sustainable_energy
-- 1. View all available columns
SELECT sql FROM sqlite_master WHERE type='table' AND name='sustainable_energy';
-- 2. Get total number of records
SELECT COUNT(*) as total_records FROM sustainable_energy;
-- 3. Get unique countries/entities
SELECT DISTINCT Entity FROM sustainable_energy ORDER BY Entity;
-- 4. Get data for a specific country (e.g., Italy)
SELECT
Entity,
Year,
Access_to_electricity_pct_of_population,
Renewable_energy_share_in_the_total_final_energy_consumption_pct,
Electricity_from_renewables_TWh,
Value_co2_emissions_kt_by_country
FROM sustainable_energy
WHERE Entity = 'Italy'
ORDER BY Year;
-- 5. Get countries with highest renewable energy share in 2020
SELECT
Entity,
Year,
Renewable_energy_share_in_the_total_final_energy_consumption_pct,
Electricity_from_renewables_TWh
FROM sustainable_energy
WHERE Year = 2020
AND Renewable_energy_share_in_the_total_final_energy_consumption_pct IS NOT NULL
ORDER BY Renewable_energy_share_in_the_total_final_energy_consumption_pct DESC
LIMIT 10;
-- 6. Get average CO2 emissions by country (latest year available)
SELECT
Entity,
MAX(Year) as latest_year,
AVG(Value_co2_emissions_kt_by_country) as avg_co2_emissions
FROM sustainable_energy
WHERE Value_co2_emissions_kt_by_country IS NOT NULL
GROUP BY Entity
ORDER BY avg_co2_emissions DESC
LIMIT 20;
-- 7. Get countries with 100% electricity access in 2020
SELECT
Entity,
Year,
Access_to_electricity_pct_of_population
FROM sustainable_energy
WHERE Year = 2020
AND Access_to_electricity_pct_of_population >= 100
ORDER BY Entity;
-- 8. Get year range for each country
SELECT
Entity,
MIN(Year) as first_year,
MAX(Year) as last_year,
COUNT(*) as data_points
FROM sustainable_energy
GROUP BY Entity
ORDER BY Entity;
-- 9. Get countries with highest GDP per capita in 2020
SELECT
Entity,
Year,
gdp_per_capita,
gdp_growth
FROM sustainable_energy
WHERE Year = 2020
AND gdp_per_capita IS NOT NULL
ORDER BY gdp_per_capita DESC
LIMIT 20;
-- 10. Compare renewable energy trends for multiple countries
SELECT
Entity,
Year,
Renewable_energy_share_in_the_total_final_energy_consumption_pct,
Electricity_from_renewables_TWh
FROM sustainable_energy
WHERE Entity IN ('Germany', 'France', 'Italy', 'Spain', 'United Kingdom')
AND Renewable_energy_share_in_the_total_final_energy_consumption_pct IS NOT NULL
ORDER BY Entity, Year;