instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Find the number of players who have played "Fighting Game F" and identify their gender.
CREATE TABLE Fighting_Game_F (player_id INT,name VARCHAR(50),age INT,gender VARCHAR(10)); INSERT INTO Fighting_Game_F (player_id,name,age,gender) VALUES (2,'Jane Smith',24,'Female'),(4,'Bob Brown',30,'Male'),(11,'Oliver Lee',26,'Male');
SELECT COUNT(*), gender FROM Fighting_Game_F GROUP BY gender;
How many hotels in 'Asia' have adopted cloud-based PMS systems?
CREATE TABLE pms_adoption (hotel_id INT,country TEXT,pms_cloud_based BOOLEAN); INSERT INTO pms_adoption (hotel_id,country,pms_cloud_based) VALUES (1,'Japan',true),(2,'China',false),(3,'Japan',false),(4,'India',true),(5,'China',true);
SELECT COUNT(*) FROM pms_adoption WHERE country LIKE 'Asia%' AND pms_cloud_based = true;
What is the maximum program impact score for programs in the environmental sector?
CREATE TABLE Programs (ProgramID INT,ProgramName TEXT,Sector TEXT,ImpactScore DECIMAL); INSERT INTO Programs (ProgramID,ProgramName,Sector,ImpactScore) VALUES (1,'Clean Energy','Environmental',85.00),(2,'Conservation Efforts','Environmental',90.00);
SELECT Sector, MAX(ImpactScore) FROM Programs WHERE Sector = 'Environmental' GROUP BY Sector;
List all aircraft models and their average flight hours for the year 2019.
CREATE TABLE aircraft_flights (id INT,model VARCHAR(50),flight_hours DECIMAL(5,2),year INT); INSERT INTO aircraft_flights (id,model,flight_hours,year) VALUES (1,'Boeing 737',3500.5,2019),(2,'Airbus A320',3200.2,2019),(3,'Boeing 787',3800.8,2018);
SELECT model, AVG(flight_hours) as avg_flight_hours FROM aircraft_flights WHERE year = 2019 GROUP BY model;
Show the number of customers that signed up for each broadband plan in the last month?
CREATE TABLE customers (id INT,name VARCHAR(255),broadband_plan_id INT,created_at TIMESTAMP); CREATE TABLE broadband_plans (id INT,name VARCHAR(255),price DECIMAL(10,2));
SELECT bp.name, COUNT(*) as total_customers FROM customers c JOIN broadband_plans bp ON c.broadband_plan_id = bp.id WHERE c.created_at >= DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 MONTH) GROUP BY bp.name;
Which programs received donations of more than $100 in a single day in 2022?
CREATE TABLE DailyDonations (DonationID int,ProgramName varchar(255),DonationAmount decimal(10,2),DonationDate date); INSERT INTO DailyDonations VALUES (1,'Education',150,'2022-01-01'),(2,'Healthcare',100,'2022-02-01'),(3,'Environment',125,'2022-03-01'),(4,'Education',175,'2022-04-01'),(5,'Healthcare',200,'2022-05-01');
SELECT ProgramName FROM (SELECT ProgramName, ROW_NUMBER() OVER (PARTITION BY ProgramName ORDER BY DonationDate) as Rank FROM DailyDonations WHERE DonationAmount > 100) as DonationRanks WHERE Rank = 1;
What is the average depth of all sea mounts in the Pacific Ocean?
CREATE TABLE if not exists sea_mounts (id INT,name TEXT,location TEXT,depth FLOAT);
SELECT AVG(depth) FROM sea_mounts WHERE location LIKE '%Pacific%';
How many donors made donations in each quarter of the year?
CREATE TABLE Donors (id INT,donor_name TEXT,donation_date DATE); INSERT INTO Donors (id,donor_name,donation_date) VALUES (1,'Jane Doe','2022-01-15');
SELECT DATEPART(quarter, donation_date) as quarter, COUNT(DISTINCT donor_name) as num_donors FROM Donors GROUP BY quarter;
What is the maximum explainability score for AI models grouped by model version in the 'ai_models' table?
CREATE TABLE ai_models (model_id INT,model_version TEXT,explainability_score FLOAT);
SELECT model_version, MAX(explainability_score) FROM ai_models GROUP BY model_version;
How many traditional dances are present in 'Africa' and 'Asia'?
CREATE TABLE TraditionalDances (DanceID INT PRIMARY KEY,DanceName VARCHAR(50),Location VARCHAR(50),Type VARCHAR(50)); INSERT INTO TraditionalDances (DanceID,DanceName,Location,Type) VALUES (1,'Kizomba','Angola','Dance'),(2,'Bharatanatyam','India','Dance');
SELECT COUNT(*) FROM TraditionalDances WHERE Location IN ('Africa', 'Asia');
What is the total number of mental health parity violations for each ethnicity?
CREATE TABLE mental_health_parity (id INT,ethnicity VARCHAR(50),violations INT); INSERT INTO mental_health_parity (id,ethnicity,violations) VALUES (1,'Hispanic',200),(2,'African American',150),(3,'Caucasian',250);
SELECT ethnicity, SUM(violations) as total_violations FROM mental_health_parity GROUP BY ethnicity;
Update the score for the player 'Sana Patel' to 1200 in the 'Galactic Guardians' table.
CREATE TABLE Galactic_Guardians (player_id INT,player_name VARCHAR(50),score INT); INSERT INTO Galactic_Guardians (player_id,player_name,score) VALUES (1,'Sana Patel',750),(2,'Mohammed Khan',1100),(3,'Fatima Bhutto',1400);
UPDATE Galactic_Guardians SET score = 1200 WHERE player_name = 'Sana Patel';
Update the "court_cases" table to reflect the new case disposition
CREATE TABLE court_cases (id INT,offense_id INT,case_number VARCHAR(20),disposition VARCHAR(20));
UPDATE court_cases SET disposition = 'Dismissed' WHERE id = 4001;
List all the forest plots, their corresponding wildlife species, and the carbon sequestration for each plot.
CREATE TABLE ForestPlots (PlotID int,PlotName varchar(50)); INSERT INTO ForestPlots VALUES (1,'Plot1'),(2,'Plot2'); CREATE TABLE Wildlife (SpeciesID int,SpeciesName varchar(50),PlotID int); INSERT INTO Wildlife VALUES (1,'Deer',1),(2,'Bear',1),(3,'Rabbit',2); CREATE TABLE CarbonSequestration (PlotID int,Sequestration float); INSERT INTO CarbonSequestration VALUES (1,500),(2,600);
SELECT ForestPlots.PlotName, Wildlife.SpeciesName, CarbonSequestration.Sequestration FROM ForestPlots INNER JOIN Wildlife ON ForestPlots.PlotID = Wildlife.PlotID INNER JOIN CarbonSequestration ON ForestPlots.PlotID = CarbonSequestration.PlotID;
What is the total number of fans that attended hockey games in Canada in 2021?
CREATE TABLE hockey_stadiums (stadium_name TEXT,location TEXT,capacity INT,games_hosted INT); CREATE TABLE hockey_attendance (stadium_name TEXT,date TEXT,fans_attended INT);
SELECT SUM(a.fans_attended) FROM hockey_stadiums s JOIN hockey_attendance a ON s.stadium_name = a.stadium_name WHERE s.location = 'Canada';
Count the number of unique esports events where at least one female player participated, and the number of unique VR games played in these events.
CREATE TABLE EsportsEvents (EventID INT,EventName VARCHAR(50)); CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10)); CREATE TABLE PlayerEvent (PlayerID INT,EventID INT); CREATE TABLE Games (GameID INT,GameName VARCHAR(50),Genre VARCHAR(20)); CREATE TABLE GameEvent (GameID INT,EventID INT,GameType VARCHAR(10)); CREATE TABLE VR_Games (GameID INT,IsVR INT);
SELECT COUNT(DISTINCT EsportsEvents.EventID), COUNT(DISTINCT Games.GameID) FROM EsportsEvents INNER JOIN PlayerEvent ON EsportsEvents.EventID = PlayerEvent.EventID INNER JOIN Players ON PlayerEvent.PlayerID = Players.PlayerID INNER JOIN GameEvent ON EsportsEvents.EventID = GameEvent.EventID INNER JOIN Games ON GameEvent.GameID = Games.GameID INNER JOIN VR_Games ON Games.GameID = VR_Games.GameID WHERE Players.Gender = 'Female' AND VR_Games.IsVR = 1;
What is the total military equipment sales revenue for each equipment type?
CREATE TABLE military_equipment_sales(id INT,equipment_type VARCHAR(20),quantity INT,sale_price FLOAT);
SELECT equipment_type, SUM(quantity * sale_price) FROM military_equipment_sales GROUP BY equipment_type;
What are the total sales for abstract artworks sold in the last decade?
CREATE TABLE Artwork (ArtworkID INT,Title VARCHAR(100),Category VARCHAR(50),Price FLOAT); CREATE TABLE Sales (SaleID INT,ArtworkID INT,SaleDate DATE); INSERT INTO Sales VALUES (1,1,'2010-05-01'); INSERT INTO Sales VALUES (2,3,'2019-12-25');
SELECT SUM(A.Price) FROM Artwork A JOIN Sales S ON A.ArtworkID = S.ArtworkID WHERE A.Category = 'Abstract' AND S.SaleDate >= '2010-01-01' AND S.SaleDate <= '2019-12-31';
Delete IoT sensor metrics for sensor_id 13 before '2022-04-01 06:00:00'
CREATE TABLE iot_sensor_metrics (sensor_id INT,value INT,timestamp TIMESTAMP); INSERT INTO iot_sensor_metrics (sensor_id,value,timestamp) VALUES (13,900,'2022-04-01 05:00:00'),(13,950,'2022-04-01 07:00:00');
WITH data_to_delete AS (DELETE FROM iot_sensor_metrics WHERE sensor_id = 13 AND timestamp < '2022-04-01 06:00:00' RETURNING *) SELECT * FROM data_to_delete;
What is the minimum water temperature (in °C) for each aquaculture zone in 2024, ordered by the minimum value?
CREATE TABLE aquaculture_zones (zone_id INT,year INT,min_water_temp FLOAT); INSERT INTO aquaculture_zones (zone_id,year,min_water_temp) VALUES (1,2024,12.5),(2,2024,13.2),(3,2024,11.8),(4,2024,12.6),(5,2024,13.1);
SELECT zone_id, MIN(min_water_temp) as min_water_temp_c FROM aquaculture_zones WHERE year = 2024 GROUP BY zone_id ORDER BY min_water_temp_c;
Which investment strategies have a return on investment (ROI) greater than 5% and have at least one client utilizing them?
CREATE TABLE InvestmentStrategies (StrategyID int,StrategyName varchar(50),ROI decimal(5,2)); INSERT INTO InvestmentStrategies (StrategyID,StrategyName,ROI) VALUES (1,'Conservative',2),(2,'Moderate',3),(3,'Aggressive',5),(4,'High Risk',10); CREATE TABLE ClientStrategies (ClientID int,StrategyID int); INSERT INTO ClientStrategies (ClientID,StrategyID) VALUES (10,1),(11,1),(12,2),(13,3),(14,2),(15,4);
SELECT i.StrategyName, i.ROI FROM InvestmentStrategies i INNER JOIN ClientStrategies cs ON i.StrategyID = cs.StrategyID WHERE i.ROI > 5 GROUP BY i.StrategyName, i.ROI HAVING COUNT(cs.ClientID) > 0;
What is the mortality rate of fish per day for each species at Farm H?
CREATE TABLE aquafarms (id INT,name TEXT); INSERT INTO aquafarms (id,name) VALUES (1,'Farm A'),(2,'Farm B'),(3,'Farm C'),(8,'Farm H'); CREATE TABLE mortality_data (aquafarm_id INT,species TEXT,mortality_quantity INT,timestamp TIMESTAMP);
SELECT species, DATE(timestamp) AS date, AVG(mortality_quantity) AS avg_mortality_rate FROM mortality_data JOIN aquafarms ON mortality_data.aquafarm_id = aquafarms.id WHERE aquafarm_id = 8 GROUP BY species, date;
What is the minimum number of streams for any folk song in Austin?
CREATE TABLE Streams (song_genre VARCHAR(255),city VARCHAR(255),stream_count INT,stream_date DATE); INSERT INTO Streams (song_genre,city,stream_count,stream_date) VALUES ('folk','Austin',2000,'2022-02-01'),('rock','Seattle',1500,'2022-02-02');
SELECT MIN(stream_count) FROM Streams WHERE song_genre = 'folk' AND city = 'Austin';
How many public participation initiatives are there in the Canadian provinces?
CREATE TABLE public_participation (id INT,name VARCHAR(255),province VARCHAR(255)); INSERT INTO public_participation (id,name,province) VALUES (1,'Initiative 1','Ontario'),(2,'Initiative 2','Quebec'),(3,'Initiative 3','British Columbia');
SELECT province, COUNT(*) FROM public_participation GROUP BY province;
delete records with rating less than 7 in the tv_shows table
CREATE TABLE tv_shows(id INT PRIMARY KEY,name VARCHAR(255),rating INT);
DELETE FROM tv_shows WHERE rating < 7;
Display the policy advocacy history for programs with a focus on emotional support animals in the Northeast and the South.
CREATE TABLE Programs (program_id INT,state VARCHAR(50),focus_area VARCHAR(50),policy_advocacy_history TEXT); CREATE TABLE Regions (region VARCHAR(50),state VARCHAR(50));
SELECT * FROM Programs P INNER JOIN Regions R ON P.state = R.state WHERE R.region IN ('Northeast', 'South') AND P.focus_area = 'emotional support animals';
How many clients are from each state, for attorneys in the Family Law practice area?
CREATE TABLE Clients (ClientID INT,Name VARCHAR(50),State VARCHAR(50)); INSERT INTO Clients (ClientID,Name,State) VALUES (1,'Doe','NY'); INSERT INTO Clients (ClientID,Name,State) VALUES (2,'Roe','CA'); CREATE TABLE Assignments (AssignmentID INT,ClientID INT,AttorneyID INT,PracticeArea VARCHAR(50)); INSERT INTO Assignments (AssignmentID,ClientID,AttorneyID,PracticeArea) VALUES (1,1,1,'Family Law'); INSERT INTO Assignments (AssignmentID,ClientID,AttorneyID,PracticeArea) VALUES (2,2,1,'Family Law');
SELECT C.State, COUNT(*) AS ClientCount FROM Clients C JOIN Assignments A ON C.ClientID = A.ClientID JOIN Attorneys AT ON A.AttorneyID = AT.AttorneyID WHERE AT.PracticeArea = 'Family Law' GROUP BY C.State;
What is the name and age of the youngest person who received food assistance in Afghanistan in 2021?
CREATE TABLE FoodAssistance (id INT,person_name VARCHAR(50),person_age INT,country VARCHAR(50),assistance_date DATE); INSERT INTO FoodAssistance (id,person_name,person_age,country,assistance_date) VALUES (1,'John Doe',25,'Afghanistan','2021-05-02'); CREATE TABLE People (id INT,person_name VARCHAR(50),person_age INT); INSERT INTO People (id,person_name,person_age) VALUES (1,'John Doe',25),(2,'Jane Smith',22);
SELECT People.person_name, MIN(FoodAssistance.person_age) AS youngest_age FROM FoodAssistance JOIN People ON FoodAssistance.person_name = People.person_name WHERE FoodAssistance.country = 'Afghanistan' AND FoodAssistance.assistance_date >= '2021-01-01' AND FoodAssistance.assistance_date <= '2021-12-31' GROUP BY People.person_name;
What is the total investment in renewable energy per country?
CREATE TABLE renewable_energy_investment (investment_id INT,country_id INT,investment FLOAT); INSERT INTO renewable_energy_investment VALUES (1,1,500000),(2,1,700000),(3,2,600000),(4,3,800000);
SELECT country_id, SUM(investment) as total_investment FROM renewable_energy_investment GROUP BY country_id;
What is the minimum budget allocated for any service in Florida?
CREATE TABLE service_budget (state VARCHAR(50),service VARCHAR(50),budget INT); INSERT INTO service_budget (state,service,budget) VALUES ('Florida','Education',5000000),('Florida','Highway Maintenance',3000000);
SELECT MIN(budget) FROM service_budget WHERE state = 'Florida';
Insert a new record in the 'mining_operation_data' table for the 'Bingham Canyon' mine, 'Copper' as the mined_material, and a production_capacity of 50000 tonnes
CREATE TABLE mining_operation_data (mine_name VARCHAR(50),mined_material VARCHAR(20),production_capacity INT);
INSERT INTO mining_operation_data (mine_name, mined_material, production_capacity) VALUES ('Bingham Canyon', 'Copper', 50000);
Identify the astronaut with the longest medical checkup duration (in minutes).
CREATE TABLE astronaut_medical(id INT,name VARCHAR(20),region VARCHAR(10),checkup_duration INT); INSERT INTO astronaut_medical(id,name,region,checkup_duration) VALUES (1,'James Wong','America',45); INSERT INTO astronaut_medical(id,name,region,checkup_duration) VALUES (2,'Fatima Ahmed','Asia',50);
SELECT name FROM astronaut_medical WHERE checkup_duration = (SELECT MAX(checkup_duration) FROM astronaut_medical);
What is the total budget of rural infrastructure projects in Mexico that were started before 2010 and have not been completed yet?
CREATE TABLE mexico_projects (project_id INT,project_name VARCHAR(50),location VARCHAR(20),start_date DATE,end_date DATE,budget INT); INSERT INTO mexico_projects (project_id,project_name,location,start_date,end_date,budget) VALUES (1,'Highway Construction','rural','2005-01-01','2010-12-31',1000000),(2,'Bridge Building','urban','2015-01-01','2016-12-31',500000),(3,'Water Supply System','rural','2008-01-01',NULL,800000);
SELECT SUM(budget) FROM mexico_projects WHERE location = 'rural' AND start_date < '2010-01-01' AND end_date IS NULL;
What are the names and websites of organizations involved in conserving critically endangered marine species?
CREATE TABLE marine_species (id INT PRIMARY KEY,name VARCHAR(255),conservation_status VARCHAR(255)); CREATE TABLE conservation_efforts (id INT PRIMARY KEY,species_id INT,location VARCHAR(255),FOREIGN KEY (species_id) REFERENCES marine_species(id)); CREATE TABLE organizations (id INT PRIMARY KEY,effort_id INT,organization_name VARCHAR(255),organization_website VARCHAR(255),FOREIGN KEY (effort_id) REFERENCES conservation_efforts(id));
SELECT marine_species.name, organizations.organization_name, organizations.organization_website FROM marine_species INNER JOIN conservation_efforts ON marine_species.id = conservation_efforts.species_id INNER JOIN organizations ON conservation_efforts.id = organizations.effort_id WHERE marine_species.conservation_status = 'critically endangered';
How many trains in the 'suburban' schema have maintenance costs greater than $5000?
CREATE SCHEMA suburban; CREATE TABLE suburban.trains (id INT,maintenance_cost INT); INSERT INTO suburban.trains (id,maintenance_cost) VALUES (1,6000),(2,3000),(3,4000);
SELECT COUNT(*) FROM suburban.trains WHERE maintenance_cost > 5000;
What is the maximum number of hours volunteered in a single week by a volunteer, and who was the volunteer?
CREATE TABLE volunteer_hours (id INT,volunteer_id INT,hours DECIMAL,week INT); INSERT INTO volunteer_hours (id,volunteer_id,hours,week) VALUES (1,1,5.0,1),(2,2,10.0,1),(3,3,7.5,1),(4,1,4.0,2),(5,3,8.0,2); CREATE TABLE volunteers (id INT,name TEXT); INSERT INTO volunteers (id,name) VALUES (1,'Samir'),(2,'Sophia'),(3,'Taro');
SELECT MAX(hours) AS max_hours, volunteer_id FROM volunteer_hours GROUP BY volunteer_id; SELECT name, volunteer_id FROM volunteers WHERE volunteer_id IN (SELECT volunteer_id FROM (SELECT MAX(hours) AS max_hours, volunteer_id FROM volunteer_hours GROUP BY volunteer_id) AS subquery WHERE max_hours = (SELECT MAX(hours) FROM volunteer_hours));
How many workers in the 'textile' industry have a salary greater than the industry average?
CREATE TABLE workers (id INT,name VARCHAR(100),industry VARCHAR(50),job_role VARCHAR(50),salary FLOAT); INSERT INTO workers (id,name,industry,job_role,salary) VALUES (1,'John Doe','textile','Engineer',60000.0),(2,'Jane Smith','textile','Manager',70000.0),(3,'Mike Johnson','retail','Cashier',30000.0),(4,'Alice Davis','textile','Designer',55000.0);
SELECT COUNT(*) FROM (SELECT salary FROM workers WHERE industry = 'textile') AS subquery WHERE salary > (SELECT AVG(salary) FROM workers WHERE industry = 'textile');
What is the total budget for ethical AI initiatives in South American countries?
CREATE TABLE EthicalAI (Country TEXT,Budget FLOAT); INSERT INTO EthicalAI (Country,Budget) VALUES ('Brazil',5000000); INSERT INTO EthicalAI (Country,Budget) VALUES ('Argentina',4000000); INSERT INTO EthicalAI (Country,Budget) VALUES ('Colombia',6000000);
SELECT SUM(Budget) FROM EthicalAI WHERE Country IN ('Brazil', 'Argentina', 'Colombia');
Show the number of basketball and football games played in 2021 and 2022.
CREATE TABLE basketball_games(game_year INT,game_type TEXT); INSERT INTO basketball_games(game_year,game_type) VALUES (2021,'Basketball'),(2022,'Basketball'),(2021,'Basketball'),(2022,'Basketball'); CREATE TABLE football_games(game_year INT,game_type TEXT); INSERT INTO football_games(game_year,game_type) VALUES (2021,'Football'),(2022,'Football'),(2021,'Football'),(2022,'Football');
SELECT game_year, COUNT(*) FROM basketball_games WHERE game_year IN (2021, 2022) GROUP BY game_year UNION ALL SELECT game_year, COUNT(*) FROM football_games WHERE game_year IN (2021, 2022) GROUP BY game_year;
Find the names and regions of marine life research stations with a depth greater than 3500 meters.
CREATE TABLE marine_life_research_stations (id INT,name TEXT,region TEXT,depth FLOAT); INSERT INTO marine_life_research_stations (id,name,region,depth) VALUES (1,'Station A','Pacific',2500.5),(2,'Station B','Atlantic',3200.2),(3,'Station C','Pacific',1800.3),(4,'Station D','Indian',4000.0);
SELECT name, region FROM marine_life_research_stations WHERE depth > 3500;
Find the average CO2 emissions per tourist in 2022 for countries with more than 2 million tourists.
CREATE TABLE country_stats (id INT,country VARCHAR(50),num_tourists INT,co2_emissions INT); INSERT INTO country_stats (id,country,num_tourists,co2_emissions) VALUES (1,'France',2000000,5000000),(2,'Spain',3000000,6000000),(3,'Germany',4000000,8000000); CREATE TABLE co2_emissions_per_country (id INT,country VARCHAR(50),co2_emissions INT); INSERT INTO co2_emissions_per_country (id,country,co2_emissions) VALUES (1,'France',5000000),(2,'Spain',6000000),(3,'Germany',8000000);
SELECT AVG(co2_emissions / num_tourists) FROM country_stats JOIN co2_emissions_per_country ON country_stats.country = co2_emissions_per_country.country WHERE num_tourists > 2000000;
What is the average cost of services provided to students with visual impairments, grouped by the type of service?
CREATE TABLE service (student_id INT,service_type TEXT,cost FLOAT); INSERT INTO service (student_id,service_type,cost) VALUES (1,'Mobility Training',500),(2,'Braille Transcription',800),(3,'Assistive Technology',1200),(4,'Mobility Training',550);
SELECT service_type, AVG(cost) as avg_cost FROM service WHERE student_id IN (SELECT student_id FROM student WHERE disability = 'Visual Impairment') GROUP BY service_type;
List the total area (in square kilometers) planted for each crop type
CREATE TABLE crop (id INT,name VARCHAR(255)); INSERT INTO crop (id,name) VALUES (1,'Corn'),(2,'Soybeans'),(3,'Wheat'); CREATE TABLE fields (id INT,crop_id INT,area DECIMAL(10,2)); INSERT INTO fields (id,crop_id,area) VALUES (1,1,12.5),(2,2,15.2),(3,3,18.7);
SELECT c.name, SUM(f.area) FROM crop c JOIN fields f ON c.id = f.crop_id GROUP BY c.name;
Which satellites were launched by Chinese manufacturers before 2020?
CREATE TABLE Satellites (SatelliteID INT,Name VARCHAR(50),LaunchDate DATE,CountryOfOrigin VARCHAR(50),Manufacturer VARCHAR(50)); INSERT INTO Satellites (SatelliteID,Name,LaunchDate,CountryOfOrigin,Manufacturer) VALUES (2,'Beidou-2 G1','2009-12-31','China','China Academy of Space Technology');
SELECT SatelliteID, Name FROM Satellites WHERE Manufacturer = 'China Academy of Space Technology' AND LaunchDate < '2020-01-01';
Show veteran employment statistics for the defense industry in Q2 2022
CREATE TABLE veteran_employment (industry TEXT,quarter NUMERIC,veteran_employment NUMERIC); INSERT INTO veteran_employment (industry,quarter,veteran_employment) VALUES ('Defense',2,120000),('Aerospace',2,85000),('Technology',2,70000),('Defense',3,130000),('Aerospace',3,90000),('Technology',3,75000);
SELECT industry, veteran_employment FROM veteran_employment WHERE industry = 'Defense' AND quarter = 2;
Identify the top three chemical ingredients used in the highest quantities, along with their quantities, in the production of renewable energy devices.
CREATE TABLE Chemical_Ingredients (Device VARCHAR(255),Chemical VARCHAR(255),Quantity INT); INSERT INTO Chemical_Ingredients (Device,Chemical,Quantity) VALUES ('DeviceA','Chemical1',500),('DeviceA','Chemical2',300),('DeviceB','Chemical1',700),('DeviceB','Chemical3',600);
SELECT Chemical, SUM(Quantity) AS Total_Quantity FROM Chemical_Ingredients WHERE Device IN ('DeviceA', 'DeviceB') GROUP BY Chemical ORDER BY Total_Quantity DESC LIMIT 3;
What is the total value of defense contracts signed by company 'Alpha Corp'?
CREATE TABLE defense_contracts (contract_id INT,company VARCHAR(255),value FLOAT,date DATE); INSERT INTO defense_contracts (contract_id,company,value,date) VALUES (1,'Alpha Corp',5000000,'2020-01-01');
SELECT SUM(value) FROM defense_contracts WHERE company = 'Alpha Corp';
Which employees have the same job title as those in the 'Marketing' department but work in a different department?
CREATE TABLE Employees (Employee_ID INT,First_Name VARCHAR(50),Last_Name VARCHAR(50),Department VARCHAR(50),Job_Title VARCHAR(50)); INSERT INTO Employees (Employee_ID,First_Name,Last_Name,Department,Job_Title) VALUES (1,'John','Doe','HR','Analyst'),(2,'Jane','Smith','Marketing','Specialist'),(3,'Mike','Jameson','IT','Engineer'),(4,'Lucy','Brown','Finance','Analyst');
SELECT e1.* FROM Employees e1 INNER JOIN (SELECT Job_Title FROM Employees WHERE Department = 'Marketing') e2 ON e1.Job_Title = e2.Job_Title WHERE e1.Department != 'Marketing'
Which athletes have been involved in the most promotional events in the last year?
CREATE TABLE AthletePromotions (AthleteID INT,PromotionType VARCHAR(20),PromotionDate DATE);
SELECT AthleteID, COUNT(*) FROM AthletePromotions WHERE PromotionDate >= DATEADD(YEAR, -1, GETDATE()) GROUP BY AthleteID ORDER BY COUNT(*) DESC;
What is the average age of all astronauts from the USA?
CREATE TABLE Astronauts (AstronautID INT,Name VARCHAR(50),Age INT,Nationality VARCHAR(50)); INSERT INTO Astronauts (AstronautID,Name,Age,Nationality) VALUES (1,'John Johnson',45,'USA'),(2,'Amelia Anderson',39,'USA');
SELECT AVG(Age) FROM Astronauts WHERE Nationality = 'USA';
What is the total amount of research grants awarded to faculty members in the College of Arts and Humanities?
CREATE TABLE arts_grants (grant_id INT,grant_amount DECIMAL(10,2),grant_recipient VARCHAR(50)); INSERT INTO arts_grants (grant_id,grant_amount,grant_recipient) VALUES (1,25000.00,'Prof. Smith'),(2,30000.00,'Prof. Johnson'),(3,20000.00,'Prof. Davis');
SELECT SUM(grant_amount) FROM arts_grants WHERE grant_recipient LIKE '%College of Arts and Humanities%';
What is the maximum speed of an autonomous train in Sydney?
CREATE TABLE autonomous_trains(train_id INT,max_speed DECIMAL(5,2),city VARCHAR(50));
SELECT MAX(max_speed) FROM autonomous_trains WHERE city = 'Sydney';
Which spacecraft have had the most maintenance issues?
CREATE TABLE spacecraft (craft_name VARCHAR(50),manufacturer VARCHAR(50),first_flight DATE,total_flights INT,total_maintenance_issues INT);
SELECT craft_name, total_maintenance_issues FROM spacecraft ORDER BY total_maintenance_issues DESC LIMIT 5;
Who are the top 3 users with the highest total calories burned in the last week?
CREATE TABLE user_calories (user_id INT,calories INT,calories_date DATE); INSERT INTO user_calories (user_id,calories,calories_date) VALUES (1,500,'2022-09-01'),(2,700,'2022-09-02'),(3,600,'2022-09-03'),(4,800,'2022-09-04');
SELECT user_id, SUM(calories) as total_calories FROM user_calories WHERE calories_date >= DATEADD(week, -1, CURRENT_DATE) GROUP BY user_id ORDER BY total_calories DESC LIMIT 3;
How many products were launched per month in 2022?
CREATE TABLE Product_Launch (id INT,product_id INT,launch_date DATE); INSERT INTO Product_Launch (id,product_id,launch_date) VALUES (1,1,'2022-01-01'),(2,2,'2022-04-15'),(3,3,'2022-07-20'),(4,4,'2022-10-01');
SELECT DATE_TRUNC('month', launch_date) as month, COUNT(*) as products_launched FROM Product_Launch WHERE launch_date >= '2022-01-01' AND launch_date < '2023-01-01' GROUP BY month ORDER BY month;
Delete tournaments where the duration of the tournament is less than or equal to 4 days.
CREATE TABLE Tournaments (TournamentID INT,Game VARCHAR(50),Name VARCHAR(50),StartDate DATE,EndDate DATE); INSERT INTO Tournaments (TournamentID,Game,Name,StartDate,EndDate) VALUES (1,'GameA','TournamentA','2022-01-01','2022-01-05'); INSERT INTO Tournaments (TournamentID,Game,Name,StartDate,EndDate) VALUES (2,'GameB','TournamentB','2022-01-10','2022-01-12'); INSERT INTO Tournaments (TournamentID,Game,Name,StartDate,EndDate) VALUES (3,'GameA','TournamentC','2022-01-15','2022-01-16');
DELETE FROM Tournaments WHERE DATEDIFF(day, StartDate, EndDate) <= 4;
What is the number of volunteers from the United States?
CREATE TABLE Volunteers (id INT,name VARCHAR(255),country VARCHAR(255)); INSERT INTO Volunteers (id,name,country) VALUES (1,'Alice','United States'),(2,'Bob','Canada');
SELECT COUNT(*) FROM Volunteers WHERE country = 'United States';
Show warehouse statistics for warehouses located in the state of California.
CREATE TABLE Warehouse (warehouse_id INT,warehouse_name VARCHAR(50),state VARCHAR(50)); INSERT INTO Warehouse (warehouse_id,warehouse_name,state) VALUES (1,'W1','California'),(2,'W2','New York'),(3,'W3','California');
SELECT * FROM Warehouse WHERE state = 'California';
What is the oldest vehicle in the bus_maintanence table?
CREATE TABLE bus_maintanence (bus_id INT,bus_model VARCHAR(255),bus_year INT,last_maintenance_date DATE); INSERT INTO bus_maintanence (bus_id,bus_model,bus_year,last_maintenance_date) VALUES (1,'Bus 1',2010,'2022-02-01'),(2,'Bus 2',2015,'2022-03-01'),(3,'Bus 3',2012,'2022-01-01');
SELECT bus_model, bus_year FROM bus_maintanence ORDER BY bus_year LIMIT 1;
Who is the most prolific author in terms of article count in the "authors" table?
CREATE TABLE authors (id INT PRIMARY KEY,name TEXT,email TEXT,joined_date DATE); CREATE TABLE articles_authors (article_id INT,author_id INT);
SELECT a.name, COUNT(aa.article_id) as article_count FROM authors a JOIN articles_authors aa ON a.id = aa.author_id GROUP BY a.name ORDER BY article_count DESC LIMIT 1;
Which HealthEquityMetrics have a description with the word 'access'?
CREATE TABLE HealthEquityMetrics (MetricID INT,MetricName VARCHAR(50),Description VARCHAR(255)); INSERT INTO HealthEquityMetrics (MetricID,MetricName,Description) VALUES (1,'Mental Health Access','Access to mental health services');
SELECT MetricName, Description FROM HealthEquityMetrics WHERE Description LIKE '%access%';
What is the average salary for employees in the 'Finance' department?
CREATE TABLE Employees (id INT,name VARCHAR(50),department VARCHAR(50),salary DECIMAL(10,2),hire_date DATE); INSERT INTO Employees (id,name,department,salary,hire_date) VALUES (2,'Jane Doe','Finance',85000.00,'2019-06-15');
SELECT department, AVG(salary) FROM Employees WHERE department = 'Finance';
Which biosensor technology development startups have received funding in Brazil?
CREATE SCHEMA if not exists biotech; CREATE TABLE if not exists biotech.startups (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255),total_funding FLOAT); CREATE TABLE if not exists biotech.funding (id INT PRIMARY KEY,startup_id INT,type VARCHAR(255),amount FLOAT); INSERT INTO biotech.startups (id,name,country,total_funding) VALUES (1,'BioBrasil','Brazil',1500000); INSERT INTO biotech.funding (id,startup_id,type,amount) VALUES (1,1,'Biosensor Technology Development',1000000); INSERT INTO biotech.funding (id,startup_id,type,amount) VALUES (2,1,'Bioprocess Engineering',500000);
SELECT s.name FROM biotech.startups s JOIN biotech.funding f ON s.id = f.startup_id WHERE s.country = 'Brazil' AND f.type = 'Biosensor Technology Development';
What was the total water consumption in the 'AgriculturalWater' table in January 2022?
CREATE TABLE AgriculturalWater (ID INT,FarmID INT,WaterAmount FLOAT,ReadingDate DATE); INSERT INTO AgriculturalWater (ID,FarmID,WaterAmount,ReadingDate) VALUES (1,1,8000,'2022-01-01'); INSERT INTO AgriculturalWater (ID,FarmID,WaterAmount,ReadingDate) VALUES (2,2,6000,'2022-01-01');
SELECT SUM(WaterAmount) FROM AgriculturalWater WHERE ReadingDate BETWEEN '2022-01-01' AND '2022-01-31';
What is the number of animals of each species in protected areas, ordered by the number of animals in descending order?
CREATE TABLE AnimalProtectedAreas (Species VARCHAR(255),Area VARCHAR(255),Animals INT); INSERT INTO AnimalProtectedAreas (Species,Area,Animals) VALUES ('Giraffe','NationalPark',50),('Giraffe','Reserve',20),('Lion','NationalPark',100),('Lion','Reserve',30),('Elephant','NationalPark',25),('Elephant','Reserve',15);
SELECT Species, SUM(Animals) as TotalAnimals FROM AnimalProtectedAreas WHERE Area = 'NationalPark' GROUP BY Species ORDER BY TotalAnimals DESC;
What is the total salary cost for the first quarter of 2021?
CREATE TABLE Employees (EmployeeID INT,Name VARCHAR(50),Department VARCHAR(50),Position VARCHAR(50),Salary FLOAT,HireDate DATE); INSERT INTO Employees (EmployeeID,Name,Department,Position,Salary,HireDate) VALUES (1,'John Doe','IT','Developer',75000.00,'2021-02-14'),(2,'Jane Smith','IT','Developer',80000.00,'2021-05-11'),(3,'Alice Johnson','Marketing','Marketing Specialist',60000.00,'2021-08-01'),(4,'Bob Brown','HR','HR Specialist',65000.00,'2021-11-15');
SELECT SUM(Salary) FROM Employees WHERE HireDate >= '2021-01-01' AND HireDate < '2021-04-01';
Which soccer player has the most international goals in their career?
CREATE TABLE international_goals (player_id INT,name TEXT,country TEXT,goals INT); INSERT INTO international_goals (player_id,name,country,goals) VALUES (1,'Cristiano Ronaldo','Portugal',117),(2,'Lionel Messi','Argentina',86),(3,'Ali Daei','Iran',109),(4,'Mokhtar Dahari','Malaysia',89),(5,'Sándor Kocsis','Hungary',75);
SELECT name, goals FROM international_goals ORDER BY goals DESC LIMIT 1;
What is the most popular product category?
CREATE TABLE Products (ProductID int,Category varchar(255));
SELECT Category, COUNT(*) AS ProductCount FROM Products GROUP BY Category ORDER BY ProductCount DESC;
What is the total CO2 emission for flights between Australia and Asian countries?
CREATE TABLE flights (id INT,origin TEXT,destination TEXT,co2_emission INT); INSERT INTO flights (id,origin,destination,co2_emission) VALUES (1,'Australia','Japan',200),(2,'Australia','China',250),(3,'Indonesia','Australia',180);
SELECT SUM(f.co2_emission) as total_emission FROM flights f WHERE (f.origin = 'Australia' AND f.destination LIKE 'Asia%') OR (f.destination = 'Australia' AND f.origin LIKE 'Asia%');
What is the total number of marine species affected by ocean acidification in the Caribbean region?
CREATE TABLE marine_species (species_name TEXT,region TEXT); INSERT INTO marine_species (species_name,region) VALUES ('Elkhorn Coral','Caribbean'),('Staghorn Coral','Caribbean'),('Brain Coral','Caribbean');
SELECT COUNT(*) FROM marine_species WHERE region = 'Caribbean';
How many crimes were committed in each district in 2021?
CREATE TABLE district_crimes (cid INT,did INT,year INT,PRIMARY KEY(cid),FOREIGN KEY(did) REFERENCES districts(did));
SELECT d.name, COUNT(dc.cid) FROM district_crimes dc JOIN districts d ON dc.did = d.did WHERE dc.year = 2021 GROUP BY d.did;
What is the total number of workplace safety violations recorded for each union in Texas?
CREATE TABLE unions (id INT,name VARCHAR(255),state VARCHAR(255)); CREATE TABLE safety_violations (id INT,union_id INT,violation_count INT); INSERT INTO unions (id,name,state) VALUES (1,'AFSCME','Texas'); INSERT INTO safety_violations (id,union_id,violation_count) VALUES (1,1,75);
SELECT u.name, SUM(sv.violation_count) as total_violations FROM unions u JOIN safety_violations sv ON u.id = sv.union_id WHERE u.state = 'Texas' GROUP BY u.name;
Teachers with more than 5 years of experience but no professional development
CREATE TABLE teachers (id INT,name VARCHAR(50),professional_development_hours INT,years_of_experience INT); INSERT INTO teachers (id,name,professional_development_hours,years_of_experience) VALUES (1,'Jane Doe',0,6);
SELECT name FROM teachers WHERE years_of_experience > 5 AND professional_development_hours = 0;
What are the names of clinical trials conducted in 'CountryD'?
CREATE TABLE clinical_trials (trial_name TEXT,country TEXT); INSERT INTO clinical_trials (trial_name,country) VALUES ('Trial1','CountryA'),('Trial2','CountryD'),('Trial3','CountryB');
SELECT DISTINCT trial_name FROM clinical_trials WHERE country = 'CountryD';
Update the rating of all sustainable food suppliers in the Asia region to 1 point lower.
CREATE TABLE Suppliers (id INT,name TEXT,region TEXT,rating INT); INSERT INTO Suppliers (id,name,region,rating) VALUES (1,'Supplier A','EU',5),(2,'Supplier B','EU',4),(3,'Supplier C','EU',3),(4,'Supplier D','Asia',4),(5,'Supplier E','Asia',5);
UPDATE Suppliers SET Suppliers.rating = Suppliers.rating - 1 WHERE Suppliers.region = 'Asia';
What is the average rating for songs released in the last 60 days?
CREATE TABLE SongRatings (rating_id INT,rating_date DATE,song_id INT,user_id INT,rating DECIMAL(3,2)); INSERT INTO SongRatings (rating_id,rating_date,song_id,user_id,rating) VALUES (1,'2022-07-01',1,1,4.5),(2,'2022-07-05',2,2,3.5),(3,'2022-06-30',3,3,5.0),(4,'2022-08-01',4,4,4.0),(5,'2022-08-02',5,5,4.5);
SELECT AVG(rating) as average_rating FROM SongRatings WHERE rating_date >= CURDATE() - INTERVAL 60 DAY;
List all the postal codes and corresponding cities in the country of Australia where the average income is above 70000.
CREATE TABLE postal_codes (postal_code INTEGER,city TEXT,average_income INTEGER); INSERT INTO postal_codes (postal_code,city,average_income) VALUES (1234,'City 1',80000),(6789,'City 2',65000),(1112,'City 3',90000),(2223,'City 4',75000);
SELECT postal_code, city FROM postal_codes WHERE average_income > 70000 AND country = 'AU';
What is the name of the country with the largest area?
CREATE TABLE countries (name VARCHAR(50),area FLOAT); INSERT INTO countries (name,area) VALUES ('Russia',17098242),('Canada',9984670),('China',9596961),('United States',9147420),('Brazil',8514877),('Australia',7686850),('India',3287263),('Argentina',2780400);
SELECT name FROM (SELECT name FROM countries WHERE area = (SELECT MAX(area) FROM countries));
Find the total number of art programs, music programs, and dance programs combined, along with the total number of attendees for these programs, in the city of Los Angeles and state of California?
CREATE TABLE ArtPrograms (city VARCHAR(50),state VARCHAR(50),program VARCHAR(50),attendees INT); INSERT INTO ArtPrograms (city,state,program,attendees) VALUES ('Los Angeles','California','Art',120),('Los Angeles','California','Music',150),('Los Angeles','California','Dance',180);
SELECT SUM(attendees) FROM ArtPrograms WHERE program IN ('Art', 'Music', 'Dance') AND city = 'Los Angeles' AND state = 'California';
What is the total waste produced by the 'plastic' division in the last quarter?
CREATE TABLE waste (division TEXT,date DATE,quantity INT); INSERT INTO waste (division,date,quantity) VALUES ('plastic','2022-01-01',500),('plastic','2022-04-01',600);
SELECT SUM(quantity) FROM waste WHERE division = 'plastic' AND date >= '2022-01-01' AND date < '2022-04-01';
How many electric vehicle charging stations are there in Tokyo, Japan as of 2020?
CREATE TABLE charging_stations (city VARCHAR(30),country VARCHAR(30),num_stations INT,year INT); INSERT INTO charging_stations VALUES ('Tokyo','Japan',5000,2020);
SELECT num_stations FROM charging_stations WHERE city = 'Tokyo' AND country = 'Japan' AND year = 2020;
List all union members who are involved in collective bargaining in the 'manufacturing' sector, along with their respective union names.
CREATE TABLE union_members (id INT,union_name VARCHAR(30),sector VARCHAR(20)); INSERT INTO union_members (id,union_name,sector) VALUES (1,'Union A','manufacturing'),(2,'Union B','education'),(3,'Union C','manufacturing'); CREATE TABLE collective_bargaining (id INT,union_id INT,member_id INT); INSERT INTO collective_bargaining (id,union_id,member_id) VALUES (1,1,101),(2,3,102);
SELECT u.union_name, um.id, um.sector FROM union_members um JOIN unions u ON um.sector = u.sector WHERE um.id IN (SELECT member_id FROM collective_bargaining WHERE union_id = u.id AND sector = 'manufacturing');
What are the water temperatures for fish farms in the South China sea?
CREATE TABLE south_china_sea_fish_farms (id INT,name VARCHAR(50),country VARCHAR(50),water_temperature FLOAT); INSERT INTO south_china_sea_fish_farms (id,name,country,water_temperature) VALUES (1,'Farm O','China',29.6),(2,'Farm P','Vietnam',28.9),(3,'Farm Q','Malaysia',28.2),(4,'Farm R','Philippines',27.8);
SELECT country, water_temperature FROM south_china_sea_fish_farms;
What is the average defense diplomacy spending by the top 3 countries in defense diplomacy?
CREATE TABLE DefenseDiplomacySpending (Country VARCHAR(50),Spending DECIMAL(10,2)); INSERT INTO DefenseDiplomacySpending (Country,Spending) VALUES ('United States',1200000),('United Kingdom',500000),('France',400000),('Canada',300000),('Germany',250000);
SELECT AVG(Spending) AS AvgSpending FROM (SELECT Spending FROM DefenseDiplomacySpending ORDER BY Spending DESC LIMIT 3) AS Top3Spenders;
What is the average satisfaction rating for patients who have completed the mindfulness-based stress reduction program?
CREATE TABLE mindfulness_program (id INT PRIMARY KEY,patient_id INT,completion_status VARCHAR(50),FOREIGN KEY (patient_id) REFERENCES patients(id)); INSERT INTO mindfulness_program (id,patient_id,completion_status) VALUES (1,1,'Completed');
SELECT AVG(patient_satisfaction.rating) FROM patient_satisfaction INNER JOIN mindfulness_program ON patient_satisfaction.patient_id = mindfulness_program.patient_id WHERE mindfulness_program.completion_status = 'Completed';
Show the total number of workouts and unique members who participated in yoga classes, broken down by month and year.
CREATE TABLE workouts (id INT,member_id INT,workout_type VARCHAR(20),workout_date DATE);
SELECT YEAR(workout_date) as year, MONTH(workout_date) as month, COUNT(DISTINCT member_id) as total_members, COUNT(*) as total_workouts FROM workouts WHERE workout_type = 'yoga' GROUP BY year, month;
Who are the top 2 authors with the most media ethics violations in 'Asia'?
CREATE TABLE authors (id INT,name TEXT,region TEXT); INSERT INTO authors VALUES (1,'John Smith','Asia'); INSERT INTO authors VALUES (2,'Jane Doe','Europe'); CREATE TABLE violations (id INT,author_id INT,location TEXT); INSERT INTO violations VALUES (1,1,'Asia'); INSERT INTO violations VALUES (2,1,'Europe');
SELECT authors.name FROM authors INNER JOIN violations ON authors.id = violations.author_id WHERE authors.region = 'Asia' GROUP BY authors.name ORDER BY COUNT(violations.id) DESC LIMIT 2;
What is the average CO2 emission of buildings in the 'GreenBuildings' table, grouped by city?
CREATE TABLE GreenBuildings (id INT,city VARCHAR(50),co2_emissions FLOAT); INSERT INTO GreenBuildings (id,city,co2_emissions) VALUES (1,'NYC',500.0),(2,'LA',600.0),(3,'NYC',450.0);
SELECT city, AVG(co2_emissions) FROM GreenBuildings GROUP BY city;
What is the minimum number of members in unions not involved in collective bargaining in California?
CREATE TABLE union_bargaining_ca (id INT,union_name TEXT,state TEXT,involved_in_bargaining BOOLEAN,members INT); INSERT INTO union_bargaining_ca (id,union_name,state,involved_in_bargaining,members) VALUES (1,'Union G','California',true,700),(2,'Union H','California',false,300),(3,'Union I','California',true,600);
SELECT MIN(members) FROM union_bargaining_ca WHERE state = 'California' AND involved_in_bargaining = false;
What is the total number of bike-sharing trips in London and the total distance covered?
CREATE TABLE bike_sharing (trip_id INT,distance FLOAT,city VARCHAR(50));
SELECT COUNT(trip_id), SUM(distance) FROM bike_sharing WHERE city = 'London';
How many visitors identified as 'Children' attended family workshops?
CREATE TABLE attendees (id INT,event_id INT,age_group VARCHAR(255)); INSERT INTO attendees (id,event_id,age_group) VALUES (1,101,'Children'),(2,101,'Children'),(3,101,'Teenagers'),(4,102,'Adults'),(5,102,'Adults'),(6,103,'Children'); CREATE TABLE events (id INT,name VARCHAR(255),type VARCHAR(255)); INSERT INTO events (id,name,type) VALUES (101,'Family Workshop A','Workshop'),(102,'Lecture Series 1','Lecture'),(103,'Family Workshop B','Workshop');
SELECT COUNT(*) FROM attendees WHERE age_group = 'Children' AND event_id IN (SELECT id FROM events WHERE type = 'Workshop');
What is the average age of female patients diagnosed with diabetes in rural Texas?
CREATE TABLE patients (id INT,name VARCHAR(50),age INT,gender VARCHAR(10),state VARCHAR(50)); INSERT INTO patients (id,name,age,gender,state) VALUES (1,'Jane Doe',65,'Female','Texas'); INSERT INTO patients (id,name,age,gender,state) VALUES (2,'John Doe',50,'Male','Texas'); CREATE TABLE diagnoses (id INT,patient_id INT,diagnosis VARCHAR(50),diagnosis_date DATE); INSERT INTO diagnoses (id,patient_id,diagnosis,diagnosis_date) VALUES (1,1,'Diabetes','2020-01-01'); INSERT INTO diagnoses (id,patient_id,diagnosis,diagnosis_date) VALUES (2,2,'Flu','2020-02-01');
SELECT AVG(age) FROM patients JOIN diagnoses ON patients.id = diagnoses.patient_id WHERE diagnoses.diagnosis = 'Diabetes' AND patients.gender = 'Female' AND patients.state = 'Texas';
Add a new author to the authors table from Brazil
CREATE TABLE authors (id INT,name VARCHAR(50),country VARCHAR(50));
INSERT INTO authors (id, name, country) VALUES (106, 'Maria Souza', 'Brazil');
What is the average donation amount in Canada?
CREATE TABLE Donations (id INT,user_id INT,country VARCHAR(50),amount DECIMAL(10,2),donation_date DATE); INSERT INTO Donations (id,user_id,country,amount,donation_date) VALUES (1,101,'United States',50.00,'2022-01-02'); INSERT INTO Donations (id,user_id,country,amount,donation_date) VALUES (2,102,'Canada',75.00,'2022-01-05');
SELECT AVG(amount) FROM Donations WHERE country = 'Canada';
Which wells in the Beaufort Sea have a production greater than 5000?
CREATE TABLE wells (well_id INT,name VARCHAR(50),location VARCHAR(50),production FLOAT); INSERT INTO wells (well_id,name,location,production) VALUES (1,'E1','Beaufort Sea',6000),(2,'E2','Beaufort Sea',5000),(3,'E3','Beaufort Sea',7000);
SELECT name, production FROM wells WHERE location = 'Beaufort Sea' AND production > 5000;
How many pollution control initiatives were conducted in the Indian Ocean by organization OceanCare?
CREATE TABLE pollution_control_initiatives (id INT,organization TEXT,location TEXT,year INT); INSERT INTO pollution_control_initiatives (id,organization,location,year) VALUES (1,'OceanCare','Indian Ocean',2020); INSERT INTO pollution_control_initiatives (id,organization,location,year) VALUES (2,'Coastal Watch','Caribbean Sea',2019);
SELECT COUNT(*) FROM pollution_control_initiatives WHERE organization = 'OceanCare' AND location = 'Indian Ocean';
How many articles were written in each language?
CREATE TABLE articles (id INT,title TEXT,language TEXT); INSERT INTO articles (id,title,language) VALUES (1,'Article1','Spanish'),(2,'Article2','English'),(3,'Article3','Spanish'),(4,'Article4','French');
SELECT language, COUNT(*) as article_count FROM articles GROUP BY language;
How many hotels in ANZ adopted AI before 2020?
CREATE TABLE ai_adoption_timeline (hotel_id INT,hotel_name VARCHAR(255),adoption_year INT);
SELECT COUNT(DISTINCT hotel_id) FROM ai_adoption_timeline WHERE region = 'ANZ' AND adoption_year < 2020;
What is the average timber production, in cubic meters, for temperate coniferous forests in Canada between 2015 and 2020?
CREATE TABLE timber_production (forest_type VARCHAR(30),year INT,volume FLOAT); INSERT INTO timber_production (forest_type,year,volume) VALUES ('Temperate Coniferous Forest - Canada',2015,1234.5),('Temperate Coniferous Forest - Canada',2016,7890.1),('Temperate Coniferous Forest - Canada',2017,4560.2),('Temperate Coniferous Forest - Canada',2018,3456.7),('Temperate Coniferous Forest - Canada',2019,5678.9),('Temperate Coniferous Forest - Canada',2020,8901.2);
SELECT AVG(volume) FROM timber_production WHERE forest_type = 'Temperate Coniferous Forest - Canada' AND year BETWEEN 2015 AND 2020;
Compare circular economy initiatives in the industrial sector between 2018 and 2020.
CREATE TABLE circular_economy (year INT,sector VARCHAR(20),initiatives INT); INSERT INTO circular_economy (year,sector,initiatives) VALUES (2018,'industrial',120),(2020,'industrial',150);
SELECT * FROM circular_economy WHERE sector = 'industrial' AND year IN (2018, 2020);