### Task
Generate a SQL query to answer the following question:
`Which 5 states have the most people living in rural areas?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE crop_stats (crop TEXT, normal_area_dafw DOUBLE PRECISION, area_sown_2025_26 DOUBLE PRECISION, area_sown_2024_25 DOUBLE PRECISION, difference_area DOUBLE PRECISION, pct_increase_decrease DOUBLE PRECISION);
CREATE TABLE language_stats (state BIGINT, language_id BIGINT, tru_id BIGINT, person BIGINT, male BIGINT, female BIGINT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name AS state_name, SUM(p.persons) AS rural_population FROM population_stats p JOIN regions r ON p.state = r.state JOIN tru t ON p.tru_id = t.id WHERE t.name = 'Rural' GROUP BY r.area_name ORDER BY rural_population DESC LIMIT 5;


### Task
Generate a SQL query to answer the following question:
`Which 5 states have the most people living in urban areas?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE crop_stats (crop TEXT, normal_area_dafw DOUBLE PRECISION, area_sown_2025_26 DOUBLE PRECISION, area_sown_2024_25 DOUBLE PRECISION, difference_area DOUBLE PRECISION, pct_increase_decrease DOUBLE PRECISION);
CREATE TABLE language_stats (state BIGINT, language_id BIGINT, tru_id BIGINT, person BIGINT, male BIGINT, female BIGINT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name AS state_name, SUM(p.persons) AS urban_population FROM population_stats p JOIN regions r ON p.state = r.state JOIN tru t ON p.tru_id = t.id WHERE t.name = 'Urban' GROUP BY r.area_name ORDER BY urban_population DESC LIMIT 5;


### Task
Generate a SQL query to answer the following question:
`Which states have more women than men?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name AS state_name, (SUM(p.females) * 1000.0 / NULLIF(SUM(p.males), 0)) AS sex_ratio FROM population_stats p JOIN regions r ON p.state = r.state JOIN tru t ON p.tru_id = t.id WHERE t.name = 'Total' GROUP BY r.area_name ORDER BY sex_ratio DESC;


### Task
Generate a SQL query to answer the following question:
`Which states show the biggest difference in gender balance between their villages and cities?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE language_stats (state BIGINT, language_id BIGINT, tru_id BIGINT, person BIGINT, male BIGINT, female BIGINT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name AS state_name, ABS((SUM(CASE WHEN t.name = 'Urban' THEN p.females ELSE 0 END) * 1000.0 / NULLIF(SUM(CASE WHEN t.name = 'Urban' THEN p.males ELSE 0 END), 0)) - (SUM(CASE WHEN t.name = 'Rural' THEN p.females ELSE 0 END) * 1000.0 / NULLIF(SUM(CASE WHEN t.name = 'Rural' THEN p.males ELSE 0 END), 0))) AS sex_ratio_difference FROM population_stats p JOIN regions r ON p.state = r.state JOIN tru t ON p.tru_id = t.id GROUP BY r.area_name ORDER BY sex_ratio_difference DESC;


### Task
Generate a SQL query to answer the following question:
`Which three age groups account for the most people in India?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT age, SUM(persons) AS total_population FROM population_stats GROUP BY age ORDER BY total_population DESC LIMIT 3;


### Task
Generate a SQL query to answer the following question:
`Can you break down the population by age, state, and whether they live in a city or village?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name AS state_name, t.name AS area_type, p.age, SUM(p.persons) AS population FROM population_stats p JOIN regions r ON p.state = r.state JOIN tru t ON p.tru_id = t.id GROUP BY r.area_name, t.name, p.age ORDER BY r.area_name, t.name, p.age;


### Task
Generate a SQL query to answer the following question:
`Which state has the most young children (0-6) living in rural areas?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE crop_stats (crop TEXT, normal_area_dafw DOUBLE PRECISION, area_sown_2025_26 DOUBLE PRECISION, area_sown_2024_25 DOUBLE PRECISION, difference_area DOUBLE PRECISION, pct_increase_decrease DOUBLE PRECISION);
CREATE TABLE language_stats (state BIGINT, language_id BIGINT, tru_id BIGINT, person BIGINT, male BIGINT, female BIGINT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name AS state_name, SUM(p.persons) AS rural_children FROM population_stats p JOIN regions r ON p.state = r.state JOIN tru t ON p.tru_id = t.id WHERE t.name = 'Rural' AND p.age = '0-6' GROUP BY r.area_name ORDER BY rural_children DESC LIMIT 1;


### Task
Generate a SQL query to answer the following question:
`What percentage of each state's total population is female?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religion_stats (state BIGINT, tru_id BIGINT, religion_id BIGINT, tot_p BIGINT, tot_m BIGINT, tot_f BIGINT, p_06 BIGINT, m_06 BIGINT, f_06 BIGINT, p_lit BIGINT, m_lit BIGINT, f_lit BIGINT, p_ill BIGINT, m_ill BIGINT, f_ill BIGINT, tot_work_p BIGINT, tot_work_m BIGINT, tot_work_f BIGINT, mainwork_p BIGINT, mainwork_m BIGINT, mainwork_f BIGINT, main_cl_p BIGINT, main_cl_m BIGINT, main_cl_f BIGINT, main_al_p BIGINT, main_al_m BIGINT, main_al_f BIGINT, main_hh_p BIGINT, main_hh_m BIGINT, main_hh_f BIGINT, main_ot_p BIGINT, main_ot_m BIGINT, main_ot_f BIGINT, margwork_p BIGINT, margwork_m BIGINT, margwork_f BIGINT, marg_cl_p BIGINT, marg_cl_m BIGINT, marg_cl_f BIGINT, marg_al_p BIGINT, marg_al_m BIGINT, marg_al_f BIGINT, marg_hh_p BIGINT, marg_hh_m BIGINT, marg_hh_f BIGINT, marg_ot_p BIGINT, marg_ot_m BIGINT, marg_ot_f BIGINT, margwork_3_6_p BIGINT, margwork_3_6_m BIGINT, margwork_3_6_f BIGINT, marg_cl_3_6_p BIGINT, marg_cl_3_6_m BIGINT, marg_cl_3_6_f BIGINT, marg_al_3_6_p BIGINT, marg_al_3_6_m BIGINT, marg_al_3_6_f BIGINT, marg_hh_3_6_p BIGINT, marg_hh_3_6_m BIGINT, marg_hh_3_6_f BIGINT, marg_ot_3_6_p BIGINT, marg_ot_3_6_m BIGINT, marg_ot_3_6_f BIGINT, margwork_0_3_p BIGINT, margwork_0_3_m BIGINT, margwork_0_3_f BIGINT, marg_cl_0_3_p BIGINT, marg_cl_0_3_m BIGINT, marg_cl_0_3_f BIGINT, marg_al_0_3_p BIGINT, marg_al_0_3_m BIGINT, marg_al_0_3_f BIGINT, marg_hh_0_3_p BIGINT, marg_hh_0_3_m BIGINT, marg_hh_0_3_f BIGINT, marg_ot_0_3_p BIGINT, marg_ot_0_3_m BIGINT, marg_ot_0_3_f BIGINT, non_work_p BIGINT, non_work_m BIGINT, non_work_f BIGINT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name AS state_name, (SUM(p.females) * 100.0 / NULLIF(SUM(p.persons), 0)) AS female_percentage FROM population_stats p JOIN regions r ON p.state = r.state JOIN tru t ON p.tru_id = t.id WHERE t.name = 'Total' GROUP BY r.area_name;


### Task
Generate a SQL query to answer the following question:
`Which age group is the largest in the rural areas of each state?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE crop_stats (crop TEXT, normal_area_dafw DOUBLE PRECISION, area_sown_2025_26 DOUBLE PRECISION, area_sown_2024_25 DOUBLE PRECISION, difference_area DOUBLE PRECISION, pct_increase_decrease DOUBLE PRECISION);
CREATE TABLE language_stats (state BIGINT, language_id BIGINT, tru_id BIGINT, person BIGINT, male BIGINT, female BIGINT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
WITH rural_totals AS (SELECT state, SUM(persons) AS total_persons FROM population_stats p JOIN tru t ON p.tru_id = t.id WHERE t.name = 'Rural' GROUP BY state), ranked_ages AS (SELECT p.state, p.age, SUM(p.persons) * 1.0 / rt.total_persons AS share, ROW_NUMBER() OVER (PARTITION BY p.state ORDER BY SUM(p.persons) DESC) AS rn FROM population_stats p JOIN tru t ON p.tru_id = t.id JOIN rural_totals rt ON p.state = rt.state WHERE t.name = 'Rural' GROUP BY p.state, p.age, rt.total_persons) SELECT r.area_name AS state_name, age FROM ranked_ages ra JOIN regions r ON ra.state = r.state WHERE rn = 1;


### Task
Generate a SQL query to answer the following question:
`Which states have more people living in cities than in villages?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id GROUP BY r.area_name HAVING SUM(CASE WHEN t.name='Urban' THEN p.persons ELSE 0 END) > SUM(CASE WHEN t.name='Rural' THEN p.persons ELSE 0 END);


### Task
Generate a SQL query to answer the following question:
`Which states have a rural population that is larger than their urban population?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id GROUP BY r.area_name HAVING SUM(CASE WHEN t.name='Rural' THEN p.persons ELSE 0 END) > SUM(CASE WHEN t.name='Urban' THEN p.persons ELSE 0 END);


### Task
Generate a SQL query to answer the following question:
`Which state has the highest number of men?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name, SUM(p.males) AS total_males FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Total' GROUP BY r.area_name ORDER BY total_males DESC LIMIT 1;


### Task
Generate a SQL query to answer the following question:
`Which state has the highest number of women?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name, SUM(p.females) AS total_females FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Total' GROUP BY r.area_name ORDER BY total_females DESC LIMIT 1;


### Task
Generate a SQL query to answer the following question:
`Which state has the largest gap between the number of men and women?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name, ABS(SUM(p.males)-SUM(p.females)) AS gender_gap FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Total' GROUP BY r.area_name ORDER BY gender_gap DESC;


### Task
Generate a SQL query to answer the following question:
`Which states have a lot of young people but very few elderly people?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name, SUM(CASE WHEN p.age IN ('0-6','7-14','15-19') THEN p.persons ELSE 0 END) AS young_pop FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Total' GROUP BY r.area_name ORDER BY young_pop DESC;


### Task
Generate a SQL query to answer the following question:
`Which states have a large elderly population?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name, SUM(CASE WHEN p.age IN ('60+','65+') THEN p.persons ELSE 0 END) AS elderly_pop FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Total' GROUP BY r.area_name ORDER BY elderly_pop DESC;


### Task
Generate a SQL query to answer the following question:
`Which states have the biggest urban populations?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name, SUM(p.persons) AS urban_pop FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Urban' GROUP BY r.area_name ORDER BY urban_pop DESC;


### Task
Generate a SQL query to answer the following question:
`Which states have the biggest rural populations?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name, SUM(p.persons) AS rural_pop FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Rural' GROUP BY r.area_name ORDER BY rural_pop DESC;


### Task
Generate a SQL query to answer the following question:
`Which states have the most equal ratio of men to women?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Total' GROUP BY r.area_name HAVING ABS(SUM(p.males)-SUM(p.females)) < 0.02 * SUM(p.persons);


### Task
Generate a SQL query to answer the following question:
`Which states have the smallest populations?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name, SUM(p.persons) AS total_population FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Total' GROUP BY r.area_name ORDER BY total_population ASC;


### Task
Generate a SQL query to answer the following question:
`Which states are more rural than urban?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE language_stats (state BIGINT, language_id BIGINT, tru_id BIGINT, person BIGINT, male BIGINT, female BIGINT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id GROUP BY r.area_name HAVING SUM(CASE WHEN t.name='Rural' THEN p.persons ELSE 0 END) > SUM(CASE WHEN t.name='Urban' THEN p.persons ELSE 0 END);


### Task
Generate a SQL query to answer the following question:
`Which states are more urban than rural?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE language_stats (state BIGINT, language_id BIGINT, tru_id BIGINT, person BIGINT, male BIGINT, female BIGINT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id GROUP BY r.area_name HAVING SUM(CASE WHEN t.name='Urban' THEN p.persons ELSE 0 END) > SUM(CASE WHEN t.name='Rural' THEN p.persons ELSE 0 END);


### Task
Generate a SQL query to answer the following question:
`In which states do rural women outnumber rural men?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Rural' GROUP BY r.area_name HAVING SUM(p.females) > SUM(p.males);


### Task
Generate a SQL query to answer the following question:
`In which states do urban women outnumber urban men?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Urban' GROUP BY r.area_name HAVING SUM(p.females) > SUM(p.males);


### Task
Generate a SQL query to answer the following question:
`Which states have the largest population of children (0-6)?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name, SUM(p.persons) AS children_population FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Total' AND p.age='0-6' GROUP BY r.area_name ORDER BY children_population DESC;


### Task
Generate a SQL query to answer the following question:
`Which states have the smallest population of elderly people?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name, SUM(p.persons) AS elderly_population FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Total' AND p.age IN ('60+','65+') GROUP BY r.area_name ORDER BY elderly_population ASC;


### Task
Generate a SQL query to answer the following question:
`Which states have twice as many people living in villages as in cities?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id GROUP BY r.area_name HAVING SUM(CASE WHEN t.name='Rural' THEN p.persons ELSE 0 END) > 2 * SUM(CASE WHEN t.name='Urban' THEN p.persons ELSE 0 END);


### Task
Generate a SQL query to answer the following question:
`Which states have twice as many people living in cities as in villages?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id GROUP BY r.area_name HAVING SUM(CASE WHEN t.name='Urban' THEN p.persons ELSE 0 END) > 2 * SUM(CASE WHEN t.name='Rural' THEN p.persons ELSE 0 END);


### Task
Generate a SQL query to answer the following question:
`Which states have the smallest difference between the number of men and women?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Total' GROUP BY r.area_name HAVING ABS(SUM(p.males)-SUM(p.females)) < 0.01 * SUM(p.persons);


### Task
Generate a SQL query to answer the following question:
`Which states have the fewest people living in rural areas?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE crop_stats (crop TEXT, normal_area_dafw DOUBLE PRECISION, area_sown_2025_26 DOUBLE PRECISION, area_sown_2024_25 DOUBLE PRECISION, difference_area DOUBLE PRECISION, pct_increase_decrease DOUBLE PRECISION);
CREATE TABLE language_stats (state BIGINT, language_id BIGINT, tru_id BIGINT, person BIGINT, male BIGINT, female BIGINT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name, SUM(p.persons) AS rural_population FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Rural' GROUP BY r.area_name ORDER BY rural_population ASC;


### Task
Generate a SQL query to answer the following question:
`Which states have the fewest people living in urban areas?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE crop_stats (crop TEXT, normal_area_dafw DOUBLE PRECISION, area_sown_2025_26 DOUBLE PRECISION, area_sown_2024_25 DOUBLE PRECISION, difference_area DOUBLE PRECISION, pct_increase_decrease DOUBLE PRECISION);
CREATE TABLE language_stats (state BIGINT, language_id BIGINT, tru_id BIGINT, person BIGINT, male BIGINT, female BIGINT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name, SUM(p.persons) AS urban_population FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Urban' GROUP BY r.area_name ORDER BY urban_population ASC;


### Task
Generate a SQL query to answer the following question:
`Which states have the most elderly people (60+)?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name, SUM(p.persons) AS elderly_population FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Total' AND p.age IN ('60+','65+') GROUP BY r.area_name ORDER BY elderly_population DESC;


### Task
Generate a SQL query to answer the following question:
`Which states have more elderly people than young children?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Total' GROUP BY r.area_name HAVING SUM(CASE WHEN p.age IN ('60+','65+') THEN p.persons ELSE 0 END) > SUM(CASE WHEN p.age='0-6' THEN p.persons ELSE 0 END);


### Task
Generate a SQL query to answer the following question:
`In which states do men outnumber women in urban areas?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE crop_stats (crop TEXT, normal_area_dafw DOUBLE PRECISION, area_sown_2025_26 DOUBLE PRECISION, area_sown_2024_25 DOUBLE PRECISION, difference_area DOUBLE PRECISION, pct_increase_decrease DOUBLE PRECISION);
CREATE TABLE language_stats (state BIGINT, language_id BIGINT, tru_id BIGINT, person BIGINT, male BIGINT, female BIGINT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Urban' GROUP BY r.area_name HAVING SUM(p.males) > SUM(p.females);


### Task
Generate a SQL query to answer the following question:
`In which states do women outnumber men in rural areas?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE crop_stats (crop TEXT, normal_area_dafw DOUBLE PRECISION, area_sown_2025_26 DOUBLE PRECISION, area_sown_2024_25 DOUBLE PRECISION, difference_area DOUBLE PRECISION, pct_increase_decrease DOUBLE PRECISION);
CREATE TABLE language_stats (state BIGINT, language_id BIGINT, tru_id BIGINT, person BIGINT, male BIGINT, female BIGINT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Rural' GROUP BY r.area_name HAVING SUM(p.females) > SUM(p.males);


### Task
Generate a SQL query to answer the following question:
`Which states have three times as many city dwellers as villagers?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id GROUP BY r.area_name HAVING SUM(CASE WHEN t.name='Urban' THEN p.persons ELSE 0 END) > 3 * SUM(CASE WHEN t.name='Rural' THEN p.persons ELSE 0 END);


### Task
Generate a SQL query to answer the following question:
`Which states have three times as many villagers as city dwellers?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id GROUP BY r.area_name HAVING SUM(CASE WHEN t.name='Rural' THEN p.persons ELSE 0 END) > 3 * SUM(CASE WHEN t.name='Urban' THEN p.persons ELSE 0 END);


### Task
Generate a SQL query to answer the following question:
`Which states have the largest workforce (people not children or elderly)?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE education_stats (state BIGINT, no_of_households BIGINT, total_person BIGINT, total_male BIGINT, total_female BIGINT, population_in_the_age_group_06_person BIGINT, population_in_the_age_group_06_male BIGINT, population_in_the_age_group_06_female BIGINT, scheduled_castes_person BIGINT, scheduled_castes_male BIGINT, scheduled_castes_populationfemale BIGINT, scheduled_tribes_person BIGINT, scheduled_tribes_male BIGINT, scheduled_tribes_female BIGINT, literates_person BIGINT, literates_male BIGINT, literates_female BIGINT, illiterate_persons BIGINT, illiterate_male BIGINT, illiterate_female BIGINT, total_worker_person BIGINT, total_worker_male BIGINT, total_worker_female BIGINT, main_working_person BIGINT, main_working_male BIGINT, main_working_female BIGINT, main_cultivator_person BIGINT, main_cultivator_male BIGINT, main_cultivator_female BIGINT, main_agricultural_labourers_person BIGINT, main_agricultural_labourers_male BIGINT, main_agricultural_labourers_female BIGINT, main_household_industries_person BIGINT, main_household_industries_male BIGINT, main_household_industries_female BIGINT, main_other_workers_person BIGINT, main_other_workers_male BIGINT, main_other_workers_female BIGINT, marginal_worker_person BIGINT, marginal_worker_male BIGINT, marginal_worker_female BIGINT, marginal_cultivator_person BIGINT, marginal_cultivator_male BIGINT, marginal_cultivator_female BIGINT, marginal_agriculture_labourers_person BIGINT, marginal_agriculture_labourers_male BIGINT, marginal_agriculture_labourers_female BIGINT, marginal_household_industries_person BIGINT, marginal_household_industries_male BIGINT, marginal_household_industries_female BIGINT, marginal_other_workers_person BIGINT, marginal_other_workers_male BIGINT, marginal_other_workers_female BIGINT, marginal_worker_population_3_6_person BIGINT, marginal_worker_population_3_6_male BIGINT, marginal_worker_population_3_6_female BIGINT, marginal_cultivator_population_3_6_person BIGINT, marginal_cultivator_population_3_6_male BIGINT, marginal_cultivator_population_3_6_female BIGINT, marginal_agriculture_labourers_population_3_6_person BIGINT, marginal_agriculture_labourers_population_3_6_male BIGINT, marginal_agriculture_labourers_population_3_6_female BIGINT, marginal_household_industries_population_3_6_person BIGINT, marginal_household_industries_population_3_6_male BIGINT, marginal_household_industries_population_36_female BIGINT, marginal_other_workers_person_3_6_person BIGINT, marginal_other_workers_person_3_6_male BIGINT, marginal_other_workers_person_3_6_female BIGINT, marginal_worker_population_0_3_person BIGINT, marginal_worker_population_0_3_male BIGINT, marginal_worker_population_0_3_female BIGINT, marginal_cultivator_population_0_3_person BIGINT, marginal_cultivator_population_0_3_male BIGINT, marginal_cultivator_population_0_3_female BIGINT, marginal_agriculture_labourers_population_0_3_person BIGINT, marginal_agriculture_labourers_population_0_3_male BIGINT, marginal_agriculture_labourers_population_0_3_female BIGINT, marginal_household_industries_population_0_3_person BIGINT, marginal_household_industries_population_0_3_male BIGINT, marginal_household_industries_population_0_3_female BIGINT, marginal_other_workers_population_0_3_person BIGINT, marginal_other_workers_population_0_3_male BIGINT, marginal_other_workers_population_0_3_female BIGINT, non_working_person BIGINT, non_working_male BIGINT, non_working_female BIGINT, tru_id BIGINT);
CREATE TABLE healthcare_stats (state BIGINT, tru_id BIGINT, number_of_hh_surveyed BIGINT, number_of_women_15_49_interviewed BIGINT, number_of_men_15_54_interviewed BIGINT, female_pop_age_6_years_and_above_who_ever_school_ DOUBLE PRECISION, pop_below_age_15_years_ DOUBLE PRECISION, sex_ratio_of_the_total_pop_females_per_1000_males DOUBLE PRECISION, sex_ratio_at_birth_for_children_born_in_the_last_five_years_ TEXT, child_u5_whose_birth_was_registered_with_the_civil_authority TEXT, deaths_in_the_last_3_years_registered_with_the_civil_authori TEXT, pop_living_in_hh_with_electricity_ DOUBLE PRECISION, pop_living_in_hh_with_an_improved_drinkingwater_source1_ DOUBLE PRECISION, pop_living_in_hh_that_use_an_improved_sanitation_facility2_ DOUBLE PRECISION, hh_using_clean_fuel_for_cooking3_ TEXT, hh_using_iodized_salt_ TEXT, hh_with_any_usual_member_covered_under_a_health_insurancefin TEXT, children_age_5_years_who_attended_preprimary_school_during_t TEXT, women_age_1549_who_are_lit4_ DOUBLE PRECISION, men_age_1549_who_are_lit4_ TEXT, women_age_1549_with_10_or_more_years_of_schooling_ DOUBLE PRECISION, men_age_1549_with_10_or_more_years_of_schooling_ TEXT, women_age_1549_who_have_ever_used_the_internet_ TEXT, men_age_1549_who_have_ever_used_the_internet_ TEXT, women_age_2024_years_married_before_age_18_years_ TEXT, men_age_2529_years_married_before_age_21_years_ TEXT, total_fertility_rate_number_of_children_per_woman TEXT, women_age_1519_years_who_were_already_mothers_or_pregnant_at TEXT, adolescent_fertility_rate_for_women_age_1519_years5 DOUBLE PRECISION, neonatal_mortality_rate_per_1000_live_births TEXT, infant_mortality_rate_per_1000_live_births TEXT, underfive_mortality_rate_per_1000_live_births TEXT, current_use_of_family_planning_methods_currently_married_wom TEXT, current_use_of_family_planning_methods_currently_married_wom.1 TEXT, current_use_of_family_planning_methods_currently_married_wom.2 TEXT, current_use_of_family_planning_methods_currently_married_wom.3 TEXT, current_use_of_family_planning_methods_currently_married_wom.4 TEXT, current_use_of_family_planning_methods_currently_married_wom.5 TEXT, current_use_of_family_planning_methods_currently_married_wom.6 TEXT, current_use_of_family_planning_methods_currently_married_wom.7 TEXT, current_use_of_family_planning_methods_currently_married_wom.8 TEXT, current_use_of_family_planning_methods_currently_married_wom.9 TEXT, current_use_of_family_planning_methods_currently_married_wom.10 TEXT, current_use_of_family_planning_methods_currently_married_wom.11 TEXT, current_use_of_family_planning_methods_currently_married_wom.12 TEXT, current_use_of_family_planning_methods_currently_married_wom.13 TEXT, current_use_of_family_planning_methods_currently_married_wom.14 TEXT, current_use_of_family_planning_methods_currently_married_wom.15 TEXT, current_use_of_family_planning_methods_currently_married_wom.16 TEXT, current_use_of_family_planning_methods_currently_married_wom.17 TEXT, current_use_of_family_planning_methods_currently_married_wom.18 TEXT, current_use_of_family_planning_methods_currently_married_wom.19 TEXT, current_use_of_family_planning_methods_currently_married_wom.20 TEXT, current_use_of_family_planning_methods_currently_married_wom.21 TEXT, current_use_of_family_planning_methods_currently_married_wom.22 TEXT, current_use_of_family_planning_methods_currently_married_wom.23 TEXT, current_use_of_family_planning_methods_currently_married_wom.24 TEXT, current_use_of_family_planning_methods_currently_married_wom.25 TEXT, current_use_of_family_planning_methods_currently_married_wom.26 TEXT, current_use_of_family_planning_methods_currently_married_wom.27 TEXT, current_use_of_family_planning_methods_currently_married_wom.28 TEXT, current_use_of_family_planning_methods_currently_married_wom.29 TEXT, current_use_of_family_planning_methods_currently_married_wom.30 TEXT, current_use_of_family_planning_methods_currently_married_wom.31 TEXT, current_use_of_family_planning_methods_currently_married_wom.32 TEXT, current_use_of_family_planning_methods_currently_married_wom.33 TEXT, current_use_of_family_planning_methods_currently_married_wom.34 TEXT, current_use_of_family_planning_methods_currently_married_wom.35 TEXT, current_use_of_family_planning_methods_currently_married_wom.36 TEXT, current_use_of_family_planning_methods_currently_married_wom.37 TEXT, current_use_of_family_planning_methods_currently_married_wom.38 TEXT, current_use_of_family_planning_methods_currently_married_wom.39 TEXT, current_use_of_family_planning_methods_currently_married_wom.40 TEXT, current_use_of_family_planning_methods_currently_married_wom.41 TEXT, current_use_of_family_planning_methods_currently_married_wom.42 TEXT, current_use_of_family_planning_methods_currently_married_wom.43 TEXT, current_use_of_family_planning_methods_currently_married_wom.44 TEXT, current_use_of_family_planning_methods_currently_married_wom.45 TEXT, current_use_of_family_planning_methods_currently_married_wom.46 TEXT, current_use_of_family_planning_methods_currently_married_wom.47 TEXT, current_use_of_family_planning_methods_currently_married_wom.48 TEXT, current_use_of_family_planning_methods_currently_married_wom.49 TEXT, current_use_of_family_planning_methods_currently_married_wom.50 TEXT, current_use_of_family_planning_methods_currently_married_wom.51 TEXT, current_use_of_family_planning_methods_currently_married_wom.52 TEXT, current_use_of_family_planning_methods_currently_married_wom.53 TEXT, current_use_of_family_planning_methods_currently_married_wom.54 TEXT, current_use_of_family_planning_methods_currently_married_wom.55 TEXT, current_use_of_family_planning_methods_currently_married_wom.56 TEXT, current_use_of_family_planning_methods_currently_married_wom.57 TEXT, current_use_of_family_planning_methods_currently_married_wom.58 TEXT, current_use_of_family_planning_methods_currently_married_wom.59 TEXT, current_use_of_family_planning_methods_currently_married_wom.60 TEXT, current_use_of_family_planning_methods_currently_married_wom.61 TEXT, current_use_of_family_planning_methods_currently_married_wom.62 TEXT, current_use_of_family_planning_methods_currently_married_wom.63 TEXT, total_unmet_need_for_family_planning_currently_married_women TEXT, unmet_need_for_spacing_currently_married_women_age_1549_year TEXT, health_worker_ever_talked_to_female_nonusers_about_family_pl TEXT, current_users_ever_told_about_side_effects_of_current_method TEXT, mothers_who_had_an_antenatal_checkup_in_the_first_trimester_ TEXT, mothers_who_had_at_least_4_antenatal_care_visits_for_last_bi TEXT, mothers_whose_last_birth_was_protected_against_neonatal_teta TEXT, mothers_who_consumed_iron_folic_acid_for_100_days_or_more_wh TEXT, mothers_who_consumed_iron_folic_acid_for_180_days_or_more_wh TEXT, registered_pregnancies_for_which_the_mother_received_a_mothe TEXT, mothers_who_received_postnatal_care_from_a_doctornurselhvanm TEXT, average_outofpocket_expenditure_per_delivery_in_a_public_hea TEXT, children_born_at_home_who_were_taken_to_a_health_facility_fo TEXT, children_who_received_postnatal_care_from_a_doctornurselhvan TEXT, institutional_births_in_the_5_years_before_the_survey_ TEXT, institutional_births_in_public_facility_in_the_5_years_befor TEXT, home_births_that_were_conducted_by_skilled_health_personnel_ TEXT, births_attended_by_skilled_health_personnel_in_the_5_years_b TEXT, births_delivered_by_caesarean_section_in_the_5_years_before_ TEXT, births_in_a_private_health_facility_that_were_delivered_by_c TEXT, births_in_a_public_health_facility_that_were_delivered_by_ca TEXT, children_age_1223_months_fully_vaccinated_based_on_informati TEXT, children_age_1223_months_fully_vaccinated_based_on_informati.1 TEXT, children_age_1223_months_fully_vaccinated_based_on_informati.2 TEXT, children_age_1223_months_fully_vaccinated_based_on_informati.3 TEXT, children_age_1223_months_who_have_received_bcg_ TEXT, children_age_1223_months_who_have_received_3_doses_of_polio_ TEXT, children_age_1223_months_who_have_received_3_doses_of_penta_ TEXT, children_age_1223_months_who_have_received_3_doses_of_penta_.1 TEXT, children_age_1223_months_who_have_received_the_first_dose_of TEXT, children_age_2435_months_who_have_received_a_second_dose_of_ TEXT, children_age_1223_months_who_have_received_3_doses_of_rotavi TEXT, children_age_1223_months_who_have_received_3_doses_of_penta_.2 TEXT, children_age_1223_months_who_have_received_3_doses_of_penta_.3 TEXT, children_age_935_months_who_received_a_vitamin_a_dose_in_the TEXT, children_age_1223_months_who_received_most_of_their_vaccinat TEXT, children_age_1223_months_who_received_most_of_their_vaccinat.1 TEXT, children_age_1223_months_who_received_most_of_their_vaccinat.2 TEXT, children_age_1223_months_who_received_most_of_their_vaccinat.3 TEXT, prevalence_of_diarrhoea_in_the_2_weeks_preceding_the_survey_ TEXT, children_with_diarrhoea_in_the_2_weeks_preceding_the_survey_ TEXT, children_with_diarrhoea_in_the_2_weeks_preceding_the_survey_.1 TEXT, children_with_diarrhoea_in_the_2_weeks_preceding_the_survey_.2 TEXT, children_with_diarrhoea_in_the_2_weeks_preceding_the_survey_.3 TEXT, children_swith_diarrhoea_in_the_2_weeks_preceding_the_survey TEXT, children_prevalence_of_symptoms_of_acute_respiratory_infecti TEXT, children_with_fever_or_symptoms_of_ari_in_the_2_weeks_preced TEXT, children_under_age_3_years_breastfed_within_one_hour_of_birt TEXT, children_under_age_6_months_exclusively_breastfed16_ TEXT, children_age_68_months_receiving_solid_or_semisolid_food_and TEXT, breastfeeding_children_age_623_months_receiving_an_adequate_ TEXT, nonbreastfeeding_children_age_623_months_receiving_an_adequa TEXT, total_children_age_623_months_receiving_an_adequate_diet16_1 TEXT, children_under_5_years_who_are_stunted_heightforage18_ TEXT, children_under_5_years_who_are_wasted_weightforheight18_ TEXT, children_under_5_years_who_are_severely_wasted_weightforheig TEXT, children_under_5_years_who_are_underweight_weightforage18_ TEXT, children_under_5_years_who_are_overweight_weightforheight20_ TEXT, women_age_1549_years_whose_body_mass_index_bmi_is_below_norm TEXT, men_age_1549_years_whose_body_mass_index_bmi_is_below_normal TEXT, women_age_1549_years_who_are_overweight_or_obese_bmi_250_kgm TEXT, men_age_1549_years_who_are_overweight_or_obese_bmi_250_kgm2_ TEXT, women_age_1549_years_who_have_high_risk_waisttohip_ratio_085 TEXT, men_age_1549_years_who_have_high_risk_waisttohip_ratio_090_ TEXT, children_age_659_months_who_are_anaemic_110_gdl22_ TEXT, nonpregnant_women_15_49_who_are_anaemic_120_gdl22_ TEXT, pregnant_women_15_49_who_are_anaemic_110_gdl22_ TEXT, all_women_15_49_who_are_anaemic22_ DOUBLE PRECISION, all_women_age_1519_years_who_are_anaemic22_ TEXT, men_age_1549_years_who_are_anaemic_130_gdl22_ TEXT, men_age_1519_years_who_are_anaemic_130_gdl22_ TEXT, women_age_15_years_and_above_with_high_141160_mgdl_blood_sug TEXT, women_age_15_years_and_above_wih_very_high_160_mgdl_blood_su DOUBLE PRECISION, women_age_15_years_and_above_wih_high_or_very_high_140_mgdl_ DOUBLE PRECISION, men_age_15_years_and_above_wih_high_141160_mgdl_blood_sugar_ DOUBLE PRECISION, men_age_15_years_and_above_wih_very_high_160_mgdl_blood_suga DOUBLE PRECISION, men_age_15_years_and_above_wih_high_or_very_high_140_mgdl_bl DOUBLE PRECISION, women_age_15_years_and_above_wih_mildly_elevated_blood_press DOUBLE PRECISION, women_age_15_years_and_above_wih_moderately_or_severely_elev DOUBLE PRECISION, women_age_15_years_and_above_wih_elevated_blood_pressure_sys DOUBLE PRECISION, men_age_15_years_and_above_wih_mildly_elevated_blood_pressur DOUBLE PRECISION, men_age_15_years_and_above_wih_moderately_or_severely_elevat DOUBLE PRECISION, men_age_15_years_and_above_wih_elevated_blood_pressure_systo DOUBLE PRECISION, women_age_3049_years_ever_undergone_a_screening_test_for_cer TEXT, women_age_3049_years_ever_undergone_a_breast_examination_for TEXT, women_age_3049_years_ever_undergone_an_oral_cavity_examinati TEXT, men_age_3049_yearsever_undergone_an_oral_cavity_examination_ TEXT, women_age_1549_years_who_have_comprehensive_knowledge24_of_h TEXT, men_age_1549_years_who_have_comprehensive_knowledge24_of_hiv TEXT, women_age_1549_years_who_know_that_consistent_condom_use_can TEXT, men_age_1549_years_who_know_that_consistent_condom_use_can_r TEXT, currently_married_women_age_1549_years_who_usually_participa TEXT, women_age_1549_years_who_worked_in_the_last_12_months_and_we TEXT, women_age_1549_years_owning_a_house_andor_land_alone_or_join TEXT, women_age_1549_years_having_a_bank_or_savings_account_that_t TEXT, women_age_1549_years_having_a_mobile_phone_that_they_themsel TEXT, women_age_1524_years_who_use_hygienic_methods_of_protection_ TEXT, evermarried_women_age_1849_years_who_have_ever_experienced_s TEXT, evermarried_women_age_1849_years_who_have_experienced_physic TEXT, young_women_age_1829_years_who_experienced_sexual_violence_b TEXT, women_age_15_years_and_above_who_use_any_kind_of_tobacco_ DOUBLE PRECISION, men_age_15_years_and_above_who_use_any_kind_of_tobacco_ DOUBLE PRECISION, women_age_15_years_and_above_who_consume_alcohol_ DOUBLE PRECISION, men_age_15_years_and_above_who_consume_alcohol_ DOUBLE PRECISION);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE occupation_stats (state BIGINT, tru_id BIGINT, age_group_id BIGINT, population_total BIGINT, population_male BIGINT, population_female BIGINT, main_workers_total BIGINT, main_workers_male BIGINT, main_workers_female BIGINT, marginal_workers_total BIGINT, marginal_workers_male BIGINT, marginal_workers_female BIGINT, marg_3_6mo_total BIGINT, marg_3_6mo_male BIGINT, marg_3_6mo_female BIGINT, marg_less_3mo_total BIGINT, marg_less_3mo_male BIGINT, marg_less_3mo_female BIGINT, non_workers_total BIGINT, non_workers_male BIGINT, non_workers_female BIGINT, seeking_work_total BIGINT, seeking_work_male BIGINT, seeking_work_female BIGINT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name, SUM(p.persons) AS working_age_population FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Total' AND p.age NOT IN ('0-6','60+','65+') GROUP BY r.area_name ORDER BY working_age_population DESC;


### Task
Generate a SQL query to answer the following question:
`Which states have roughly the same number of people in rural and urban areas?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE crop_stats (crop TEXT, normal_area_dafw DOUBLE PRECISION, area_sown_2025_26 DOUBLE PRECISION, area_sown_2024_25 DOUBLE PRECISION, difference_area DOUBLE PRECISION, pct_increase_decrease DOUBLE PRECISION);
CREATE TABLE language_stats (state BIGINT, language_id BIGINT, tru_id BIGINT, person BIGINT, male BIGINT, female BIGINT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id GROUP BY r.area_name HAVING ABS(SUM(CASE WHEN t.name='Urban' THEN p.persons ELSE 0 END)-SUM(CASE WHEN t.name='Rural' THEN p.persons ELSE 0 END)) < 0.05 * SUM(p.persons);


### Task
Generate a SQL query to answer the following question:
`List the states with the biggest rural populations.`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name, SUM(p.persons) AS rural_population FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Rural' GROUP BY r.area_name ORDER BY rural_population DESC;


### Task
Generate a SQL query to answer the following question:
`List the states with the biggest urban populations.`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name, SUM(p.persons) AS urban_population FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Urban' GROUP BY r.area_name ORDER BY urban_population DESC;


### Task
Generate a SQL query to answer the following question:
`Where is the gender gap the smallest?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name, ABS(SUM(p.males)-SUM(p.females)) AS gender_diff FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Total' GROUP BY r.area_name ORDER BY gender_diff ASC;


### Task
Generate a SQL query to answer the following question:
`Which states have the most women?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name, SUM(p.females) AS total_females FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Total' GROUP BY r.area_name ORDER BY total_females DESC;


### Task
Generate a SQL query to answer the following question:
`Which states have the most men?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name, SUM(p.males) AS total_males FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Total' GROUP BY r.area_name ORDER BY total_males DESC;


### Task
Generate a SQL query to answer the following question:
`Which states have the highest percentage of children?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name, SUM(p.persons) * 1.0 / (SELECT SUM(persons) FROM population_stats ps WHERE ps.state=p.state AND ps.tru_id=p.tru_id) AS child_share FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Total' AND p.age='0-6' GROUP BY r.area_name, p.state, p.tru_id ORDER BY child_share DESC;


### Task
Generate a SQL query to answer the following question:
`Which states have the highest percentage of elderly people?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name, SUM(p.persons) * 1.0 / (SELECT SUM(persons) FROM population_stats ps WHERE ps.state=p.state AND ps.tru_id=p.tru_id) AS elderly_share FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Total' AND p.age IN ('60+','65+') GROUP BY r.area_name, p.state, p.tru_id ORDER BY elderly_share DESC;


### Task
Generate a SQL query to answer the following question:
`In which states does the rural population exceed the urban population?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id GROUP BY r.area_name HAVING SUM(CASE WHEN t.name='Rural' THEN p.persons ELSE 0 END) > SUM(CASE WHEN t.name='Urban' THEN p.persons ELSE 0 END);


### Task
Generate a SQL query to answer the following question:
`In which states does the urban population exceed the rural population?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id GROUP BY r.area_name HAVING SUM(CASE WHEN t.name='Urban' THEN p.persons ELSE 0 END) > SUM(CASE WHEN t.name='Rural' THEN p.persons ELSE 0 END);


### Task
Generate a SQL query to answer the following question:
`Which states have a rural/urban population split that is almost equal (less than 10% difference)?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id GROUP BY r.area_name HAVING ABS(SUM(CASE WHEN t.name='Urban' THEN p.persons ELSE 0 END)-SUM(CASE WHEN t.name='Rural' THEN p.persons ELSE 0 END)) < 0.1 * SUM(p.persons);


### Task
Generate a SQL query to answer the following question:
`Rank the states by total population.`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religion_stats (state BIGINT, tru_id BIGINT, religion_id BIGINT, tot_p BIGINT, tot_m BIGINT, tot_f BIGINT, p_06 BIGINT, m_06 BIGINT, f_06 BIGINT, p_lit BIGINT, m_lit BIGINT, f_lit BIGINT, p_ill BIGINT, m_ill BIGINT, f_ill BIGINT, tot_work_p BIGINT, tot_work_m BIGINT, tot_work_f BIGINT, mainwork_p BIGINT, mainwork_m BIGINT, mainwork_f BIGINT, main_cl_p BIGINT, main_cl_m BIGINT, main_cl_f BIGINT, main_al_p BIGINT, main_al_m BIGINT, main_al_f BIGINT, main_hh_p BIGINT, main_hh_m BIGINT, main_hh_f BIGINT, main_ot_p BIGINT, main_ot_m BIGINT, main_ot_f BIGINT, margwork_p BIGINT, margwork_m BIGINT, margwork_f BIGINT, marg_cl_p BIGINT, marg_cl_m BIGINT, marg_cl_f BIGINT, marg_al_p BIGINT, marg_al_m BIGINT, marg_al_f BIGINT, marg_hh_p BIGINT, marg_hh_m BIGINT, marg_hh_f BIGINT, marg_ot_p BIGINT, marg_ot_m BIGINT, marg_ot_f BIGINT, margwork_3_6_p BIGINT, margwork_3_6_m BIGINT, margwork_3_6_f BIGINT, marg_cl_3_6_p BIGINT, marg_cl_3_6_m BIGINT, marg_cl_3_6_f BIGINT, marg_al_3_6_p BIGINT, marg_al_3_6_m BIGINT, marg_al_3_6_f BIGINT, marg_hh_3_6_p BIGINT, marg_hh_3_6_m BIGINT, marg_hh_3_6_f BIGINT, marg_ot_3_6_p BIGINT, marg_ot_3_6_m BIGINT, marg_ot_3_6_f BIGINT, margwork_0_3_p BIGINT, margwork_0_3_m BIGINT, margwork_0_3_f BIGINT, marg_cl_0_3_p BIGINT, marg_cl_0_3_m BIGINT, marg_cl_0_3_f BIGINT, marg_al_0_3_p BIGINT, marg_al_0_3_m BIGINT, marg_al_0_3_f BIGINT, marg_hh_0_3_p BIGINT, marg_hh_0_3_m BIGINT, marg_hh_0_3_f BIGINT, marg_ot_0_3_p BIGINT, marg_ot_0_3_m BIGINT, marg_ot_0_3_f BIGINT, non_work_p BIGINT, non_work_m BIGINT, non_work_f BIGINT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name, SUM(p.persons) AS total_population FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Total' GROUP BY r.area_name ORDER BY total_population DESC;


### Task
Generate a SQL query to answer the following question:
`Which states have the smallest rural populations?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name, SUM(p.persons) AS rural_population FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Rural' GROUP BY r.area_name ORDER BY rural_population ASC;


### Task
Generate a SQL query to answer the following question:
`Which states have the smallest urban populations?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name, SUM(p.persons) AS urban_population FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Urban' GROUP BY r.area_name ORDER BY urban_population ASC;


### Task
Generate a SQL query to answer the following question:
`Which states have at least 20% more women than men?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Total' GROUP BY r.area_name HAVING SUM(p.females) > 1.2 * SUM(p.males);


### Task
Generate a SQL query to answer the following question:
`Which states have at least 20% more men than women?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Total' GROUP BY r.area_name HAVING SUM(p.males) > 1.2 * SUM(p.females);


### Task
Generate a SQL query to answer the following question:
`Which states have the most teenagers?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name, SUM(p.persons) AS teen_population FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Total' AND p.age IN ('10-14','15-19') GROUP BY r.area_name ORDER BY teen_population DESC;


### Task
Generate a SQL query to answer the following question:
`Which states have the fewest young children?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name, SUM(p.persons) AS child_population FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Total' AND p.age='0-6' GROUP BY r.area_name ORDER BY child_population ASC;


### Task
Generate a SQL query to answer the following question:
`Which states have the largest working-age populations?`

### Database Schema
This query will run on a database whose schema is represented in this string:
CREATE TABLE age_groups (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE education_stats (state BIGINT, no_of_households BIGINT, total_person BIGINT, total_male BIGINT, total_female BIGINT, population_in_the_age_group_06_person BIGINT, population_in_the_age_group_06_male BIGINT, population_in_the_age_group_06_female BIGINT, scheduled_castes_person BIGINT, scheduled_castes_male BIGINT, scheduled_castes_populationfemale BIGINT, scheduled_tribes_person BIGINT, scheduled_tribes_male BIGINT, scheduled_tribes_female BIGINT, literates_person BIGINT, literates_male BIGINT, literates_female BIGINT, illiterate_persons BIGINT, illiterate_male BIGINT, illiterate_female BIGINT, total_worker_person BIGINT, total_worker_male BIGINT, total_worker_female BIGINT, main_working_person BIGINT, main_working_male BIGINT, main_working_female BIGINT, main_cultivator_person BIGINT, main_cultivator_male BIGINT, main_cultivator_female BIGINT, main_agricultural_labourers_person BIGINT, main_agricultural_labourers_male BIGINT, main_agricultural_labourers_female BIGINT, main_household_industries_person BIGINT, main_household_industries_male BIGINT, main_household_industries_female BIGINT, main_other_workers_person BIGINT, main_other_workers_male BIGINT, main_other_workers_female BIGINT, marginal_worker_person BIGINT, marginal_worker_male BIGINT, marginal_worker_female BIGINT, marginal_cultivator_person BIGINT, marginal_cultivator_male BIGINT, marginal_cultivator_female BIGINT, marginal_agriculture_labourers_person BIGINT, marginal_agriculture_labourers_male BIGINT, marginal_agriculture_labourers_female BIGINT, marginal_household_industries_person BIGINT, marginal_household_industries_male BIGINT, marginal_household_industries_female BIGINT, marginal_other_workers_person BIGINT, marginal_other_workers_male BIGINT, marginal_other_workers_female BIGINT, marginal_worker_population_3_6_person BIGINT, marginal_worker_population_3_6_male BIGINT, marginal_worker_population_3_6_female BIGINT, marginal_cultivator_population_3_6_person BIGINT, marginal_cultivator_population_3_6_male BIGINT, marginal_cultivator_population_3_6_female BIGINT, marginal_agriculture_labourers_population_3_6_person BIGINT, marginal_agriculture_labourers_population_3_6_male BIGINT, marginal_agriculture_labourers_population_3_6_female BIGINT, marginal_household_industries_population_3_6_person BIGINT, marginal_household_industries_population_3_6_male BIGINT, marginal_household_industries_population_36_female BIGINT, marginal_other_workers_person_3_6_person BIGINT, marginal_other_workers_person_3_6_male BIGINT, marginal_other_workers_person_3_6_female BIGINT, marginal_worker_population_0_3_person BIGINT, marginal_worker_population_0_3_male BIGINT, marginal_worker_population_0_3_female BIGINT, marginal_cultivator_population_0_3_person BIGINT, marginal_cultivator_population_0_3_male BIGINT, marginal_cultivator_population_0_3_female BIGINT, marginal_agriculture_labourers_population_0_3_person BIGINT, marginal_agriculture_labourers_population_0_3_male BIGINT, marginal_agriculture_labourers_population_0_3_female BIGINT, marginal_household_industries_population_0_3_person BIGINT, marginal_household_industries_population_0_3_male BIGINT, marginal_household_industries_population_0_3_female BIGINT, marginal_other_workers_population_0_3_person BIGINT, marginal_other_workers_population_0_3_male BIGINT, marginal_other_workers_population_0_3_female BIGINT, non_working_person BIGINT, non_working_male BIGINT, non_working_female BIGINT, tru_id BIGINT);
CREATE TABLE healthcare_stats (state BIGINT, tru_id BIGINT, number_of_hh_surveyed BIGINT, number_of_women_15_49_interviewed BIGINT, number_of_men_15_54_interviewed BIGINT, female_pop_age_6_years_and_above_who_ever_school_ DOUBLE PRECISION, pop_below_age_15_years_ DOUBLE PRECISION, sex_ratio_of_the_total_pop_females_per_1000_males DOUBLE PRECISION, sex_ratio_at_birth_for_children_born_in_the_last_five_years_ TEXT, child_u5_whose_birth_was_registered_with_the_civil_authority TEXT, deaths_in_the_last_3_years_registered_with_the_civil_authori TEXT, pop_living_in_hh_with_electricity_ DOUBLE PRECISION, pop_living_in_hh_with_an_improved_drinkingwater_source1_ DOUBLE PRECISION, pop_living_in_hh_that_use_an_improved_sanitation_facility2_ DOUBLE PRECISION, hh_using_clean_fuel_for_cooking3_ TEXT, hh_using_iodized_salt_ TEXT, hh_with_any_usual_member_covered_under_a_health_insurancefin TEXT, children_age_5_years_who_attended_preprimary_school_during_t TEXT, women_age_1549_who_are_lit4_ DOUBLE PRECISION, men_age_1549_who_are_lit4_ TEXT, women_age_1549_with_10_or_more_years_of_schooling_ DOUBLE PRECISION, men_age_1549_with_10_or_more_years_of_schooling_ TEXT, women_age_1549_who_have_ever_used_the_internet_ TEXT, men_age_1549_who_have_ever_used_the_internet_ TEXT, women_age_2024_years_married_before_age_18_years_ TEXT, men_age_2529_years_married_before_age_21_years_ TEXT, total_fertility_rate_number_of_children_per_woman TEXT, women_age_1519_years_who_were_already_mothers_or_pregnant_at TEXT, adolescent_fertility_rate_for_women_age_1519_years5 DOUBLE PRECISION, neonatal_mortality_rate_per_1000_live_births TEXT, infant_mortality_rate_per_1000_live_births TEXT, underfive_mortality_rate_per_1000_live_births TEXT, current_use_of_family_planning_methods_currently_married_wom TEXT, current_use_of_family_planning_methods_currently_married_wom.1 TEXT, current_use_of_family_planning_methods_currently_married_wom.2 TEXT, current_use_of_family_planning_methods_currently_married_wom.3 TEXT, current_use_of_family_planning_methods_currently_married_wom.4 TEXT, current_use_of_family_planning_methods_currently_married_wom.5 TEXT, current_use_of_family_planning_methods_currently_married_wom.6 TEXT, current_use_of_family_planning_methods_currently_married_wom.7 TEXT, current_use_of_family_planning_methods_currently_married_wom.8 TEXT, current_use_of_family_planning_methods_currently_married_wom.9 TEXT, current_use_of_family_planning_methods_currently_married_wom.10 TEXT, current_use_of_family_planning_methods_currently_married_wom.11 TEXT, current_use_of_family_planning_methods_currently_married_wom.12 TEXT, current_use_of_family_planning_methods_currently_married_wom.13 TEXT, current_use_of_family_planning_methods_currently_married_wom.14 TEXT, current_use_of_family_planning_methods_currently_married_wom.15 TEXT, current_use_of_family_planning_methods_currently_married_wom.16 TEXT, current_use_of_family_planning_methods_currently_married_wom.17 TEXT, current_use_of_family_planning_methods_currently_married_wom.18 TEXT, current_use_of_family_planning_methods_currently_married_wom.19 TEXT, current_use_of_family_planning_methods_currently_married_wom.20 TEXT, current_use_of_family_planning_methods_currently_married_wom.21 TEXT, current_use_of_family_planning_methods_currently_married_wom.22 TEXT, current_use_of_family_planning_methods_currently_married_wom.23 TEXT, current_use_of_family_planning_methods_currently_married_wom.24 TEXT, current_use_of_family_planning_methods_currently_married_wom.25 TEXT, current_use_of_family_planning_methods_currently_married_wom.26 TEXT, current_use_of_family_planning_methods_currently_married_wom.27 TEXT, current_use_of_family_planning_methods_currently_married_wom.28 TEXT, current_use_of_family_planning_methods_currently_married_wom.29 TEXT, current_use_of_family_planning_methods_currently_married_wom.30 TEXT, current_use_of_family_planning_methods_currently_married_wom.31 TEXT, current_use_of_family_planning_methods_currently_married_wom.32 TEXT, current_use_of_family_planning_methods_currently_married_wom.33 TEXT, current_use_of_family_planning_methods_currently_married_wom.34 TEXT, current_use_of_family_planning_methods_currently_married_wom.35 TEXT, current_use_of_family_planning_methods_currently_married_wom.36 TEXT, current_use_of_family_planning_methods_currently_married_wom.37 TEXT, current_use_of_family_planning_methods_currently_married_wom.38 TEXT, current_use_of_family_planning_methods_currently_married_wom.39 TEXT, current_use_of_family_planning_methods_currently_married_wom.40 TEXT, current_use_of_family_planning_methods_currently_married_wom.41 TEXT, current_use_of_family_planning_methods_currently_married_wom.42 TEXT, current_use_of_family_planning_methods_currently_married_wom.43 TEXT, current_use_of_family_planning_methods_currently_married_wom.44 TEXT, current_use_of_family_planning_methods_currently_married_wom.45 TEXT, current_use_of_family_planning_methods_currently_married_wom.46 TEXT, current_use_of_family_planning_methods_currently_married_wom.47 TEXT, current_use_of_family_planning_methods_currently_married_wom.48 TEXT, current_use_of_family_planning_methods_currently_married_wom.49 TEXT, current_use_of_family_planning_methods_currently_married_wom.50 TEXT, current_use_of_family_planning_methods_currently_married_wom.51 TEXT, current_use_of_family_planning_methods_currently_married_wom.52 TEXT, current_use_of_family_planning_methods_currently_married_wom.53 TEXT, current_use_of_family_planning_methods_currently_married_wom.54 TEXT, current_use_of_family_planning_methods_currently_married_wom.55 TEXT, current_use_of_family_planning_methods_currently_married_wom.56 TEXT, current_use_of_family_planning_methods_currently_married_wom.57 TEXT, current_use_of_family_planning_methods_currently_married_wom.58 TEXT, current_use_of_family_planning_methods_currently_married_wom.59 TEXT, current_use_of_family_planning_methods_currently_married_wom.60 TEXT, current_use_of_family_planning_methods_currently_married_wom.61 TEXT, current_use_of_family_planning_methods_currently_married_wom.62 TEXT, current_use_of_family_planning_methods_currently_married_wom.63 TEXT, total_unmet_need_for_family_planning_currently_married_women TEXT, unmet_need_for_spacing_currently_married_women_age_1549_year TEXT, health_worker_ever_talked_to_female_nonusers_about_family_pl TEXT, current_users_ever_told_about_side_effects_of_current_method TEXT, mothers_who_had_an_antenatal_checkup_in_the_first_trimester_ TEXT, mothers_who_had_at_least_4_antenatal_care_visits_for_last_bi TEXT, mothers_whose_last_birth_was_protected_against_neonatal_teta TEXT, mothers_who_consumed_iron_folic_acid_for_100_days_or_more_wh TEXT, mothers_who_consumed_iron_folic_acid_for_180_days_or_more_wh TEXT, registered_pregnancies_for_which_the_mother_received_a_mothe TEXT, mothers_who_received_postnatal_care_from_a_doctornurselhvanm TEXT, average_outofpocket_expenditure_per_delivery_in_a_public_hea TEXT, children_born_at_home_who_were_taken_to_a_health_facility_fo TEXT, children_who_received_postnatal_care_from_a_doctornurselhvan TEXT, institutional_births_in_the_5_years_before_the_survey_ TEXT, institutional_births_in_public_facility_in_the_5_years_befor TEXT, home_births_that_were_conducted_by_skilled_health_personnel_ TEXT, births_attended_by_skilled_health_personnel_in_the_5_years_b TEXT, births_delivered_by_caesarean_section_in_the_5_years_before_ TEXT, births_in_a_private_health_facility_that_were_delivered_by_c TEXT, births_in_a_public_health_facility_that_were_delivered_by_ca TEXT, children_age_1223_months_fully_vaccinated_based_on_informati TEXT, children_age_1223_months_fully_vaccinated_based_on_informati.1 TEXT, children_age_1223_months_fully_vaccinated_based_on_informati.2 TEXT, children_age_1223_months_fully_vaccinated_based_on_informati.3 TEXT, children_age_1223_months_who_have_received_bcg_ TEXT, children_age_1223_months_who_have_received_3_doses_of_polio_ TEXT, children_age_1223_months_who_have_received_3_doses_of_penta_ TEXT, children_age_1223_months_who_have_received_3_doses_of_penta_.1 TEXT, children_age_1223_months_who_have_received_the_first_dose_of TEXT, children_age_2435_months_who_have_received_a_second_dose_of_ TEXT, children_age_1223_months_who_have_received_3_doses_of_rotavi TEXT, children_age_1223_months_who_have_received_3_doses_of_penta_.2 TEXT, children_age_1223_months_who_have_received_3_doses_of_penta_.3 TEXT, children_age_935_months_who_received_a_vitamin_a_dose_in_the TEXT, children_age_1223_months_who_received_most_of_their_vaccinat TEXT, children_age_1223_months_who_received_most_of_their_vaccinat.1 TEXT, children_age_1223_months_who_received_most_of_their_vaccinat.2 TEXT, children_age_1223_months_who_received_most_of_their_vaccinat.3 TEXT, prevalence_of_diarrhoea_in_the_2_weeks_preceding_the_survey_ TEXT, children_with_diarrhoea_in_the_2_weeks_preceding_the_survey_ TEXT, children_with_diarrhoea_in_the_2_weeks_preceding_the_survey_.1 TEXT, children_with_diarrhoea_in_the_2_weeks_preceding_the_survey_.2 TEXT, children_with_diarrhoea_in_the_2_weeks_preceding_the_survey_.3 TEXT, children_swith_diarrhoea_in_the_2_weeks_preceding_the_survey TEXT, children_prevalence_of_symptoms_of_acute_respiratory_infecti TEXT, children_with_fever_or_symptoms_of_ari_in_the_2_weeks_preced TEXT, children_under_age_3_years_breastfed_within_one_hour_of_birt TEXT, children_under_age_6_months_exclusively_breastfed16_ TEXT, children_age_68_months_receiving_solid_or_semisolid_food_and TEXT, breastfeeding_children_age_623_months_receiving_an_adequate_ TEXT, nonbreastfeeding_children_age_623_months_receiving_an_adequa TEXT, total_children_age_623_months_receiving_an_adequate_diet16_1 TEXT, children_under_5_years_who_are_stunted_heightforage18_ TEXT, children_under_5_years_who_are_wasted_weightforheight18_ TEXT, children_under_5_years_who_are_severely_wasted_weightforheig TEXT, children_under_5_years_who_are_underweight_weightforage18_ TEXT, children_under_5_years_who_are_overweight_weightforheight20_ TEXT, women_age_1549_years_whose_body_mass_index_bmi_is_below_norm TEXT, men_age_1549_years_whose_body_mass_index_bmi_is_below_normal TEXT, women_age_1549_years_who_are_overweight_or_obese_bmi_250_kgm TEXT, men_age_1549_years_who_are_overweight_or_obese_bmi_250_kgm2_ TEXT, women_age_1549_years_who_have_high_risk_waisttohip_ratio_085 TEXT, men_age_1549_years_who_have_high_risk_waisttohip_ratio_090_ TEXT, children_age_659_months_who_are_anaemic_110_gdl22_ TEXT, nonpregnant_women_15_49_who_are_anaemic_120_gdl22_ TEXT, pregnant_women_15_49_who_are_anaemic_110_gdl22_ TEXT, all_women_15_49_who_are_anaemic22_ DOUBLE PRECISION, all_women_age_1519_years_who_are_anaemic22_ TEXT, men_age_1549_years_who_are_anaemic_130_gdl22_ TEXT, men_age_1519_years_who_are_anaemic_130_gdl22_ TEXT, women_age_15_years_and_above_with_high_141160_mgdl_blood_sug TEXT, women_age_15_years_and_above_wih_very_high_160_mgdl_blood_su DOUBLE PRECISION, women_age_15_years_and_above_wih_high_or_very_high_140_mgdl_ DOUBLE PRECISION, men_age_15_years_and_above_wih_high_141160_mgdl_blood_sugar_ DOUBLE PRECISION, men_age_15_years_and_above_wih_very_high_160_mgdl_blood_suga DOUBLE PRECISION, men_age_15_years_and_above_wih_high_or_very_high_140_mgdl_bl DOUBLE PRECISION, women_age_15_years_and_above_wih_mildly_elevated_blood_press DOUBLE PRECISION, women_age_15_years_and_above_wih_moderately_or_severely_elev DOUBLE PRECISION, women_age_15_years_and_above_wih_elevated_blood_pressure_sys DOUBLE PRECISION, men_age_15_years_and_above_wih_mildly_elevated_blood_pressur DOUBLE PRECISION, men_age_15_years_and_above_wih_moderately_or_severely_elevat DOUBLE PRECISION, men_age_15_years_and_above_wih_elevated_blood_pressure_systo DOUBLE PRECISION, women_age_3049_years_ever_undergone_a_screening_test_for_cer TEXT, women_age_3049_years_ever_undergone_a_breast_examination_for TEXT, women_age_3049_years_ever_undergone_an_oral_cavity_examinati TEXT, men_age_3049_yearsever_undergone_an_oral_cavity_examination_ TEXT, women_age_1549_years_who_have_comprehensive_knowledge24_of_h TEXT, men_age_1549_years_who_have_comprehensive_knowledge24_of_hiv TEXT, women_age_1549_years_who_know_that_consistent_condom_use_can TEXT, men_age_1549_years_who_know_that_consistent_condom_use_can_r TEXT, currently_married_women_age_1549_years_who_usually_participa TEXT, women_age_1549_years_who_worked_in_the_last_12_months_and_we TEXT, women_age_1549_years_owning_a_house_andor_land_alone_or_join TEXT, women_age_1549_years_having_a_bank_or_savings_account_that_t TEXT, women_age_1549_years_having_a_mobile_phone_that_they_themsel TEXT, women_age_1524_years_who_use_hygienic_methods_of_protection_ TEXT, evermarried_women_age_1849_years_who_have_ever_experienced_s TEXT, evermarried_women_age_1849_years_who_have_experienced_physic TEXT, young_women_age_1829_years_who_experienced_sexual_violence_b TEXT, women_age_15_years_and_above_who_use_any_kind_of_tobacco_ DOUBLE PRECISION, men_age_15_years_and_above_who_use_any_kind_of_tobacco_ DOUBLE PRECISION, women_age_15_years_and_above_who_consume_alcohol_ DOUBLE PRECISION, men_age_15_years_and_above_who_consume_alcohol_ DOUBLE PRECISION);
CREATE TABLE languages (id BIGINT PRIMARY KEY, name TEXT);
CREATE TABLE occupation_stats (state BIGINT, tru_id BIGINT, age_group_id BIGINT, population_total BIGINT, population_male BIGINT, population_female BIGINT, main_workers_total BIGINT, main_workers_male BIGINT, main_workers_female BIGINT, marginal_workers_total BIGINT, marginal_workers_male BIGINT, marginal_workers_female BIGINT, marg_3_6mo_total BIGINT, marg_3_6mo_male BIGINT, marg_3_6mo_female BIGINT, marg_less_3mo_total BIGINT, marg_less_3mo_male BIGINT, marg_less_3mo_female BIGINT, non_workers_total BIGINT, non_workers_male BIGINT, non_workers_female BIGINT, seeking_work_total BIGINT, seeking_work_male BIGINT, seeking_work_female BIGINT);
CREATE TABLE population_stats (state BIGINT, tru_id BIGINT, age TEXT, persons BIGINT, males BIGINT, females BIGINT);
CREATE TABLE regions (state BIGINT PRIMARY KEY, area_name TEXT);
CREATE TABLE religions (id BIGINT PRIMARY KEY, religion_name TEXT);
CREATE TABLE tru (id BIGINT PRIMARY KEY, name TEXT);

### SQL
SELECT r.area_name, SUM(p.persons) AS working_age_population FROM population_stats p JOIN regions r ON p.state=r.state JOIN tru t ON p.tru_id=t.id WHERE t.name='Total' AND p.age NOT IN ('0-6','60+','65+') GROUP BY r.area_name ORDER BY working_age_population DESC;