On this page

Largest countries of a continent

H2Read onlyScripts Gallery

A first Script to learn from: a required text parameter, an optional integer with a default, on the WORLD sample of every installation.

Verification status. The output below was captured with this query on the WORLD sample database, as shown in Arguments and parameters. The header lines added here (description, tags, status, access, dialect) do not change the result.

When to use it

  • Learn how -- @param checks and converts arguments before anything runs.
  • Start from a working Script and adapt it to your own tables.

The Script

Download world-largest-countries.sql

-- @description: Largest countries of a continent
-- @tags: world, sample, geo
-- @status: stable
-- @access: read
-- @dialect: H2
-- @param continent TEXT "Continent, as in COUNTRY.CONTINENT"
-- @param min_population INTEGER = 50000000 "Smallest population listed"
SELECT CODE, NAME, POPULATION
  FROM COUNTRY
 WHERE CONTINENT = ${continent} AND POPULATION >= ${min_population}
 ORDER BY POPULATION DESC;

Parameters

ParameterTypeDefaultMeaning
continentTEXTRequiredContinent, as in COUNTRY.CONTINENT
min_populationINTEGER50000000Smallest population listed

Install and run it

  1. Save the file in your Scripts Library folder (scripts in the installation folder by default), for example as gallery/world-largest-countries.sql.
  2. Open the sample database: CONNECT WORLD;.
  3. Check what it declares: LIB SHOW gallery/world-largest-countries.sql;
  4. Run it: @gallery/world-largest-countries.sql continent='Europe';

To keep the result in a file: DUMP LIB gallery/world-largest-countries.sql continent='Asia' TO asia_largest AS XLSX; (see Exporting Script results).

What you get

The countries of the continent with at least min_population inhabitants, largest first, with the values used shown under the statement.

@countries/largest.sql continent='Europe';
-- continent = 'Europe'
-- min_population = 50000000
|----|----------------------------------------------------|-----------|
|CODE|NAME                                                |POPULATION |
|----|----------------------------------------------------|-----------|
|RUS |Russian Federation                                  |146934000  |
|DEU |Germany                                             |82164700   |
|GBR |United Kingdom                                      |59623400   |
|FRA |France                                              |59225700   |
|ITA |Italy                                               |57680000   |
|UKR |Ukraine                                             |50456000   |
|----|----------------------------------------------------|-----------|

6 rows fetched in 12 ms.

countries/largest.sql: SUCCESS (1 statement, 0 failed) [run BUZ2SI4X]
Running the Script with continent='Europe'

Limits

  • continent is compared exactly: 'Europe', not 'europe'.
  • Without continent, the call is refused before anything runs, unless a session variable continent exists.

Found something wrong or unclear on this page? , with the page address.