xiaohongshu
xiaohongshu
dst-query
Execute SQL queries on Danmarks Statistik data stored in DuckDB. Use when user needs specific data analysis, filtering, aggregation, or joins. Also includes table summary functionality.
Full skill instructions
Execute SQL queries to analyze DST data stored in DuckDB. This is the core skill for data analysis - enabling filtering, aggregation, joins, and extracting insights from stored statistical data.
DST uses ".." for suppressed/confidential data. Must handle before numeric operations.
Filter approach:
SELECT * FROM dst_table
WHERE INDHOLD != '..' -- Filter out suppressed
Safe casting approach:
SELECT
TID,
CASE
WHEN INDHOLD != '..' THEN CAST(INDHOLD AS INTEGER)
ELSE NULL
END as value
FROM dst_table
Using helpers:
from scripts.db.helpers import safe_numeric_cast
query = f"SELECT TID, {safe_numeric_cast('INDHOLD')} as value FROM dst_table"
DST uses special codes for totals/aggregates:
"TOT" - Total"I alt" - Total (Danish)"Drivmidler i alt" - All fuel types"IALT" - Total (alternative)Filter them out when analyzing details:
SELECT * FROM dst_table
WHERE fuel_type NOT IN ('Drivmidler i alt', 'I alt')
AND gender NOT IN ('TOT', 'IALT')
DST time codes as strings don't sort chronologically:
"2024K1" - Quarter 1, 2024"2024M01" - January 2024"2024" - Year 2024Extract for proper sorting:
-- For quarters
SELECT
TID,
CAST(SUBSTRING(TID, 1, 4) AS INTEGER) as year,
CAST(SUBSTRING(TID, 6, 1) AS INTEGER) as quarter
FROM dst_table
WHERE TID LIKE '%K%'
ORDER BY year, quarter
Get a quick overview of table structure and statistics before detailed querying.
python scripts/db/table_summary.py --table-id <TABLE_ID>
Execute a SQL query:
python scripts/db/query_data.py --sql "<QUERY>"
Table format (default - console-friendly):
--format table
JSON format (for programmatic use):
--format json
CSV format (for exports):
--format csv
Save query results:
--output <file>
Add automatic LIMIT:
--limit 100
All DST tables in DuckDB follow this pattern:
dst_{table_id} (lowercase)dst_folk1adst_aup01Important: Always use lowercase in queries.
Tables stored from DST API use these conventions:
;)SELECT * FROM dst_folk1a LIMIT 10
SELECT COUNT(*) FROM dst_folk1a
-- See what columns exist
DESCRIBE dst_folk1a;
-- Or use table summary (recommended)
-- python scripts/db/table_summary.py --table-id FOLK1A
SELECT region, SUM(population) as total_pop
FROM dst_folk1a
GROUP BY region
ORDER BY total_pop DESC
-- Note: Time codes from DST (e.g., "2024K1" for Q1 2024)
SELECT tid, value
FROM dst_folk1a
WHERE område = '000' -- Whole country
ORDER BY tid
-- Use exact codes from tableinfo
SELECT *
FROM dst_folk1a
WHERE tid LIKE '2024%' -- All 2024 periods
AND område IN ('000', '101') -- Denmark and Copenhagen
AND køn IN ('1', '2') -- Men and women (not 'TOT')
SELECT
område,
COUNT(*) as record_count,
AVG(CAST(indhold AS DOUBLE)) as avg_value,
MAX(CAST(indhold AS DOUBLE)) as max_value
FROM dst_folk1a
GROUP BY område
SELECT
a.område,
a.indhold as population,
b.indhold as employment
FROM dst_folk1a a
JOIN dst_aup01 b ON a.område = b.område AND a.tid = b.tid
WHERE a.tid = '2024K1'
SELECT
område,
CAST(indhold AS DOUBLE) as value,
100.0 * CAST(indhold AS DOUBLE) / SUM(CAST(indhold AS DOUBLE)) OVER () as percentage
FROM dst_folk1a
WHERE tid = '2024K1' AND køn = 'TOT'
-- Find most recent quarter
WITH latest AS (
SELECT MAX(tid) as max_tid FROM dst_folk1a
)
SELECT område, SUM(CAST(indhold AS DOUBLE)) as total
FROM dst_folk1a
WHERE tid = (SELECT max_tid FROM latest)
GROUP BY område
ORDER BY total DESC
Before analyzing, check when data was last updated:
SELECT table_id, last_updated, row_count
FROM dst_metadata
WHERE table_id = 'FOLK1A'
Recommendations:
python scripts/db/table_summary.py --table-id FOLK1A
python scripts/db/query_data.py --sql "SELECT * FROM dst_folk1a LIMIT 5"
python scripts/db/query_data.py --sql "SELECT year, SUM(population) as total FROM dst_folk1a GROUP BY year ORDER BY year"
python scripts/db/query_data.py --sql "SELECT region, AVG(value) as avg_val FROM dst_folk1a WHERE year >= 2020 GROUP BY region"
python scripts/db/query_data.py --sql "SELECT * FROM dst_folk1a" --format csv --output results.csv
python scripts/db/query_data.py --sql "SELECT * FROM dst_folk1a LIMIT 100" --format json --output data.json
python scripts/db/query_data.py --sql "SELECT * FROM dst_folk1a" --limit 1000
SELECT
year,
value,
LAG(value) OVER (ORDER BY year) as prev_year_value,
value - LAG(value) OVER (ORDER BY year) as change
FROM dst_folk1a
WHERE region = '000'
ORDER BY year
SELECT
region,
MAX(CASE WHEN year = 2023 THEN value END) as val_2023,
MAX(CASE WHEN year = 2024 THEN value END) as val_2024
FROM dst_folk1a
GROUP BY region
SELECT
PERCENTILE_CONT(0.25) WITHIN GROUP (ORDER BY value) as p25,
PERCENTILE_CONT(0.50) WITHIN GROUP (ORDER BY value) as median,
PERCENTILE_CONT(0.75) WITHIN GROUP (ORDER BY value) as p75
FROM dst_folk1a
SELECT *
FROM dst_folk1a
WHERE year BETWEEN 2020 AND 2024
AND region IN (SELECT DISTINCT region FROM dst_aup01 WHERE employment > 1000)
AND value IS NOT NULL
ORDER BY value DESC
LIMIT 100
"2024K1" (quarterly), "2024M01" (monthly), "2024" (annual)"000" (whole country), "101" (Copenhagen), etc."TOT", "IALT" often represent totalstid LIKE '2024%'CAST(indhold AS DOUBLE)python scripts/db/list_tables.py (dst-list-tables skill)dst_folk1aområde (region), tid (time), køn (gender), indhold (value)indhold)CAST(indhold AS DOUBLE)--output results.csvSELECT COUNT(*) FROM table# 1. Get summary
python scripts/db/table_summary.py --table-id FOLK1A
# 2. See sample data
python scripts/db/query_data.py --sql "SELECT * FROM dst_folk1a LIMIT 5"
# 3. Check record count
python scripts/db/query_data.py --sql "SELECT COUNT(*) FROM dst_folk1a"
# 4. Explore key dimensions
python scripts/db/query_data.py --sql "SELECT DISTINCT region FROM dst_folk1a"
# 1. Get summary statistics
python scripts/db/table_summary.py --table-id FOLK1A
# 2. Query time series
python scripts/db/query_data.py --sql "SELECT year, SUM(value) as total FROM dst_folk1a GROUP BY year ORDER BY year"
# 3. Calculate growth
python scripts/db/query_data.py --sql "SELECT year, value, value - LAG(value) OVER (ORDER BY year) as growth FROM dst_folk1a WHERE region = '000'"
# 4. Export results
python scripts/db/query_data.py --sql "..." --format csv --output analysis.csv
# 1. Get regional breakdown
python scripts/db/query_data.py --sql "SELECT region, COUNT(*) as records, AVG(value) as avg_value FROM dst_folk1a GROUP BY region ORDER BY avg_value DESC"
# 2. Top regions
python scripts/db/query_data.py --sql "SELECT region, SUM(value) as total FROM dst_folk1a WHERE year = 2024 GROUP BY region ORDER BY total DESC LIMIT 10"
# 3. Compare specific regions
python scripts/db/query_data.py --sql "SELECT year, region, value FROM dst_folk1a WHERE region IN ('000', '101', '147') ORDER BY year, region"
Aggregation:
String Functions:
Date Functions:
Window Functions:
Conditional:
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience