{"id":1114,"date":"2013-12-26T14:00:26","date_gmt":"2013-12-26T14:00:26","guid":{"rendered":"http:\/\/all-geo.org\/volcan01010\/?p=1114"},"modified":"2014-01-01T14:09:58","modified_gmt":"2014-01-01T14:09:58","slug":"generate-volcano-trivia-with-this-sqlite-tutorial","status":"publish","type":"post","link":"https:\/\/all-geo.org\/volcan01010\/2013\/12\/generate-volcano-trivia-with-this-sqlite-tutorial\/","title":{"rendered":"Generate volcano trivia with this SQLite tutorial"},"content":{"rendered":"<p>Excel is not a database. Even so, spreadsheets are commonly used as such. They are convenient places to enter and store data, but not to get it out again. This post aims to show how using a real database makes this easier.<\/p>\n<p>It uses an SQLite database, which is what many browsers (e.g. Firefox) use to store your bookmarks and history. These can also be read by other software e.g. Geographic Information Systems. It has none of the overly-complex wrappings of MS Access or LibreOffice Base and doesn&#8217;t need a server like MySQL or Oracle. Once the data are imported, typically from a comma separated value (<i>csv<\/i>) file, it simply provides an interface so that we can ask questions using Structured Query Language (SQL).<\/p>\n<p>This example uses the Smithsonian Institute&#8217;s Global Volcanism Program catalogue of volcanoes, which can be downloaded as a csv file from <a href=\"http:\/\/www.volcano.si.edu\/list_volcano_excel.cfm\">their website<\/a>, as the database.\u00a0 It lists locations and recent eruptions of over 1,500 active volcanoes. Querying the list can generate a wealth of interesting (and less-interesting) volcano facts.<\/p>\n<p>The commands may look complicated at first, but hopefully you can see where the advantages in a real database lie.\u00a0 If so, there are instructions for getting started at the end.\u00a0 If not, just enjoy the trivia.<\/p>\n<h3>Get an A-Z list of all the volcanoes in the world.<\/h3>\n<pre>SELECT \"Volcano Name\" FROM GVPVolcano\r\nORDER BY \"Volcano Name\";<\/pre>\n<table>\n<tbody>\n<tr>\n<th>Volcano name<\/th>\n<\/tr>\n<tr>\n<td>Abu<\/td>\n<\/tr>\n<tr>\n<td>Babuyan Claro<\/td>\n<\/tr>\n<tr>\n<td>Cabal\u00edan<\/td>\n<\/tr>\n<tr>\n<td>Dabbahu<\/td>\n<\/tr>\n<tr>\n<td>E-san<\/td>\n<\/tr>\n<tr>\n<td>Falcon Island<\/td>\n<\/tr>\n<tr>\n<td>Gabillema<\/td>\n<\/tr>\n<tr>\n<td>Hachijo-jima<\/td>\n<\/tr>\n<tr>\n<td>Iamalele<\/td>\n<\/tr>\n<tr>\n<td>Jailolo<\/td>\n<\/tr>\n<tr>\n<td>Kaba<\/td>\n<\/tr>\n<tr>\n<td>La Palma<\/td>\n<\/tr>\n<tr>\n<td>Ma Alalta<\/td>\n<\/tr>\n<tr>\n<td>NW Eifuku<\/td>\n<\/tr>\n<tr>\n<td>O&#8217;a Caldera<\/td>\n<\/tr>\n<tr>\n<td>Pacaya<\/td>\n<\/tr>\n<tr>\n<td>Qal&#8217;eh Hasan Ali<\/td>\n<\/tr>\n<tr>\n<td>Rabaul<\/td>\n<\/tr>\n<tr>\n<td>SW Usangu Basin<\/td>\n<\/tr>\n<tr>\n<td>Ta&#8217;u<\/td>\n<\/tr>\n<tr>\n<td>Ubehebe Craters<\/td>\n<\/tr>\n<tr>\n<td>Vailulu&#8217;u<\/td>\n<\/tr>\n<tr>\n<td>Waesche<\/td>\n<\/tr>\n<tr>\n<td>Xianjindao<\/td>\n<\/tr>\n<tr>\n<td>Yake-dake<\/td>\n<\/tr>\n<tr>\n<td>Zacate Grande, Isla<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The database contains information on 1555 volcanoes. That&#8217;s a big spreadsheet to manipulate by hand. This list is trimmed to give just the first example for each letter of the alphabet. There are 160 volcanoes whose name begins with &#8216;S&#8217;, but only one that begins with &#8216;X&#8217; (Xianjindo in North Korea).<\/p>\n<h3>Get a list of all the volcanoes in Iceland.<\/h3>\n<pre>SELECT \"Volcano Name\" FROM GVPVolcano\r\n  WHERE \"Country\" IS \"Iceland\";<\/pre>\n<table>\n<tbody>\n<tr>\n<th>Volcano Name<\/th>\n<\/tr>\n<tr>\n<td>Snaefellsj\u00f6kull<\/td>\n<\/tr>\n<tr>\n<td>Helgrindur<\/td>\n<\/tr>\n<tr>\n<td>Lj\u00f3sufj\u00f6ll<\/td>\n<\/tr>\n<tr>\n<td>Reykjanes<\/td>\n<\/tr>\n<tr>\n<td>Kr\u00edsuv\u00edk<\/td>\n<\/tr>\n<tr>\n<td>Brennisteinsfj\u00f6ll<\/td>\n<\/tr>\n<tr>\n<td>Hengill<\/td>\n<\/tr>\n<tr>\n<td>Hr\u00f3mundartindur<\/td>\n<\/tr>\n<tr>\n<td>Gr\u00edmsnes<\/td>\n<\/tr>\n<tr>\n<td>Prestahnukur<\/td>\n<\/tr>\n<tr>\n<td>Hveravellir<\/td>\n<\/tr>\n<tr>\n<td>Hofsj\u00f6kull<\/td>\n<\/tr>\n<tr>\n<td>Vestmannaeyjar<\/td>\n<\/tr>\n<tr>\n<td>Eyjafjallaj\u00f6kull<\/td>\n<\/tr>\n<tr>\n<td>Katla<\/td>\n<\/tr>\n<tr>\n<td>Tindfjallaj\u00f6kull<\/td>\n<\/tr>\n<tr>\n<td>Torfaj\u00f6kull<\/td>\n<\/tr>\n<tr>\n<td>Hekla<\/td>\n<\/tr>\n<tr>\n<td>Gr\u00edmsv\u00f6tn<\/td>\n<\/tr>\n<tr>\n<td>B\u00e1rdarbunga<\/td>\n<\/tr>\n<tr>\n<td>Tungnafellsj\u00f6kull<\/td>\n<\/tr>\n<tr>\n<td>Kverkfj\u00f6ll<\/td>\n<\/tr>\n<tr>\n<td>Askja<\/td>\n<\/tr>\n<tr>\n<td>Fremrinamur<\/td>\n<\/tr>\n<tr>\n<td>Krafla<\/td>\n<\/tr>\n<tr>\n<td>Theistareykjarbunga<\/td>\n<\/tr>\n<tr>\n<td>Tj\u00f6rnes Fracture Zone<\/td>\n<\/tr>\n<tr>\n<td>\u00d6raefaj\u00f6kull<\/td>\n<\/tr>\n<tr>\n<td>Esjufj\u00f6ll<\/td>\n<\/tr>\n<tr>\n<td>Kolbeinsey Ridge<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>If you wanted to plot them on a map, you can get their latitude and longitude, too.<\/p>\n<pre>SELECT \"Volcano Name\", Longitude, Latitude FROM GVPVolcano\r\n  WHERE \"Country\" IS \"Iceland\";<\/pre>\n<table>\n<tbody>\n<tr>\n<th>Volcano Name<\/th>\n<th>Longitude<\/th>\n<th>Latitude<\/th>\n<\/tr>\n<tr>\n<td>Snaefellsj\u00f6kull<\/td>\n<td>-23.78<\/td>\n<td>64.8<\/td>\n<\/tr>\n<tr>\n<td>Helgrindur<\/td>\n<td>-23.25<\/td>\n<td>64.87<\/td>\n<\/tr>\n<tr>\n<td>Lj\u00f3sufj\u00f6ll<\/td>\n<td>-22.23<\/td>\n<td>64.87<\/td>\n<\/tr>\n<tr>\n<td>Reykjanes<\/td>\n<td>-22.5<\/td>\n<td>63.88<\/td>\n<\/tr>\n<tr>\n<td>Kr\u00edsuv\u00edk<\/td>\n<td>-22.1<\/td>\n<td>63.93<\/td>\n<\/tr>\n<tr>\n<td>Brennisteinsfj\u00f6ll<\/td>\n<td>-21.83<\/td>\n<td>63.92<\/td>\n<\/tr>\n<tr>\n<td>Hengill<\/td>\n<td>-21.32<\/td>\n<td>64.08<\/td>\n<\/tr>\n<tr>\n<td>Hr\u00f3mundartindur<\/td>\n<td>-21.202<\/td>\n<td>64.073<\/td>\n<\/tr>\n<tr>\n<td>Gr\u00edmsnes<\/td>\n<td>-20.87<\/td>\n<td>64.03<\/td>\n<\/tr>\n<tr>\n<td>Prestahnukur<\/td>\n<td>-20.58<\/td>\n<td>64.6<\/td>\n<\/tr>\n<tr>\n<td>Hveravellir<\/td>\n<td>-19.98<\/td>\n<td>64.75<\/td>\n<\/tr>\n<tr>\n<td>Hofsj\u00f6kull<\/td>\n<td>-18.92<\/td>\n<td>64.78<\/td>\n<\/tr>\n<tr>\n<td>Vestmannaeyjar<\/td>\n<td>-20.28<\/td>\n<td>63.43<\/td>\n<\/tr>\n<tr>\n<td>Eyjafjallaj\u00f6kull<\/td>\n<td>-19.62<\/td>\n<td>63.63<\/td>\n<\/tr>\n<tr>\n<td>Katla<\/td>\n<td>-19.05<\/td>\n<td>63.63<\/td>\n<\/tr>\n<tr>\n<td>Tindfjallaj\u00f6kull<\/td>\n<td>-19.57<\/td>\n<td>63.78<\/td>\n<\/tr>\n<tr>\n<td>Torfaj\u00f6kull<\/td>\n<td>-19.17<\/td>\n<td>63.92<\/td>\n<\/tr>\n<tr>\n<td>Hekla<\/td>\n<td>-19.7<\/td>\n<td>63.98<\/td>\n<\/tr>\n<tr>\n<td>Gr\u00edmsv\u00f6tn<\/td>\n<td>-17.33<\/td>\n<td>64.42<\/td>\n<\/tr>\n<tr>\n<td>B\u00e1rdarbunga<\/td>\n<td>-17.53<\/td>\n<td>64.63<\/td>\n<\/tr>\n<tr>\n<td>Tungnafellsj\u00f6kull<\/td>\n<td>-17.92<\/td>\n<td>64.73<\/td>\n<\/tr>\n<tr>\n<td>Kverkfj\u00f6ll<\/td>\n<td>-16.72<\/td>\n<td>64.65<\/td>\n<\/tr>\n<tr>\n<td>Askja<\/td>\n<td>-16.75<\/td>\n<td>65.03<\/td>\n<\/tr>\n<tr>\n<td>Fremrinamur<\/td>\n<td>-16.65<\/td>\n<td>65.43<\/td>\n<\/tr>\n<tr>\n<td>Krafla<\/td>\n<td>-16.78<\/td>\n<td>65.73<\/td>\n<\/tr>\n<tr>\n<td>Theistareykjarbunga<\/td>\n<td>-16.83<\/td>\n<td>65.88<\/td>\n<\/tr>\n<tr>\n<td>Tj\u00f6rnes Fracture Zone<\/td>\n<td>-17.1<\/td>\n<td>66.3<\/td>\n<\/tr>\n<tr>\n<td>\u00d6raefaj\u00f6kull<\/td>\n<td>-16.65<\/td>\n<td>64.0<\/td>\n<\/tr>\n<tr>\n<td>Esjufj\u00f6ll<\/td>\n<td>-16.65<\/td>\n<td>64.27<\/td>\n<\/tr>\n<tr>\n<td>kolbeinsey ridge<\/td>\n<td>-18.5<\/td>\n<td>66.67<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>What can you tell me about Hekla?<\/h3>\n<pre>SELECT * FROM GVPVolcano\r\n WHERE \"Volcano Name\" IS \"Hekla\";<\/pre>\n<p>There isn&#8217;t room to show all the columns as a table, but the data look like:<\/p>\n<p><em>Volcano Number =<\/em> 372070<br \/>\n<em>Volcano Name =<\/em> Hekla<br \/>\n<em>Country =<\/em> Iceland<br \/>\n<em>Primary Volcano Type =<\/em> Stratovolcano<br \/>\n<em>Last Known Eruption =<\/em> 2000 CE<br \/>\n<em>Region =<\/em> Iceland and Arctic Ocean<br \/>\n<em>Subregion =<\/em> Iceland (southern)<br \/>\n<em>Latitude =<\/em> 63.98<br \/>\n<em>Longitude<\/em> = -19.7<br \/>\n<em>Elevation (m) =<\/em> 1491.0<br \/>\n<em>Dominant Rock Type =<\/em> Andesite \/ Basaltic Andesite<br \/>\n<em>Tectonic Setting =<\/em> Tensional Oceanic<\/p>\n<h3>Which is taller, Mt Fiji or Mt Etna?<\/h3>\n<pre>SELECT \"Volcano Name\", \"Elevation (m)\" FROM GVPVolcano\r\n  WHERE \"Volcano Name\" is \"Fuji\"\r\n  OR \"Volcano Name\" IS \"Etna\";<\/pre>\n<table>\n<tbody>\n<tr>\n<th>Volcano Name<\/th>\n<th>Elevation (m)<\/th>\n<\/tr>\n<tr>\n<td>Etna<\/td>\n<td>3330.0<\/td>\n<\/tr>\n<tr>\n<td>Fuji<\/td>\n<td>3776.0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Fuji wins! But Etna has been trying hard to catch up recently.<\/p>\n<p><iframe loading=\"lazy\" title=\"Paroxysm at Etna, 16-17 November 2013\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/WIHk_A0z0Rc?start=95&#038;feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<h3>What are the 10 tallest volcanoes in the world?<\/h3>\n<pre>SELECT \"Volcano Name\", Country, \"Elevation (m)\" FROM GVPVolcano\r\nWHERE \"Elevation (m)\" IS NOT \"NaN\"\r\nORDER BY \"Elevation (m)\" DESC\r\nLIMIT 10;<\/pre>\n<table>\n<tbody>\n<tr>\n<th>Volcano Name<\/th>\n<th>Country<\/th>\n<th>Elevation (m)<\/th>\n<\/tr>\n<tr>\n<td>Ojos del Salado, Nevados<\/td>\n<td>Chile-Argentina<\/td>\n<td>6887.0<\/td>\n<\/tr>\n<tr>\n<td>Llullaillaco<\/td>\n<td>Chile-Argentina<\/td>\n<td>6739.0<\/td>\n<\/tr>\n<tr>\n<td>Tipas<\/td>\n<td>Argentina<\/td>\n<td>6660.0<\/td>\n<\/tr>\n<tr>\n<td>Incahuasi, Nevado de<\/td>\n<td>Chile-Argentina<\/td>\n<td>6621.0<\/td>\n<\/tr>\n<tr>\n<td>C\u00f3ndor, Cerro el<\/td>\n<td>Argentina<\/td>\n<td>6532.0<\/td>\n<\/tr>\n<tr>\n<td>Coropuna<\/td>\n<td>Peru<\/td>\n<td>6377.0<\/td>\n<\/tr>\n<tr>\n<td>Parinacota<\/td>\n<td>Chile-Bolivia<\/td>\n<td>6348.0<\/td>\n<\/tr>\n<tr>\n<td>Chimborazo<\/td>\n<td>Ecuador<\/td>\n<td>6310.0<\/td>\n<\/tr>\n<tr>\n<td>Pular<\/td>\n<td>Chile<\/td>\n<td>6233.0<\/td>\n<\/tr>\n<tr>\n<td>Solo, El<\/td>\n<td>Chile-Argentina<\/td>\n<td>6190.0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>They are all in western South America. I suppose that this region has the advantage of the Pacific plate being subducted under the South American continent and pushing up the Andes mountain range. The volcanoes just sit on top of it. This highlights the issue that your definition of the tallest may depend on where you are measuring from. Sea level, the Earth&#8217;s crust, the centre of the Earth? This video from <a href=\"http:\/\/www.youtube.com\/watch?v=3yqJdhWKjBU\">BBC Planet Earth Unplugged<\/a> explains this nicely.<\/p>\n<div style=\"width: 522px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/volcano.si.edu\/volcano.cfm?vn=355130\"><img loading=\"lazy\" decoding=\"async\" class=\" \" alt=\"\" src=\"http:\/\/volcano.si.edu\/Photos\/full\/069007.jpg\" width=\"512\" height=\"374\" \/><\/a><p class=\"wp-caption-text\">Ojos de Salados, on the Chile-Argentina border, is 6888 m tall and last erupted around 700 AD. Source: http:\/\/volcano.si.edu\/volcano.cfm?vn=355130<\/p><\/div>\n<h3>What are the 5 northernmost volcanoes in the world?<\/h3>\n<pre>SELECT \"Volcano Name\", Country, Latitude, \"Tectonic Setting\" \r\n FROM GVPVolcano\r\n ORDER BY Latitude DESC\r\n LIMIT 5;<\/pre>\n<table>\n<tbody>\n<tr>\n<th>Volcano Name<\/th>\n<th>Country<\/th>\n<th>Latitude<\/th>\n<th>Tectonic Setting<\/th>\n<\/tr>\n<tr>\n<td>Unnamed<\/td>\n<td>Undersea Features<\/td>\n<td>88.27<\/td>\n<td>Tensional Oceanic<\/td>\n<\/tr>\n<tr>\n<td>Unnamed<\/td>\n<td>Undersea Features<\/td>\n<td>85.58<\/td>\n<td>Tensional Oceanic<\/td>\n<\/tr>\n<tr>\n<td>Jan Mayen<\/td>\n<td>Norway<\/td>\n<td>71.08<\/td>\n<td>Tensional Oceanic<\/td>\n<\/tr>\n<tr>\n<td>Kolbeinsey Ridge<\/td>\n<td>Iceland<\/td>\n<td>66.67<\/td>\n<td>Tensional Oceanic<\/td>\n<\/tr>\n<tr>\n<td>Tj\u00f6rnes Fracture Zone<\/td>\n<td>Iceland<\/td>\n<td>66.3<\/td>\n<td>Tensional Oceanic<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>They all relate to the mid-ocean ridges, whereas the southern ones are all in Antarctica and are relate to subduction. There are no active volcanoes within 1,100 km of the South Pole.<\/p>\n<table>\n<tbody>\n<tr>\n<th>Volcano Name<\/th>\n<th>Country<\/th>\n<th>Latitude<\/th>\n<th>Tectonic Setting<\/th>\n<\/tr>\n<tr>\n<td>Morning, Mt.<\/td>\n<td>Antarctica<\/td>\n<td>-78.5<\/td>\n<td>Intermediate Continental<\/td>\n<\/tr>\n<tr>\n<td>Royal Society Range<\/td>\n<td>Antarctica<\/td>\n<td>-78.25<\/td>\n<td>Intermediate Continental<\/td>\n<\/tr>\n<tr>\n<td>Erebus<\/td>\n<td>Antarctica<\/td>\n<td>-77.53<\/td>\n<td>Intermediate Continental<\/td>\n<\/tr>\n<tr>\n<td>Waesche<\/td>\n<td>Antarctica<\/td>\n<td>-77.17<\/td>\n<td>Intermediate Continental<\/td>\n<\/tr>\n<tr>\n<td>Unnamed<\/td>\n<td>Antarctica<\/td>\n<td>-76.83<\/td>\n<td>Intermediate Continental<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div style=\"width: 522px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/volcano.si.edu\/volcano.cfm?vn=390017\"><img loading=\"lazy\" decoding=\"async\" class=\" \" alt=\"\" src=\"http:\/\/volcano.si.edu\/Photos\/full\/121047.jpg\" width=\"512\" height=\"342\" \/><\/a><p class=\"wp-caption-text\">Mount Morning, Antarctica, is the southernmost volcano in the world. Source: http:\/\/volcano.si.edu\/volcano.cfm?vn=390017<\/p><\/div>\n<h3>What are the most volcanically active countries in the world?<\/h3>\n<pre>SELECT Country, COUNT(Country) AS NumberOfVolcanoes FROM GVPVolcano\r\n  GROUP BY Country\r\n  ORDER BY NumberOfVolcanoes DESC\r\n  LIMIT 5;<\/pre>\n<table>\n<tbody>\n<tr>\n<th>Country<\/th>\n<th>NumberOfVolcanoes<\/th>\n<\/tr>\n<tr>\n<td>United States<\/td>\n<td>184<\/td>\n<\/tr>\n<tr>\n<td>Russia<\/td>\n<td>154<\/td>\n<\/tr>\n<tr>\n<td>Indonesia<\/td>\n<td>142<\/td>\n<\/tr>\n<tr>\n<td>Japan<\/td>\n<td>114<\/td>\n<\/tr>\n<tr>\n<td>Chile<\/td>\n<td>78<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>If you stood all the volcanoes in the world on top of each other, could you reach the Moon?<\/h3>\n<pre>SELECT SUM(\"Elevation (m)\") AS TotalHeight FROM GVPVolcano;<\/pre>\n<table>\n<tbody>\n<tr>\n<th>TotalHeight<\/th>\n<\/tr>\n<tr>\n<td>2533877.0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Not even close! 2,534 km is nothing compared to the 384,000 km distance to the Moon. It isn&#8217;t even a tenth as high as the orbits of geostationary satellites (36,000 km).<\/p>\n<h3>Which volcanoes have erupted since I was born?<\/h3>\n<p>You have to be a little bit tricky with this, as the eruption years in the database are in the form &#8220;2013 CE&#8221;, so you have to trim off the spare text and tell SQLite to treat it as a number (integer).<\/p>\n<pre>SELECT CAST(TRIM(\"Last Known Eruption\", \" CE\") AS integer) AS Year, \r\n \"Volcano Name\", Country FROM GVPVolcano\r\nWHERE \"Last Known Eruption\" LIKE \"% CE\"\r\nAND Year &gt;= 1979\r\nORDER BY Year;<\/pre>\n<table>\n<tbody>\n<tr>\n<th>Year<\/th>\n<th>Volcano Name<\/th>\n<th>Country<\/th>\n<\/tr>\n<tr>\n<td>1979<\/td>\n<td>Curacoa<\/td>\n<td>Tonga<\/td>\n<\/tr>\n<tr>\n<td>1979<\/td>\n<td>Carr\u00e1n-Los Venados<\/td>\n<td>Chile<\/td>\n<\/tr>\n<tr>\n<td>1979<\/td>\n<td>Arenales<\/td>\n<td>Chile<\/td>\n<\/tr>\n<tr>\n<td>1979<\/td>\n<td>Lautaro<\/td>\n<td>Chile<\/td>\n<\/tr>\n<tr>\n<td>1979<\/td>\n<td>Soufri\u00e8re St. Vincent<\/td>\n<td>Saint Vincent and the Grenadines<\/td>\n<\/tr>\n<tr>\n<td>1980<\/td>\n<td>Kuchinoerabujima<\/td>\n<td>Japan<\/td>\n<\/tr>\n<tr>\n<td>1980<\/td>\n<td>On-take<\/td>\n<td>Japan<\/td>\n<\/tr>\n<tr>\n<td>1980<\/td>\n<td>Callaqui<\/td>\n<td>Chile<\/td>\n<\/tr>\n<tr>\n<td>1981<\/td>\n<td>Okataina<\/td>\n<td>New Zealand<\/td>\n<\/tr>\n<tr>\n<td>1981<\/td>\n<td>Shikotsu<\/td>\n<td>Japan<\/td>\n<\/tr>\n<tr>\n<td>1981<\/td>\n<td>Chachadake [Tiatia]<\/td>\n<td>Japan &#8211; administered by Russia<\/td>\n<\/tr>\n<tr>\n<td>1982<\/td>\n<td>Chirpoi<\/td>\n<td>Russia<\/td>\n<\/tr>\n<tr>\n<td>1982<\/td>\n<td>Chich\u00f3n, El<\/td>\n<td>Mexico<\/td>\n<\/tr>\n<tr>\n<td>1982<\/td>\n<td>Wolf<\/td>\n<td>Ecuador<\/td>\n<\/tr>\n<tr>\n<td>1983<\/td>\n<td>Colo [Una Una]<\/td>\n<td>Indonesia<\/td>\n<\/tr>\n<tr>\n<td>1983<\/td>\n<td>Kusatsu-Shirane<\/td>\n<td>Japan<\/td>\n<\/tr>\n<tr>\n<td>1984<\/td>\n<td>Galunggung<\/td>\n<td>Indonesia<\/td>\n<\/tr>\n<tr>\n<td>1984<\/td>\n<td>Kaitoku Seamount<\/td>\n<td>Japan<\/td>\n<\/tr>\n<tr>\n<td>1984<\/td>\n<td>Mauna Loa<\/td>\n<td>United States<\/td>\n<\/tr>\n<tr>\n<td>1984<\/td>\n<td>Krafla<\/td>\n<td>Iceland<\/td>\n<\/tr>\n<tr>\n<td>&#8230;<\/td>\n<td>&#8230;<\/td>\n<td>&#8230;<\/td>\n<\/tr>\n<tr>\n<td>etc.<\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>There were 273 of them, apparently. The database only lists the most recent eruption of each volcano, so Mt St Helens appears in 2008, and not 1980 in the snippet above. 57 volcanoes registered eruptions in 2013.<\/p>\n<h3>How many volcanoes are in the poorest countries of the world?<\/h3>\n<p>The real power of SQL comes from combining data from different tables. In this example, we use a list of the countries with Gross Domestic Product per Capita of less than $5,000 from the CIA World Factbook as a filter for volcanically-active countries. If you weren&#8217;t just doing this for fun, you&#8217;d need to check that all the country names are identical in the two tables.<\/p>\n<pre>SELECT COUNT(\"Volcano Name\") AS NumOfCountries FROM GVPVolcano\r\nWHERE Country IN (SELECT Country FROM CIAFactbook\r\nWHERE \"GDP - per capita (PPP)\" &lt; 5000);<\/pre>\n<table>\n<tbody>\n<tr>\n<th>NumOfCountries<\/th>\n<\/tr>\n<tr>\n<td>482<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>So 482 of the 1555 active volcanoes are in the poorest 88 of the 261 countries in the CIA Factbook.<\/p>\n<h3>Which countries have the most volcanoes per head?<\/h3>\n<p>This example uses a JOIN.\u00a0 JOINs are extremely powerful when you have data of different types in different tables. The number of volcanoes per head is very small, so citizens per volcano is presented here instead.<\/p>\n<pre>SELECT v.Country, \r\n COUNT(v.Country) AS NumberOfVolcanoes,\r\n c.Population,\r\n c.Population \/ COUNT(v.Country)*1.0 AS CitizensPerVolcano\r\nFROM GVPVolcano AS v\r\nLEFT JOIN CIAFactbook AS c\r\nON v.Country=c.Country\r\nWHERE Population IS NOT Null\r\n  GROUP BY v.Country\r\n  ORDER BY CitizensPerVolcano ASC\r\n  LIMIT 5;<\/pre>\n<table>\n<tbody>\n<tr>\n<th>Country<\/th>\n<th>NumberOfVolcanoes<\/th>\n<th>Population<\/th>\n<th>CitizensPerVolcano<\/th>\n<\/tr>\n<tr>\n<td>Tonga<\/td>\n<td>18<\/td>\n<td>120898<\/td>\n<td>6716<\/td>\n<\/tr>\n<tr>\n<td>Iceland<\/td>\n<td>30<\/td>\n<td>306694<\/td>\n<td>10223<\/td>\n<\/tr>\n<tr>\n<td>Dominica<\/td>\n<td>5<\/td>\n<td>72660<\/td>\n<td>14532<\/td>\n<\/tr>\n<tr>\n<td>Vanuatu<\/td>\n<td>14<\/td>\n<td>218519<\/td>\n<td>15608<\/td>\n<\/tr>\n<tr>\n<td>Saint Kitts and Nevis<\/td>\n<td>2<\/td>\n<td>40131<\/td>\n<td>20065<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The join works by matching the Countries column in each of the two tables. Unsurprisingly, I suppose, it turns out that volcanic island nations are the places where people live closest to active volcanoes.<\/p>\n<h2>A practical example for geologists<\/h2>\n<p>Another purpose of this post is to demonstrate how scientists can benefit from using databases in their work. As a geologist, I need to keep track of samples collected from the field and the results that I get from analysing them. A suitable database might contain the following tables with the following columns:<\/p>\n<ul>\n<li><b>Site: <\/b>Number, Latitude, Longitude<\/li>\n<li><b>Sample: <\/b>Number, SiteNumber, Type (e.g. lava, ash), Description<\/li>\n<li><b>XRFData: <\/b>SampleNumber, SiO2, Al2O3, NaO, K2O, &#8230;<\/li>\n<\/ul>\n<p>The idea is that each table contains only one type of data and that each has one key column with unique values (e.g. site or sample numbers). You can then get your data with short queries.<\/p>\n<p>For example, chemical composition data from the XRF instrument is commonly plotted on a &#8216;Total alkalis vs silica&#8217; plot, which distinguishes between different magma types (e.g. basalt, andesite). You can extract the data with:<\/p>\n<pre>SELECT SampleNumber, \r\n  NaO+K2O AS TotalAlkali, \r\n  SiO AS Silica \r\nFROM XRFData;<\/pre>\n<p>To plot a map of SiO<sub>2<\/sub> content in lava samples you can join the tables together.<\/p>\n<pre>SELECT Sample.Number, \r\n  Site.Latitude, \r\n  Site.Longitude, \r\n  XRFData.SiO2\r\nFROM Sample\r\n  LEFT JOIN Site ON Sample.SiteNumber=Site.Number\r\n  LEFT JOIN XRFData ON Sample.Number=XRFData.SampleNumber\r\nWHERE Site.Type IS 'lava';<\/pre>\n<p>If you do more analysis, you can simply add another table (e.g. SieveData, LiteratureData) without having to mess around with the data that you already have and, as long as your sample numbers are distinct, you can keep data from different projects together instead of scattered across many spreadsheets.<\/p>\n<h2>Getting started<\/h2>\n<p>There are two good programs for viewing SQLite databases. Both are <a href=\"http:\/\/en.wikipedia.org\/wiki\/Free_and_open-source_software\">free+open source software<\/a>, so you can download and install them on as many machines as you like. <a href=\"https:\/\/addons.mozilla.org\/en-US\/firefox\/addon\/sqlite-manager\/\">SQLite Manager<\/a> is an add-on for the Firefox web browser. It has a nice tool for importing data from <i>csv<\/i> files. <a href=\"http:\/\/sqliteman.com\/\">Sqliteman<\/a> is a small stand-alone package that runs on Linux (<i>sudo apt-get install sqliteman<\/i> on Ubuntu-like systems), Windows or Mac. There is also a command-line interface utility, <i>sqlite3<\/i> that can import and export data.<\/p>\n<p>Click <a href=\"http:\/\/xweb.geos.ed.ac.uk\/~jsteven5\/blog\/volcan01010_tutorial.sqlite\">here<\/a> to download the SQLite file for the database used in this post. It includes data from the Smithsonian Institute&#8217;s Global Volcanism Program&#8217;s <a href=\"http:\/\/www.volcano.si.edu\/list_volcano_excel.cfm\">volcano spreadsheet<\/a> and csv version of the <a href=\"https:\/\/www.cia.gov\/library\/publications\/the-world-factbook\/\">CIA World Factbook<\/a> from <a href=\"https:\/\/www.google.com\/fusiontables\/DataSource?snapid=134490\">here<\/a>.<\/p>\n<p>I highly recommend the <a href=\"http:\/\/w3schools.com\/sql\/\">W3 Schools&#8217; SQL tutorial<\/a> for learning the language. It takes about an hour. It is also worth reading up on <a href=\"http:\/\/en.wikipedia.org\/wiki\/Database_design\">database structure<\/a>, particularly <a href=\"http:\/\/en.wikipedia.org\/wiki\/Database_normalization\">normalization<\/a>, to help you choose suitable tables.<\/p>\n<p>Regular readers of volcan01010 may be surprised that I have got this far without mentioning <a href=\"http:\/\/scipy-lectures.github.io\/\">Python<\/a>, a free+open source programming language that is becoming central to a scientist&#8217;s toolbox. The <i>sqlite3<\/i> module comes as standard and lets Python read and write directly from \/ to SQLite databases. The <a href=\"http:\/\/zetcode.com\/db\/sqlitepythontutorial\/\">Zetcode SQLite Python tutorial<\/a> gives a great introduction.\u00a0 It&#8217;s often easiest to input and edit data as <i>csv<\/i> files and it&#8217;s straightforward to write a Python script to automatically import them as tables for analysis. As <i>csv <\/i>files are plain text, they are easily portable and can also be tracked with <a href=\"http:\/\/en.wikipedia.org\/wiki\/Git_%28software%29\">version control<\/a> software.<\/p>\n<p>Happy databasing&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Excel is not a database. Even so, spreadsheets are commonly used as such. They are convenient places to enter and store data, but not to get it out again. This post aims to show how using a real database makes &hellip; <a href=\"https:\/\/all-geo.org\/volcan01010\/2013\/12\/generate-volcano-trivia-with-this-sqlite-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1114","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/all-geo.org\/volcan01010\/wp-json\/wp\/v2\/posts\/1114","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/all-geo.org\/volcan01010\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/all-geo.org\/volcan01010\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/all-geo.org\/volcan01010\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/all-geo.org\/volcan01010\/wp-json\/wp\/v2\/comments?post=1114"}],"version-history":[{"count":11,"href":"https:\/\/all-geo.org\/volcan01010\/wp-json\/wp\/v2\/posts\/1114\/revisions"}],"predecessor-version":[{"id":1125,"href":"https:\/\/all-geo.org\/volcan01010\/wp-json\/wp\/v2\/posts\/1114\/revisions\/1125"}],"wp:attachment":[{"href":"https:\/\/all-geo.org\/volcan01010\/wp-json\/wp\/v2\/media?parent=1114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/all-geo.org\/volcan01010\/wp-json\/wp\/v2\/categories?post=1114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/all-geo.org\/volcan01010\/wp-json\/wp\/v2\/tags?post=1114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}