instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Find the number of travel advisories issued per level in 'travel_advisory' table.
CREATE TABLE travel_advisory (advisory_level VARCHAR(20),advisory_count INT); INSERT INTO travel_advisory (advisory_level,advisory_count) VALUES ('Level 1',5),('Level 2',3),('Level 3',1);
SELECT advisory_level, SUM(advisory_count) as total_advisories FROM travel_advisory GROUP BY advisory_level;
Update the 'sites' table to correct the location of the 'Tutankhamun's Tomb'
CREATE TABLE sites (id INT PRIMARY KEY,name TEXT,location TEXT,start_date DATE);
UPDATE sites SET location = 'Luxor, Egypt' WHERE name = 'Tutankhamun''s Tomb';
What is the percentage of organic ingredients in cosmetics produced in Germany?
CREATE TABLE ingredients (product_id INT,ingredient_name VARCHAR(50),organic BOOLEAN); INSERT INTO ingredients VALUES (1,'Water',false),(1,'Paraben',false),(2,'Aloe Vera',true),(2,'Fragrance',false); CREATE TABLE sourcing (product_id INT,country VARCHAR(20)); INSERT INTO sourcing VALUES (1,'France'),(2,'Germany');
SELECT 100.0 * AVG(organic) AS percentage FROM ingredients JOIN sourcing ON ingredients.product_id = sourcing.product_id WHERE country = 'Germany';
What is the number of organizations that provide 'education_support' in each type of area ('rural_areas', 'urban_areas', 'suburban_areas')?
CREATE TABLE rural_areas (id INT,num_orgs INT,services VARCHAR(50));CREATE TABLE urban_areas (id INT,num_orgs INT,services VARCHAR(50));CREATE TABLE suburban_areas (id INT,num_orgs INT,services VARCHAR(50));
SELECT 'rural_areas' AS area, num_orgs FROM rural_areas WHERE services LIKE '%education_support%' UNION SELECT 'urban_areas' AS area, num_orgs FROM urban_areas WHERE services LIKE '%education_support%' UNION SELECT 'suburban_areas' AS area, num_orgs FROM suburban_areas WHERE services LIKE '%education_support%';
What is the maximum ocean floor depth in the Southern ocean?
CREATE TABLE depth_maxima (id INT,ocean VARCHAR(255),depth FLOAT); INSERT INTO depth_maxima (id,ocean,depth) VALUES (1,'Pacific',10994.0),(2,'Atlantic',8605.0),(3,'Indian',7455.0),(4,'Arctic',5381.0),(5,'Southern',7235.0);
SELECT depth FROM depth_maxima WHERE ocean = 'Southern';
What is the average citizen satisfaction score for waste management services in each district?
CREATE TABLE Waste_Management_Feedback (district_id INT,score INT); INSERT INTO Waste_Management_Feedback (district_id,score) VALUES (1,7),(1,8),(2,6),(2,5),(3,9),(3,8),(4,6),(4,7); CREATE TABLE Districts (id INT,name VARCHAR(50)); INSERT INTO Districts (id,name) VALUES (1,'Uptown'),(2,'Downtown'),(3,'Suburban'),(4,'Ru...
SELECT D.name, AVG(WMF.score) as Avg_Score FROM Waste_Management_Feedback WMF JOIN Districts D ON WMF.district_id = D.id GROUP BY D.name;
What is the average treatment capacity of wastewater treatment plants in South America?
CREATE TABLE wastewater_plants (id INT,continent VARCHAR(20),capacity FLOAT); INSERT INTO wastewater_plants (id,continent,capacity) VALUES (1,'South America',80.0),(2,'South America',85.0),(3,'North America',90.0),(4,'North America',95.0);
SELECT AVG(capacity) FROM wastewater_plants WHERE continent = 'South America';
Display the top 5 countries by organic produce exports in 2019.
CREATE TABLE OrganicProduceExports (id INT,country VARCHAR(50),year INT,value INT); INSERT INTO OrganicProduceExports (id,country,year,value) VALUES (1,'Mexico',2018,800),(2,'Mexico',2019,950),(3,'Peru',2018,600),(4,'Peru',2019,750),(5,'Ecuador',2018,500),(6,'Ecuador',2019,650),(7,'Argentina',2018,400),(8,'Argentina',2...
SELECT country, SUM(value) FROM OrganicProduceExports WHERE year = 2019 GROUP BY country ORDER BY SUM(value) DESC LIMIT 5;
Insert a new autonomous vehicle model, the 'Tesla Model Y', into the vehicles table.
CREATE TABLE vehicles (vehicle_id INT,model VARCHAR(20),manufacture VARCHAR(20),has_autonomous_features BOOLEAN);
INSERT INTO vehicles (model, manufacture, has_autonomous_features) VALUES ('Model Y', 'Tesla', TRUE);
What is the minimum number of flight hours for Space Shuttles before retirement?
CREATE TABLE space_shuttles (id INT,name VARCHAR(255),flights INT,flight_hours INT); INSERT INTO space_shuttles (id,name,flights,flight_hours) VALUES (1,'Atlantis',33,4848);
SELECT MIN(flight_hours) FROM space_shuttles WHERE name = 'Atlantis';
Delete all the traffic violation records in the city of New York from the year 2020.
CREATE TABLE violations (id INT,city VARCHAR(255),violation_date DATE); INSERT INTO violations (id,city,violation_date) VALUES (1,'New York','2020-01-01'),(2,'New York','2019-12-31'),(3,'Chicago','2020-02-01');
DELETE FROM violations WHERE city = 'New York' AND EXTRACT(YEAR FROM violation_date) = 2020;
Add a new carbon offset project called 'Mangrove Conservation' to the 'carbon_offset_projects' table
CREATE TABLE carbon_offset_projects (id INT PRIMARY KEY,project_name VARCHAR(100),location VARCHAR(50));
INSERT INTO carbon_offset_projects (project_name, location) VALUES ('Mangrove Conservation', 'Sundarbans');
What is the average risk score for policyholders in California?
CREATE TABLE policyholders (id INT,name VARCHAR(100),state VARCHAR(20),risk_score INT); INSERT INTO policyholders (id,name,state,risk_score) VALUES (1,'John Doe','CA',500),(2,'Jane Smith','CA',700),(3,'Alice Johnson','NY',600);
SELECT AVG(risk_score) FROM policyholders WHERE state = 'CA';
How many fish species were added to sustainable seafood trend reports each year in the last 5 years?
CREATE TABLE seafood_trends (year INT,species INT); INSERT INTO seafood_trends (year,species) VALUES (2017,3),(2018,4),(2019,5),(2020,6),(2021,7);
SELECT year, COUNT(species) FROM seafood_trends WHERE year BETWEEN 2016 AND 2021 GROUP BY year;
Delete a cargo record
cargo(cargo_id,cargo_name,weight,volume,description)
DELETE FROM cargo WHERE cargo_id = 2002;
List the names of startups that have not yet had an exit event
CREATE TABLE startup (id INT,name TEXT,exit_event TEXT); INSERT INTO startup (id,name,exit_event) VALUES (1,'Acme Inc','Acquisition'); INSERT INTO startup (id,name,exit_event) VALUES (2,'Beta Corp',NULL);
SELECT name FROM startup WHERE exit_event IS NULL;
What was the average price per gram of cannabis in Alaska in the third quarter of 2020?
CREATE TABLE sales (id INT,state VARCHAR(20),price DECIMAL(10,2),weight DECIMAL(10,2),month INT,year INT);
SELECT AVG(price/weight) FROM sales WHERE state = 'Alaska' AND (month = 7 OR month = 8 OR month = 9) AND year = 2020;
List the top 5 countries with the highest number of disaster response interventions in 2015.
CREATE TABLE disaster_response (country VARCHAR(255),num_interventions INT,year INT);
SELECT country, num_interventions FROM disaster_response WHERE year = 2015 ORDER BY num_interventions DESC LIMIT 5;
How many students with 'Hearing' disabilities are there in each department?
CREATE TABLE Students (Id INT,Name VARCHAR(50),Department VARCHAR(50),DisabilityType VARCHAR(50),Accommodations VARCHAR(50)); INSERT INTO Students (Id,Name,Department,DisabilityType,Accommodations) VALUES (1,'Alex Johnson','Occupational Therapy','Hearing','Sign Language Interpreter');
SELECT Department, COUNT(*) AS CountOfStudents FROM Students WHERE DisabilityType = 'Hearing' GROUP BY Department;
How many vehicles were serviced in 'Uptown'?
CREATE TABLE uptown_vehicles (vehicle_id int,service_date date); INSERT INTO uptown_vehicles (vehicle_id,service_date) VALUES (1,'2022-02-01'),(2,'2022-03-01'),(3,'2022-04-01');
SELECT COUNT(*) FROM uptown_vehicles WHERE service_date < CURDATE();
Which indigenous communities are most affected by coastal erosion?
CREATE TABLE coastal_erosion (id INT,community VARCHAR(255),erosion_rate FLOAT); CREATE TABLE indigenous_communities (id INT,name VARCHAR(255),location VARCHAR(255));
SELECT i.name, c.erosion_rate FROM indigenous_communities i JOIN coastal_erosion c ON i.location = c.community ORDER BY c.erosion_rate DESC;
How many community development initiatives were implemented in Oceania?
CREATE TABLE community_development (id INT,initiative_name VARCHAR(50),location VARCHAR(50),implementation_date DATE); INSERT INTO community_development (id,initiative_name,location,implementation_date) VALUES (1,'Community Library','Australia','2018-09-25');
SELECT COUNT(*) FROM community_development WHERE location LIKE '%Oceania%';
Delete the 'Blue Line' route
CREATE TABLE routes (route_id INT,route_name VARCHAR(255)); INSERT INTO routes (route_id,route_name) VALUES (1,'Green Line'),(2,'Red Line'),(3,'Blue Line');
DELETE FROM routes WHERE route_name = 'Blue Line';
What are the names and number of languages preserved in each region?
CREATE TABLE LanguagePreservation (id INT,region VARCHAR(255),language VARCHAR(255),preserved BOOLEAN); INSERT INTO LanguagePreservation (id,region,language,preserved) VALUES (1,'Region A','Language 1',TRUE),(2,'Region B','Language 2',FALSE),(3,'Region A','Language 3',TRUE);
SELECT region, language, COUNT(*) FROM LanguagePreservation WHERE preserved = TRUE GROUP BY region;
What is the maximum ticket price for hockey matches in the WestCoast region?
CREATE TABLE Stadiums(id INT,name TEXT,location TEXT,sport TEXT,capacity INT); INSERT INTO Stadiums(id,name,location,sport,capacity) VALUES (1,'Staples Center','Los Angeles','Hockey',18118),(2,'United Center','Chicago','Hockey',19717);
SELECT MAX(price) FROM TicketSales WHERE stadium_id IN (SELECT id FROM Stadiums WHERE location = 'WestCoast' AND sport = 'Hockey')
What percentage of the audience is non-binary and prefers articles about culture in the Western region?
CREATE TABLE audience (id INT,gender VARCHAR(10),region VARCHAR(20)); CREATE TABLE interests (id INT,category VARCHAR(20)); INSERT INTO audience VALUES (3,'non-binary','Western'); INSERT INTO interests VALUES (3,'culture');
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM audience)) as percentage FROM audience INNER JOIN interests ON audience.id = interests.id WHERE audience.region = 'Western' AND interests.category = 'culture' AND audience.gender = 'non-binary';
What is the maximum yield of a single crop grown by small-scale farmers in India?
CREATE TABLE crop_yields (farmer_id INT,country VARCHAR(50),crop VARCHAR(50),yield INT); INSERT INTO crop_yields (farmer_id,country,crop,yield) VALUES (1,'India','Rice',1000),(2,'India','Wheat',1200),(3,'India','Potatoes',1500);
SELECT MAX(yield) FROM crop_yields WHERE country = 'India';
What is the rank of energy efficiency for each region in the 'energy_efficiency' table?
CREATE TABLE energy_efficiency (region VARCHAR(50),energy_efficiency NUMERIC(5,2)); INSERT INTO energy_efficiency (region,energy_efficiency) VALUES ('Europe',80.0),('North America',75.0),('South America',65.0),('Asia',70.0);
SELECT region, RANK() OVER (ORDER BY energy_efficiency DESC) FROM energy_efficiency;
List all maritime law compliance initiatives with their corresponding countries.
CREATE SCHEMA oceans;CREATE TABLE oceans.maritime_compliance (id INT PRIMARY KEY,initiative VARCHAR(50),country VARCHAR(50)); INSERT INTO oceans.maritime_compliance (id,initiative,country) VALUES (1,'Safety regulations','USA'),(2,'Environmental regulations','Canada');
SELECT context.initiative, context.country FROM oceans.maritime_compliance AS context;
List all animals and their populations
CREATE TABLE animals (id INT PRIMARY KEY,name VARCHAR(50),species VARCHAR(50),population INT);
SELECT name, population FROM animals;
Insert a new record into the 'suppliers' table with id 101, name 'Green Supplies', 'country' 'USA', and 'renewable_material_usage' as 90%
CREATE TABLE suppliers (id INT,name VARCHAR(255),country VARCHAR(255),renewable_material_usage DECIMAL(5,2));
INSERT INTO suppliers (id, name, country, renewable_material_usage) VALUES (101, 'Green Supplies', 'USA', 0.90);
List the basketball players from the 'east_teams' and 'west_teams' tables who have more than 5 assists in a game.
CREATE TABLE east_teams (player_id INT,name VARCHAR(50),position VARCHAR(50),team VARCHAR(50),assists INT); CREATE TABLE west_teams (player_id INT,name VARCHAR(50),position VARCHAR(50),team VARCHAR(50),assists INT); INSERT INTO east_teams (player_id,name,position,team,assists) VALUES (1,'James Johnson','Guard','Boston ...
SELECT name, assists FROM east_teams WHERE assists > 5 UNION SELECT name, assists FROM west_teams WHERE assists > 5;
What is the policy renewal rate by policyholder gender?
CREATE TABLE PolicyHistory (PolicyID INT,PolicyType VARCHAR(20),Gender VARCHAR(10),Renewal BOOLEAN); INSERT INTO PolicyHistory (PolicyID,PolicyType,Gender,Renewal) VALUES (1,'Auto','Male',TRUE),(2,'Home','Female',FALSE),(3,'Life','Male',TRUE);
SELECT Gender, COUNT(*) OVER (PARTITION BY Gender) AS TotalPolicies, COUNT(*) FILTER (WHERE Renewal = TRUE) OVER (PARTITION BY Gender) AS RenewedPolicies, ROUND(COUNT(*) FILTER (WHERE Renewal = TRUE) OVER (PARTITION BY Gender) * 100.0 / COUNT(*) OVER (PARTITION BY Gender), 2) AS RenewalRate FROM PolicyHistory WHERE Ren...
What is the name of the rural health center with the most patients in "Texas"?
CREATE TABLE HealthCenters (HealthCenterID INT,Name VARCHAR(50),State VARCHAR(20),PatientCount INT); INSERT INTO HealthCenters (HealthCenterID,Name,State,PatientCount) VALUES (1,'Rural Health Center A','Texas',2500); INSERT INTO HealthCenters (HealthCenterID,Name,State,PatientCount) VALUES (2,'Rural Health Center B','T...
SELECT Name FROM HealthCenters WHERE State = 'Texas' AND PatientCount = (SELECT MAX(PatientCount) FROM HealthCenters WHERE State = 'Texas');
List all unions and their headquarters locations
CREATE TABLE unions (id INT,union_name VARCHAR(255)); CREATE TABLE union_details (id INT,union_name VARCHAR(255),location VARCHAR(255)); INSERT INTO unions (id,union_name) VALUES (1,'United Auto Workers'); INSERT INTO unions (id,union_name) VALUES (2,'United Food and Commercial Workers'); INSERT INTO union_details (id,...
SELECT unions.union_name, union_details.location FROM unions INNER JOIN union_details ON unions.union_name = union_details.union_name;
What is the average number of points scored by each player in a match for a specific team?
CREATE TABLE Player (PlayerID int,PlayerName varchar(50),TeamID int); CREATE TABLE Match (MatchID int,HomeTeamID int,AwayTeamID int,HomeTeamScore int,AwayTeamScore int); INSERT INTO Player (PlayerID,PlayerName,TeamID) VALUES (1,'Sachin Tendulkar',1),(2,'Rahul Dravid',1),(3,'Brian Lara',2),(4,'Shivnarine Chanderpaul',2...
SELECT p.TeamID, p.PlayerName, AVG(CASE WHEN p.TeamID = m.HomeTeamID THEN m.HomeTeamScore ELSE m.AwayTeamScore END) AS Avg_Points FROM Player p JOIN Match m ON (p.TeamID = m.HomeTeamID OR p.TeamID = m.AwayTeamID) GROUP BY p.TeamID, p.PlayerName;
Which genetic research projects have received funding in Germany?
CREATE TABLE genetic_research (id INT,project_name VARCHAR(50),location VARCHAR(50),funding_amount INT); INSERT INTO genetic_research (id,project_name,location,funding_amount) VALUES (1,'Project C','Germany',8000000); INSERT INTO genetic_research (id,project_name,location,funding_amount) VALUES (2,'Project D','France',...
SELECT project_name, funding_amount FROM genetic_research WHERE location = 'Germany';
What is the total number of articles published in "The Los Angeles Times" in 2020?
CREATE TABLE articles (id INT,title TEXT,content TEXT,publication_date DATE,newspaper TEXT);
SELECT COUNT(*) FROM articles WHERE newspaper = 'The Los Angeles Times' AND publication_date BETWEEN '2020-01-01' AND '2020-12-31';
Update the AI model version for the 'Creative AI' category to 2.3.
CREATE TABLE models (id INT,name VARCHAR(255),version FLOAT,category VARCHAR(255)); INSERT INTO models (id,name,version,category) VALUES (1,'Artistic Model',1.2,'Art');
UPDATE models SET version = 2.3 WHERE category = 'Creative AI'
Determine the rank of each team based on their total ticket sales in Canada.
CREATE TABLE teams (team_id INT,team_name VARCHAR(100)); INSERT INTO teams (team_id,team_name) VALUES (1,'Toronto Raptors'),(2,'Vancouver Grizzlies'); CREATE TABLE matches (match_id INT,team_home_id INT,team_away_id INT,tickets_sold INT); INSERT INTO matches (match_id,team_home_id,team_away_id,tickets_sold) VALUES (9,1...
SELECT team_name, RANK() OVER (ORDER BY total_sales DESC) as team_rank FROM (SELECT team_home_id, SUM(tickets_sold) as total_sales FROM matches WHERE location = 'Canada' GROUP BY team_home_id UNION ALL SELECT team_away_id, SUM(tickets_sold) as total_sales FROM matches WHERE location = 'Canada' GROUP BY team_away_id) to...
Update the contractor for permit 2021-015 to 'Green Builders'
CREATE TABLE building_permits (permit_number TEXT,contractor TEXT); INSERT INTO building_permits (permit_number,contractor) VALUES ('2021-015','Contractor D');
WITH cte AS (UPDATE building_permits SET contractor = 'Green Builders' WHERE permit_number = '2021-015') SELECT * FROM cte;
List the number of donations per month for the year 2022.
CREATE TABLE donations (id INT,donation_date DATE); INSERT INTO donations (id,donation_date) VALUES (1,'2022-01-01'),(2,'2022-01-15'),(3,'2022-02-01'),(4,'2022-02-15'),(5,'2022-03-01'),(6,'2022-12-31');
SELECT EXTRACT(MONTH FROM donation_date) as month, COUNT(*) as donations FROM donations WHERE donation_date BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY month;
Find the percentage change in water usage from the year 2018 to 2019
CREATE TABLE water_usage (year INT,usage FLOAT); INSERT INTO water_usage (year,usage) VALUES (2018,1234.56),(2019,2345.67),(2020,3456.78),(2021,4567.89);
SELECT ((usage_2019.usage - usage_2018.usage) / usage_2018.usage * 100) FROM (SELECT usage FROM water_usage WHERE year = 2018) AS usage_2018, (SELECT usage FROM water_usage WHERE year = 2019) AS usage_2019;
How many patients were diagnosed with PTSD in 2019 and 2020?
CREATE TABLE diagnoses (id INT,patient_id INT,diagnosis VARCHAR(30),diagnosis_date DATE); INSERT INTO diagnoses (id,patient_id,diagnosis,diagnosis_date) VALUES (1,1,'anxiety','2020-05-05'),(2,2,'depression','2019-08-12'),(3,3,'anxiety','2020-11-15'),(4,4,'PTSD','2019-06-28'),(5,5,'PTSD','2020-02-03'),(6,6,'anxiety','20...
SELECT YEAR(diagnosis_date) AS year, COUNT(*) FROM diagnoses WHERE diagnosis = 'PTSD' GROUP BY year;
Which countries have the highest number of esports event viewers, and what is their age distribution?
CREATE TABLE events (id INT,game VARCHAR(30),viewers INT,country VARCHAR(20)); INSERT INTO events (id,game,viewers,country) VALUES (1,'LoL',100000,'KR'),(2,'CS:GO',50000,'US'),(3,'Dota 2',80000,'CN'),(4,'Fortnite',120000,'US'); CREATE TABLE players (id INT,age INT,country VARCHAR(20)); INSERT INTO players (id,age,count...
SELECT e.country, COUNT(e.id) AS viewers, AVG(p.age) AS avg_age FROM events e JOIN players p ON e.country = p.country GROUP BY e.country ORDER BY viewers DESC;
Insert a new city record in Texas with 2 libraries.
CREATE TABLE cities (id INT,name TEXT,state TEXT,num_libraries INT);
INSERT INTO cities (name, state, num_libraries) VALUES ('New City', 'TX', 2);
Who are the top 3 threat actors by the number of incidents in the last year?
CREATE TABLE threat_actors (id INT,actor_name VARCHAR(50),incident_date DATE); INSERT INTO threat_actors (id,actor_name,incident_date) VALUES (1,'APT28','2022-01-01'),(2,'APT33','2022-02-05'),(3,'Lazarus','2022-03-10');
SELECT actor_name, COUNT(*) as incident_count FROM threat_actors WHERE incident_date >= DATEADD(year, -1, GETDATE()) GROUP BY actor_name ORDER BY incident_count DESC LIMIT 3;
What was the total quantity of salmon exported from Norway to the USA in 2021?
CREATE TABLE seafood_exports (id INT,export_date DATE,export_country TEXT,import_country TEXT,quantity INT); INSERT INTO seafood_exports (id,export_date,export_country,import_country,quantity) VALUES (1,'2021-01-01','Norway','USA',1200); INSERT INTO seafood_exports (id,export_date,export_country,import_country,quantity...
SELECT SUM(quantity) FROM seafood_exports WHERE export_country = 'Norway' AND import_country = 'USA' AND EXTRACT(YEAR FROM export_date) = 2021 AND species = 'Salmon';
What are the names of all heritage sites in France?
CREATE TABLE heritage_sites (site_id INT,site_name TEXT,country TEXT); INSERT INTO heritage_sites (site_id,site_name,country) VALUES (1,'Eiffel Tower','France'),(2,'Statue of Liberty','USA'),(3,'Sydney Opera House','Australia');
SELECT site_name FROM heritage_sites WHERE country = 'France';
Delete virtual tours with less than 500 views in Brazil and Argentina.
CREATE TABLE virtual_tours(id INT,name TEXT,country TEXT,views INT); INSERT INTO virtual_tours(id,name,country,views) VALUES (4,'Tour A','Brazil',700),(5,'Tour B','Argentina',400),(6,'Tour C','Chile',1200);
DELETE FROM virtual_tours WHERE (country = 'Brazil' OR country = 'Argentina') AND views < 500;
Which country has the highest exploration_cost in the Exploration_Data table?
CREATE TABLE Exploration_Data (country text,exploration_date date,exploration_cost real); INSERT INTO Exploration_Data (country,exploration_date,exploration_cost) VALUES ('USA','2020-01-01',500000),('Canada','2020-01-02',550000);
SELECT country, MAX(exploration_cost) FROM Exploration_Data GROUP BY country;
What is the most common gender of users who have posted ads?
CREATE TABLE users (id INT PRIMARY KEY,name VARCHAR(50),age INT,gender VARCHAR(10)); CREATE TABLE ads (id INT PRIMARY KEY,post_id INT,clicks INT,views INT,user_id INT); INSERT INTO users (id,name,age,gender) VALUES (1,'Kai',22,'Non-binary'); INSERT INTO users (id,name,age,gender) VALUES (2,'Lea',25,'Female'); INSERT IN...
SELECT users.gender, COUNT(ads.id) FROM users INNER JOIN ads ON users.id = ads.user_id GROUP BY users.gender ORDER BY COUNT(ads.id) DESC LIMIT 1;
List all types of sustainable materials used by companies in descending order of their popularity.
CREATE TABLE company_materials (company_id INT,material TEXT); INSERT INTO company_materials (company_id,material) VALUES (1,'organic cotton'),(1,'recycled polyester'),(2,'organic cotton'),(2,'hemp'),(3,'recycled polyester'),(3,'linen'),(4,'hemp'),(5,'organic cotton'),(6,'recycled polyester'),(6,'linen'),(7,'organic co...
SELECT material, COUNT(*) as count FROM company_materials GROUP BY material ORDER BY count DESC;
What is the minimum mental health score for students in California?
CREATE TABLE StudentMentalHealth (id INT,name TEXT,mental_health_score INT,state TEXT); INSERT INTO StudentMentalHealth (id,name,mental_health_score,state) VALUES (1,'Jessica',75,'California'),(2,'Lucas',85,'Texas'),(3,'Oliver',95,'California');
SELECT MIN(mental_health_score) FROM StudentMentalHealth WHERE state = 'California';
What is the average age of non-binary patients by condition?
CREATE TABLE PatientDemographics (PatientID int,ConditionID int,Gender varchar(20)); INSERT INTO PatientDemographics (PatientID,ConditionID,Gender) VALUES (1,1,'Female'),(2,2,'Male'),(3,3,'Non-binary');
SELECT PatientDemographics.ConditionID, PatientDemographics.Gender, AVG(PatientDemographics.Age) FROM PatientDemographics JOIN PatientAges ON PatientDemographics.PatientID = PatientAges.PatientID WHERE PatientDemographics.Gender = 'Non-binary' GROUP BY PatientDemographics.ConditionID, PatientDemographics.Gender;
What is the minimum sodium content in vegetarian dishes in Canada?
CREATE TABLE CanadianDishes(id INT,name TEXT,sodium INT,is_vegetarian BOOLEAN); INSERT INTO CanadianDishes(id,name,sodium,is_vegetarian) VALUES (1,'Vegetarian Chili',600,TRUE),(2,'Lentil Soup',450,TRUE);
SELECT MIN(sodium) FROM CanadianDishes WHERE is_vegetarian = TRUE;
What is the geopolitical risk level for 'Country X' in 2022?
CREATE TABLE geopolitical_risks (country varchar(255),year int,risk_level int); INSERT INTO geopolitical_risks (country,year,risk_level) VALUES ('Country X',2022,3),('Country X',2021,2),('Country Y',2022,4);
SELECT risk_level FROM geopolitical_risks WHERE country = 'Country X' AND year = 2022;
What is the total number of volunteer hours served by each volunteer in the Central region?
CREATE TABLE volunteer_hours (volunteer_id INT,vol_name TEXT,vol_region TEXT,hours_served INT); INSERT INTO volunteer_hours (volunteer_id,vol_name,vol_region,hours_served) VALUES (1,'Ali Doe','Central',50),(2,'Priya Smith','Central',75),(3,'Khalid Johnson','Central',100);
SELECT vol_name, SUM(hours_served) as total_hours FROM volunteer_hours WHERE vol_region = 'Central' GROUP BY vol_name;
How many marine species are found in the Mediterranean Sea?
CREATE TABLE marine_species (species_name TEXT,habitat TEXT); INSERT INTO marine_species (species_name,habitat) VALUES ('Dolphin','Mediterranean Sea'),('Tuna','Atlantic Ocean');
SELECT COUNT(*) FROM marine_species WHERE habitat = 'Mediterranean Sea';
What's the average number of hours served by volunteers per day?
CREATE TABLE VolunteerHours (Id INT,VolunteerId INT,Hours DECIMAL(10,2),HoursDate DATE); INSERT INTO VolunteerHours VALUES (1,1,10.00,'2022-01-01'),(2,1,8.00,'2022-01-02');
SELECT DATE_TRUNC('day', HoursDate) as Day, AVG(Hours) as AvgHours FROM VolunteerHours GROUP BY Day;
What is the average lifespan of artists who have died?
CREATE TABLE Artists (ArtistID int,Name varchar(50),BirthYear int,DeathYear int); INSERT INTO Artists (ArtistID,Name,BirthYear,DeathYear) VALUES (1,'Leonardo da Vinci',1452,1519),(2,'Vincent van Gogh',1853,1890),(3,'Salvador Dalí',1904,1989),(4,'Pablo Picasso',1881,1973),(5,'Francis Bacon',1909,1992);
SELECT AVG(DeathYear - BirthYear) AS AverageLifespan FROM Artists WHERE DeathYear IS NOT NULL;
What is the minimum price of a product in the education_products table?
CREATE TABLE education_products (product_id INT,product_name TEXT,price DECIMAL); INSERT INTO education_products (product_id,product_name,price) VALUES (1,'Sustainability Guidebook',20),(2,'Eco-Friendly Craft Kit',30),(3,'Educational Poster',10);
SELECT MIN(price) FROM education_products;
Insert new records into the teams table
CREATE TABLE teams (id INT PRIMARY KEY,name VARCHAR(50),league VARCHAR(50));
INSERT INTO teams (id, name, league) VALUES (1, 'Tigers', 'MLB'), (2, 'Lakers', 'NBA');
How many schools are there in Haiti and how many students attend them?
CREATE TABLE schools (id INT,country VARCHAR(255),name VARCHAR(255),num_students INT); INSERT INTO schools (id,country,name,num_students) VALUES (1,'Haiti','School 1',500),(2,'Haiti','School 2',700);
SELECT country, SUM(num_students) FROM schools GROUP BY country;
What is the percentage of students who prefer open pedagogy by gender?
CREATE TABLE student_pedagogy (student_id INT,gender VARCHAR(255),prefers_open_pedagogy BOOLEAN); INSERT INTO student_pedagogy (student_id,gender,prefers_open_pedagogy) VALUES (1,'Male',TRUE),(2,'Female',FALSE),(3,'Non-binary',TRUE),(4,'Male',FALSE);
SELECT gender, 100.0 * AVG(CASE WHEN prefers_open_pedagogy THEN 1 ELSE 0 END) as percentage_prefers_open_pedagogy FROM student_pedagogy GROUP BY gender;
Create a table named 'MentalHealthParity' in 'healthcare' schema
CREATE TABLE healthcare.MentalHealthParity(parity_id INT PRIMARY KEY,healthcare_provider VARCHAR(100),mental_health_coverage FLOAT);
CREATE TABLE healthcare.MentalHealthParity( parity_id INT PRIMARY KEY, healthcare_provider VARCHAR(100), mental_health_coverage FLOAT);
Add data to 'climate_communication_campaigns' table
CREATE TABLE climate_communication_campaigns (id INT PRIMARY KEY,name VARCHAR(50),target_audience VARCHAR(50),start_date DATE,end_date DATE,objective VARCHAR(50));
INSERT INTO climate_communication_campaigns (id, name, target_audience, start_date, end_date, objective) VALUES (1, 'Green Living Tips', 'General Public', '2023-01-01', '2023-12-31', 'Promote energy efficiency');
What is the maximum number of workforce development training hours received by a worker in the 'Paper' industry?
CREATE TABLE training_hours (id INT,industry VARCHAR(255),hours INT);
SELECT MAX(hours) FROM training_hours WHERE industry = 'Paper';
Which military equipment type has the highest number of maintenance incidents?
CREATE TABLE equipment_maintenance (equipment_type TEXT,incidents INT); INSERT INTO equipment_maintenance (equipment_type,incidents) VALUES ('Tank',25),('Fighter Jet',15),('Helicopter',30);
SELECT equipment_type, incidents FROM equipment_maintenance ORDER BY incidents DESC LIMIT 1;
What is the total number of vulnerabilities reported for each software category?
CREATE TABLE category_vulnerabilities (category VARCHAR(255),vulnerability_count INT); INSERT INTO category_vulnerabilities (category,vulnerability_count) VALUES ('Operating System',25),('Application',18),('Network Device',12),('Database',9),('Hardware',5);
SELECT category, SUM(vulnerability_count) as total_vulnerabilities FROM category_vulnerabilities GROUP BY category;
Find the attendee count for events in Los Angeles, ordered by event type.
CREATE TABLE Events (ID INT,City VARCHAR(50),EventType VARCHAR(50),AttendeeCount INT);
SELECT EventType, AttendeeCount FROM Events WHERE City = 'Los Angeles' ORDER BY EventType;
What is the total number of articles in 'category1' and 'category2'?
CREATE TABLE articles (id INT,title VARCHAR(50),category VARCHAR(20)); INSERT INTO articles (id,title,category) VALUES (1,'Article1','category1'),(2,'Article2','category2');
SELECT COUNT(*) FROM articles WHERE category IN ('category1', 'category2');
How many unique customers have purchased sustainable fashion items?
CREATE TABLE Customers (id INT,name VARCHAR(20),sustainable BOOLEAN); INSERT INTO Customers (id,name,sustainable) VALUES (1,'Alice',true),(2,'Bob',false),(3,'Charlie',true),(4,'David',true);
SELECT COUNT(DISTINCT id) FROM Customers WHERE sustainable = true;
What is the average temperature change in the Arctic region between 1980 and 2010, and how does it compare to the global average temperature change during the same period?
CREATE TABLE ArcticWeatherData (location VARCHAR(50),year INT,avg_temp FLOAT);
SELECT w1.avg_temp - w2.avg_temp AS temp_diff FROM (SELECT AVG(avg_temp) FROM ArcticWeatherData WHERE location LIKE 'Arctic%' AND year BETWEEN 1980 AND 2010) w1, (SELECT AVG(avg_temp) FROM ArcticWeatherData WHERE year BETWEEN 1980 AND 2010) w2;
List the names of heritage sites and their respective conservation statuses in 'Country A'.
CREATE TABLE Heritage_Sites (site_name VARCHAR(50),country VARCHAR(50),conservation_status VARCHAR(50)); INSERT INTO Heritage_Sites (site_name,country,conservation_status) VALUES ('Site A','Country A','Endangered');
SELECT site_name, conservation_status FROM Heritage_Sites WHERE country = 'Country A';
Show the number of heritage sites in each country in Europe, ordered from the most to the least, along with their respective percentage in relation to the total number of heritage sites in Europe.
CREATE TABLE UNESCO_Heritage_Sites (id INT,country VARCHAR(50),site VARCHAR(100)); INSERT INTO UNESCO_Heritage_Sites (id,country,site) VALUES (1,'Italy','Colosseum'),(2,'France','Eiffel Tower'),(3,'Spain','Alhambra');
SELECT country, COUNT(site) as num_sites, ROUND(COUNT(site) * 100.0 / (SELECT COUNT(*) FROM UNESCO_Heritage_Sites WHERE country = 'Europe'), 2) as percentage FROM UNESCO_Heritage_Sites WHERE country = 'Europe' GROUP BY country ORDER BY num_sites DESC;
Find the number of military aircrafts in maintenance
CREATE TABLE MilitaryEquipment (id INT,type VARCHAR(50),status VARCHAR(50)); INSERT INTO MilitaryEquipment (id,type,status) VALUES (1,'F-16','Maintenance'); INSERT INTO MilitaryEquipment (id,type,status) VALUES (2,'A-10','Operational');
SELECT COUNT(*) FROM MilitaryEquipment WHERE status = 'Maintenance' AND type LIKE 'Aircraft';
Which clients have a higher balance between their Shariah-compliant and conventional financing?
CREATE TABLE shariah_financing(client_id INT,country VARCHAR(25),amount FLOAT);CREATE TABLE conventional_financing(client_id INT,country VARCHAR(25),amount FLOAT);INSERT INTO shariah_financing(client_id,country,amount) VALUES (1,'Malaysia',5000),(2,'UAE',7000),(3,'Indonesia',6000),(4,'Saudi Arabia',8000);INSERT INTO co...
SELECT s.client_id, s.country, s.amount AS shariah_amount, c.amount AS conventional_amount, CASE WHEN s.amount > c.amount THEN 'Shariah' ELSE 'Conventional' END AS higher_balance FROM shariah_financing s JOIN conventional_financing c ON s.client_id = c.client_id;
What is the average rating of K-pop songs released in 2022?
CREATE TABLE songs (id INT,title VARCHAR(255),artist VARCHAR(255),genre VARCHAR(255),release_year INT,rating DECIMAL(3,2)); INSERT INTO songs (id,title,artist,genre,release_year,rating) VALUES (1,'Song 1','Artist A','K-pop',2022,8.5),(2,'Song 2','Artist B','Pop',2021,9.0),(3,'Song 3','Artist C','K-pop',2022,8.8);
SELECT AVG(rating) FROM songs WHERE genre = 'K-pop' AND release_year = 2022;
Identify the number of models developed by each organization that are biased.
CREATE TABLE models (model_id INT,org_id INT,is_biased BOOLEAN); INSERT INTO models (model_id,org_id,is_biased) VALUES (101,1,true),(102,1,false),(103,2,true),(104,2,true),(105,3,false);
SELECT org_id, COUNT(*) FROM models WHERE is_biased = true GROUP BY org_id;
What is the average salary of workers in the 'manufacturing' division?
CREATE TABLE employees (id INT,name VARCHAR(100),division VARCHAR(50),salary FLOAT); INSERT INTO employees (id,name,division,salary) VALUES (1,'John Doe','manufacturing',60000.00),(2,'Jane Smith','marketing',70000.00);
SELECT AVG(salary) FROM employees WHERE division = 'manufacturing';
What is the average cargo handling time in hours for the 'handling_events' table?
CREATE TABLE handling_events (event_id INT,port_id INT,event_time TIME); INSERT INTO handling_events (event_id,port_id,event_time) VALUES (1,1,'12:30:00'),(2,2,'10:00:00'),(3,3,'14:00:00');
SELECT AVG(TIME_TO_SEC(event_time) / 3600) FROM handling_events;
How many sustainable tours are in the United Kingdom?
CREATE TABLE sustainable_tours (tour_id INT,tour_name TEXT,country TEXT); INSERT INTO sustainable_tours (tour_id,tour_name,country) VALUES (1,'Wind Farm Visit','UK'),(2,'Solar Panel Farm','UK');
SELECT COUNT(*) FROM sustainable_tours WHERE country = 'UK';
Find the number of employees and total salary costs for companies with mining operations in Canada and the US.
CREATE TABLE company (id INT,name VARCHAR(255),country VARCHAR(255),num_employees INT,avg_salary DECIMAL(10,2));CREATE VIEW canadian_companies AS SELECT * FROM company WHERE country = 'Canada';CREATE VIEW us_companies AS SELECT * FROM company WHERE country = 'USA';CREATE VIEW mining_companies AS SELECT * FROM company W...
SELECT mc.name, SUM(mc.num_employees) as total_employees, SUM(mc.num_employees * mc.avg_salary) as total_salary_costs FROM (SELECT * FROM canadian_companies UNION ALL SELECT * FROM us_companies) mc JOIN mining_companies m ON mc.id = m.id GROUP BY mc.name;
What is the average funding received by biotech startups in each state?
CREATE SCHEMA if not exists avg_funding;CREATE TABLE if not exists avg_funding.startups (id INT,name VARCHAR(100),state VARCHAR(50),funding DECIMAL(10,2));INSERT INTO avg_funding.startups (id,name,state,funding) VALUES (1,'StartupA','California',2000000.00),(2,'StartupB','New York',1500000.00),(3,'StartupC','California...
SELECT state, AVG(funding) FROM avg_funding.startups GROUP BY state;
Update the 'resilience_score' of the bridge named 'Chenab Bridge' to 92.5.
CREATE TABLE bridges (id INT,name TEXT,region TEXT,resilience_score FLOAT); INSERT INTO bridges (id,name,region,resilience_score) VALUES (1,'Golden Gate Bridge','West Coast',85.2),(2,'Brooklyn Bridge','East Coast',76.3),(3,'Bay Bridge','West Coast',78.1),(4,'Chenab Bridge','South Asia',89.6);
UPDATE bridges SET resilience_score = 92.5 WHERE name = 'Chenab Bridge';
How many ground vehicles were ordered by the Army in 2020?
CREATE TABLE Ground_Vehicles (ID INT,Branch VARCHAR(50),Year INT,Quantity INT); INSERT INTO Ground_Vehicles (ID,Branch,Year,Quantity) VALUES (1,'Army',2015,60),(2,'Army',2020,75),(3,'Navy',2017,40);
SELECT Quantity FROM Ground_Vehicles WHERE Branch = 'Army' AND Year = 2020;
What is the average number of workers in unions advocating for labor rights in each state?
CREATE TABLE unions (id INT,state VARCHAR(2),workers INT,issue VARCHAR(14));
SELECT state, AVG(workers) FROM unions WHERE issue = 'labor_rights' GROUP BY state;
Show the minimum and maximum salary by department
CREATE TABLE salaries (id INT,department VARCHAR(255),salary DECIMAL(10,2)); INSERT INTO salaries (id,department,salary) VALUES (1,'Engineering',90000.00),(2,'Marketing',80000.00),(3,'Sales',70000.00),(4,'HR',75000.00);
SELECT department, MIN(salary) as min_salary, MAX(salary) as max_salary FROM salaries GROUP BY department;
What is the average age of female community health workers in Texas?
CREATE TABLE CommunityHealthWorkers (ID INT,Gender VARCHAR(10),Age INT,State VARCHAR(50)); INSERT INTO CommunityHealthWorkers (ID,Gender,Age,State) VALUES (1,'Female',45,'Texas'); INSERT INTO CommunityHealthWorkers (ID,Gender,Age,State) VALUES (2,'Male',50,'Texas');
SELECT AVG(Age) FROM CommunityHealthWorkers WHERE Gender = 'Female' AND State = 'Texas';
How many employees work in the 'Risk Management' department in the 'New York' office?
CREATE TABLE office (office_id INT,city VARCHAR(50),state VARCHAR(50)); CREATE TABLE department (department_id INT,department_name VARCHAR(50),office_id INT); CREATE TABLE employee (employee_id INT,employee_name VARCHAR(100),department_id INT); INSERT INTO office (office_id,city,state) VALUES (1,'New York','NY'),(2,'To...
SELECT COUNT(*) FROM employee JOIN department ON employee.department_id = department.department_id JOIN office ON department.office_id = office.office_id WHERE office.city = 'New York' AND department.department_name = 'Risk Management';
What is the average waste generation per manufacturing country?
CREATE TABLE waste_generation (id INT,garment_id INT,country VARCHAR(20),waste_quantity INT,manufacturing_date DATE);CREATE VIEW avg_waste_generation_by_country AS SELECT country,AVG(waste_quantity) as avg_waste FROM waste_generation GROUP BY country;
SELECT country, avg_waste FROM avg_waste_generation_by_country;
How many factories have been certified as fair trade in the past 2 years?
CREATE TABLE FairTradeCertifiedFactories(factory_id INT,certification_year INT);
SELECT COUNT(*) FROM FairTradeCertifiedFactories WHERE certification_year >= YEAR(CURRENT_DATE) - 2;
Which countries participated in peacekeeping operations from 2018 to 2020?
CREATE TABLE peacekeeping (country VARCHAR(50),year INT,operation VARCHAR(50)); INSERT INTO peacekeeping (country,year,operation) VALUES ('Ethiopia',2018,'MINUSCA'); INSERT INTO peacekeeping (country,year,operation) VALUES ('Rwanda',2018,'MONUSCO'); INSERT INTO peacekeeping (country,year,operation) VALUES ('Bangladesh'...
SELECT DISTINCT country FROM peacekeeping WHERE year BETWEEN 2018 AND 2020;
What is the average climate finance provided to countries in the Pacific region for climate mitigation projects in 2020?
CREATE TABLE climate_finance (country VARCHAR(50),year INT,sector VARCHAR(50),mitigation BOOLEAN,amount FLOAT); INSERT INTO climate_finance (country,year,sector,mitigation,amount) VALUES ('Fiji',2020,'Mitigation',true,2000000),('Palau',2020,'Mitigation',true,3000000),('Marshall Islands',2020,'Mitigation',true,4000000),...
SELECT AVG(amount) FROM climate_finance WHERE country IN ('Fiji', 'Palau', 'Marshall Islands', 'Samoa', 'Tonga', 'Tuvalu') AND year = 2020 AND mitigation = true;
What is the number of unique digital asset launches per day in the Ethereum network, excluding weekends?
CREATE TABLE ethereum_assets (launch_date TIMESTAMP,asset_id INT);
SELECT DATE(launch_date) as launch_day, COUNT(DISTINCT asset_id) as unique_daily_launches FROM ethereum_assets WHERE DATE(launch_date) BETWEEN '2021-01-01' AND '2021-12-31' AND DAYOFWEEK(launch_date) NOT IN (1,7) GROUP BY launch_day;
What is the average certification rating of smart cities in Canada?
CREATE TABLE SmartCities (id INT,name VARCHAR(50),country VARCHAR(50),population INT,area_size FLOAT,certification_rating INT); INSERT INTO SmartCities (id,name,country,population,area_size,certification_rating) VALUES (3,'Vancouver','Canada',631486,114.69,85);
SELECT AVG(s.certification_rating) FROM SmartCities s WHERE s.country = 'Canada';
What is the total number of ethical AI patents filed by women-led organizations?
CREATE TABLE Ethical_AI_Patents (organization VARCHAR(50),year INT,patent VARCHAR(50)); INSERT INTO Ethical_AI_Patents (organization,year,patent) VALUES ('AI for Good',2018,'AI Ethics Framework'),('Ethical Tech Lab',2019,'Ethical AI Algorithm'),('Women in AI',2018,'Ethical AI Guidelines'),('AI Empowerment',2019,'Ethica...
SELECT organization, COUNT(patent) as num_patents FROM Ethical_AI_Patents GROUP BY organization;
Which program had the highest total volunteer hours from volunteers outside of the US in 2021?
CREATE TABLE Volunteers (volunteer_id INT,volunteer_name VARCHAR(50),program_id INT,volunteer_hours INT,volunteer_date DATE,volunteer_country VARCHAR(50)); INSERT INTO Volunteers (volunteer_id,volunteer_name,program_id,volunteer_hours,volunteer_date,volunteer_country) VALUES (1,'Sophia',1,5,'2021-06-05','Mexico'),(2,'J...
SELECT program_id, SUM(volunteer_hours) as total_2021_volunteer_hours FROM Volunteers WHERE volunteer_date BETWEEN '2021-01-01' AND '2021-12-31' AND volunteer_country != 'US' GROUP BY program_id ORDER BY total_2021_volunteer_hours DESC LIMIT 1;
What is the average number of academic publications per author?
CREATE TABLE publications (id INT,author_gender VARCHAR(6),title VARCHAR(255)); INSERT INTO publications (id,author_gender,title) VALUES (1,'Female','Machine Learning Algorithms'),(2,'Male','Quantum Physics'),(3,'Female','Data Visualization'),(4,'Male','Deep Learning');
SELECT AVG(total_publications) FROM (SELECT COUNT(*) as total_publications FROM publications GROUP BY author_gender) as subquery;