How to query public data sets using BigQuery
BigQuery is a fully managed data warehouse and analytics platform. Public datasets are available for you to analyze using SQL queries. You can access BigQuery public data sets using the web UI, the command-line tool, or by making calls to the BigQuery REST API using a variety of client libraries such as Java, .NET, or Python.
Currently, BigQuery public datasets are stored in the
location. When you query a public dataset, supply
--location=US flag on the command line, choose
US as the
processing location in the BigQuery web UI, or specify the
location property in the
jobReference section of the job resource
when you use the API. Because the public datasets are stored in the US, you cannot write public
data query results to a table in another region, and you cannot join tables in public datasets
with tables in another region.
To get started using a BigQuery public dataset, create or select a project. The first terabyte of data processed per month is free, so you can start querying public datasets without enabling billing. If you intend to go beyond the free tier, you should also enable billing.
Sign in to your Google Account.
If you don't already have one, sign up for a new account.
Select or create a GCP project.
Make sure that billing is enabled for your project.
- BigQuery is automatically enabled in new projects. To activate BigQuery in a pre-existing project, Enable the BigQuery API.
This dataset combines key education statistics from a variety of sources to provide a look at global literacy, spending, and access.
For more information, see the World Bank website.
You can start exploring this data in the BigQuery console:
Here are some examples of SQL queries you can run on this data in BigQuery.
These samples use BigQuery’s support for standard SQL. Use the
#standardSQL tag to let BigQuery know you want to use standard SQL. For more
information about the
#standardSQL prefix, see
Setting a query prefix.
Of total government spending, what percentage is spent on education?
This query retrieves government spending on education from the year 2000 to the present. This range ensures enough countries are represented (reporting can be sparse), and it smooths any inconsistencies in the data.
#standardSQL SELECT country_name, AVG(value) AS average FROM `bigquery-public-data.world_bank_intl_education.international_education` WHERE indicator_code = "SE.XPD.TOTL.GB.ZS" AND year > 2000 GROUP BY country_name ORDER BY average DESC
bq query --use_legacy_sql=false ' SELECT country_name, AVG(value) AS average FROM `bigquery-public-data.world_bank_intl_education.international_education` WHERE indicator_code = "SE.XPD.TOTL.GB.ZS" AND year > 2000 GROUP BY country_name ORDER BY average DESC'
Sample results are shown here:
+--------------------------------+--------------------+ | country_name | average | +--------------------------------+--------------------+ | Vanuatu | 30.541126251220685 | | Lesotho | 27.614941188267313 | | Tunisia | 25.567561236294846 | | Kenya | 24.601095744541716 | | Ghana | 24.306796160611253 | | Ethiopia | 24.28029394149782 | | Botswana | 24.269573211669933 | | Namibia | 22.96822834014892 | | St. Vincent and the Grenadines | 22.605224609375014 | | Djibouti | 22.52495741844175 | | ... | +--------------------------------+--------------------+
The following visualization presents an interesting comparison between countries. In the chart, the countries in gray don’t have sufficient data. You can view this visualization in Google Data Studio. For a tutorial on using Google Data Studio with BigQuery, see Visualizing BigQuery Data Using Google Data Studio.
About the data
Dataset Source: World Bank
Category: Encyclopedic, Economic
Use: This dataset is publicly available for anyone to use under the following terms provided by the Dataset Source - http://www.data.gov/privacy-policy#data_policy - and is provided "AS IS" without any warranty, express or implied, from Google. Google disclaims all liability for any damages, direct or indirect, resulting from the use of the dataset.
Citation: The World Bank: Education Statistics
Update Frequency: Biannual
View in BigQuery: Go to World Bank education data