SELECT country_name, apnic_users FROM countries WHERE apnic_users > 300000 AND terrestrial_license = 'YES' ORDER BY apnic_users DESC
This query gives the country name and the amount of APNIC users from all countries with more than 300,000 estimated APNIC users and a terrestrial license, sorted by user numbers, largest first.
| Columns and table | SELECT * (all columns) or SELECT country_name, apnic_users FROM countries |
|---|---|
| Conditions | WHERE with = <> < > <= >=, combined with AND OR NOT and brackets |
| Lists and text | country_code IN ('SY', 'IR'); current_pops LIKE '%sfiabgr1%' (% = any text) |
| Empty values | IS NULL, IS NOT NULL |
| Sort and limit | ORDER BY apnic_users DESC (ASC: smallest first), LIMIT 10 |
| Count and average | COUNT(*) SUM() AVG() MIN() MAX() ROUND(x, 1), per group with GROUP BY continent_code |
| Combine tables | FROM countries c JOIN mlab m ON m.country_code = c.country_code (LEFT JOIN: also rows without partner) |
| Name a result | a.users AS users_on_license_day |
'YES' is not 'yes' (only LIKE ignores case-sensitivity).date >= '2024-01-01' or date('now', '-30 days').substr(date, 1, 7).
If a table value contains only a certain month (e.g. 10.2020) or a year (e.g. 2020), the corresponding SQL value will be the first day of that month (i.e. 2020-10-01) or year (i.e. 2020-01-01).NULL and match no comparison. The operator <> leaves them out (e.g. terrestrial_license <> 'YES'). '/', while for date values, "/" becomes NULL.AVG() over a month is a mean of daily medians.SELECT country_name, license_status, ipv4_addresses, current_pops, apnic_users FROM countries WHERE terrestrial_license = 'NO' AND ip_provisioned = 'current' ORDER BY apnic_users DESC
SELECT c.country_name, c.terrestrial_license_date,
MIN(a.date) AS first_users_day, MAX(a.users) AS max_users_before_license
FROM countries c JOIN apnic a ON a.country_code = c.country_code
WHERE a.users > 0 AND a.date < c.terrestrial_license_date
GROUP BY c.country_code
ORDER BY c.country_name
SELECT substr(date, 1, 7) AS month, SUM(tests) AS tests,
ROUND(AVG(minrtt_median), 1) AS mean_daily_median_minrtt_ms
FROM mlab
WHERE country_code = 'SY'
GROUP BY month
ORDER BY month
SELECT pop, COUNT(*) AS prefixes, SUM(ipv4_addresses) AS ipv4_addresses, SUM(ipv6_56_prefixes) AS ipv6_56_prefixes FROM prefixes WHERE country_code = 'SD' AND active = 'YES' GROUP BY pop
Every table has the column country_code (e.g. 'DE') to combine them.