instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the average number of missions per astronaut for each country?
CREATE TABLE AstronautMissions (country TEXT,astronaut TEXT,num_missions INTEGER); INSERT INTO AstronautMissions (country,astronaut,num_missions) VALUES ('USA','John Glenn',2),('USA','Neil Armstrong',2),('USA','Mae Jemison',1),('Russia','Yuri Gagarin',1),('China','Yang Liwei',1),('India','Rakesh Sharma',1);
SELECT country, AVG(num_missions) FROM AstronautMissions GROUP BY country;
List the routes with the longest average distance for shipments in August 2021
CREATE TABLE Routes (id INT,route VARCHAR(50),distance INT,timestamp DATE); INSERT INTO Routes (id,route,distance,timestamp) VALUES (1,'LA-NY',2500,'2021-08-01'),(2,'NY-LA',2500,'2021-08-02'),(3,'Chicago-Houston',1500,'2021-08-03'),(4,'Houston-Chicago',1500,'2021-08-04'),(5,'Seattle-Miami',3500,'2021-08-05');
SELECT route, AVG(distance) FROM Routes WHERE timestamp BETWEEN '2021-08-01' AND '2021-08-31' GROUP BY route ORDER BY AVG(distance) DESC LIMIT 3;
Who are the inventors of patents filed in 'Germany' and when were the patents filed?
CREATE TABLE ai_patents (id INT PRIMARY KEY,patent_name VARCHAR(50),inventor VARCHAR(50),filing_date DATE,country VARCHAR(50)); INSERT INTO ai_patents (id,patent_name,inventor,filing_date,country) VALUES (1,'Neural Network Patent','Charlie','2022-01-01','USA'),(2,'Reinforcement Learning Patent','Diana','2023-02-15','Canada'),(3,'Explainable AI Patent','Eli','2022-07-01','Germany');
SELECT inventor, filing_date FROM ai_patents WHERE country = 'Germany';
Delete all records related to climate communication projects in Sub-Saharan Africa from the climate_projects table.
CREATE TABLE climate_projects (id INT,project_name VARCHAR(20),project_location VARCHAR(20),project_type VARCHAR(20)); INSERT INTO climate_projects (id,project_name,project_location,project_type) VALUES (1,'Communication Project 1','Sub-Saharan Africa','Climate Communication'),(2,'Mitigation Project 1','Asia','Climate Mitigation'),(3,'Communication Project 2','Sub-Saharan Africa','Climate Communication');
DELETE FROM climate_projects WHERE project_location = 'Sub-Saharan Africa' AND project_type = 'Climate Communication';
What is the total number of flu vaccinations administered in rural areas?
CREATE TABLE flu_vaccinations (patient_id INT,location VARCHAR(20)); INSERT INTO flu_vaccinations (patient_id,location) VALUES (1,'Rural'); INSERT INTO flu_vaccinations (patient_id,location) VALUES (2,'Urban');
SELECT COUNT(*) FROM flu_vaccinations WHERE location = 'Rural';
How many unique users posted content in each month?
CREATE TABLE posts (id INT,user_id INT,post_date DATE); INSERT INTO posts (id,user_id,post_date) VALUES (1,1,'2022-01-01'),(2,2,'2022-01-02'),(3,3,'2022-02-01'),(4,4,'2022-03-01');
SELECT MONTH(post_date), COUNT(DISTINCT user_id) FROM posts GROUP BY MONTH(post_date);
List artworks by artists from India or Spain, excluding those created before 1900.
CREATE TABLE Artists (ArtistID INT PRIMARY KEY,Name VARCHAR(100),Nationality VARCHAR(50)); INSERT INTO Artists (ArtistID,Name,Nationality) VALUES (1,'Francisco Goya','Spanish'); INSERT INTO Artists (ArtistID,Name,Nationality) VALUES (2,'M.F. Husain','Indian'); CREATE TABLE ArtWorks (ArtWorkID INT PRIMARY KEY,Title VARCHAR(100),YearCreated INT,ArtistID INT,FOREIGN KEY (ArtistID) REFERENCES Artists(ArtistID)); INSERT INTO ArtWorks (ArtWorkID,Title,YearCreated,ArtistID) VALUES (1,'Saturn Devouring His Son',1823,1); INSERT INTO ArtWorks (ArtWorkID,Title,YearCreated,ArtistID) VALUES (2,'Horses and Tiger',1960,2);
SELECT ArtWorks.Title FROM ArtWorks INNER JOIN Artists ON ArtWorks.ArtistID = Artists.ArtistID WHERE Artists.Nationality IN ('Indian', 'Spanish') AND ArtWorks.YearCreated > 1900;
How many cases were opened in Q2 2022 for clients in Ontario, Canada?
CREATE TABLE clients (client_id INT,state TEXT,country TEXT); INSERT INTO clients (client_id,state,country) VALUES (1,'Toronto','Canada'),(2,'Miami','USA'),(3,'Vancouver','Canada'); CREATE TABLE cases (case_id INT,client_id INT,opened_date DATE); INSERT INTO cases (case_id,client_id,opened_date) VALUES (1,1,'2022-04-01'),(2,1,'2022-06-15'),(3,2,'2021-12-31');
SELECT COUNT(*) FROM cases WHERE client_id IN (SELECT client_id FROM clients WHERE country = 'Canada' AND state = 'Toronto') AND opened_date >= '2022-04-01' AND opened_date < '2022-07-01'
Find the top 3 players with the highest number of kills in 'Call of Duty' matches in the last month.
CREATE TABLE matches (id INT,game VARCHAR(10),player VARCHAR(50),kills INT,deaths INT,match_date DATE); INSERT INTO matches (id,game,player,kills,deaths,match_date) VALUES (1,'Call of Duty','John',30,10,'2022-06-15');
SELECT player, SUM(kills) AS total_kills FROM (SELECT player, kills, ROW_NUMBER() OVER (PARTITION BY player ORDER BY kills DESC, match_date DESC) rn FROM matches WHERE game = 'Call of Duty' AND match_date >= DATEADD(month, -1, GETDATE())) sub WHERE rn <= 3 GROUP BY player;
Find the total number of cargo handling equipment across all ports.
CREATE TABLE ports (id INT,name VARCHAR(50)); CREATE TABLE cargo_equipment (id INT,port_id INT,type VARCHAR(50),quantity INT);
SELECT SUM(quantity) FROM cargo_equipment;
What is the regulatory rating for 'App5' in the 'Social Networking' category?
CREATE TABLE dapps (id INT,name TEXT,category TEXT,rating INT); INSERT INTO dapps (id,name,category,rating) VALUES (11,'App5','Social Networking',80);
SELECT rating FROM dapps WHERE name = 'App5';
Show the total construction hours worked in 'Mumbai' for the month of 'January' in 2020 and 2021.
CREATE TABLE construction_hours (worker_id INT,city VARCHAR(20),hours_worked INT,work_date DATE); INSERT INTO construction_hours (worker_id,city,hours_worked,work_date) VALUES (1,'Mumbai',8,'2020-01-01'); INSERT INTO construction_hours (worker_id,city,hours_worked,work_date) VALUES (2,'Mumbai',10,'2021-01-03');
SELECT SUM(hours_worked) FROM construction_hours WHERE city = 'Mumbai' AND EXTRACT(MONTH FROM work_date) = 1 AND (EXTRACT(YEAR FROM work_date) = 2020 OR EXTRACT(YEAR FROM work_date) = 2021);
What are the artifact types and their quantities from site X?
CREATE TABLE excavation_sites (id INT,name VARCHAR(255)); INSERT INTO excavation_sites (id,name) VALUES (1,'Site X');
SELECT artifact_type, COUNT(*) FROM artifacts JOIN excavation_sites ON artifacts.excavation_site_id = excavation_sites.id
How many legal technology patents were granted to women-led teams in the past 5 years?
CREATE TABLE legal_technology_patents (patent_id INT,year INT,gender VARCHAR(10)); INSERT INTO legal_technology_patents (patent_id,year,gender) VALUES (1,2020,'Female'),(2,2019,'Male'),(3,2018,'Female'),(4,2017,'Female'),(5,2016,'Male');
SELECT COUNT(*) FROM legal_technology_patents WHERE gender = 'Female' AND year >= 2016;
What is the maximum number of visitors at a cultural event in Tokyo?
CREATE TABLE Cultural_Events (id INT,city VARCHAR(50),attendance INT); CREATE VIEW Tokyo_Events AS SELECT * FROM Cultural_Events WHERE city = 'Tokyo';
SELECT MAX(attendance) FROM Tokyo_Events;
What is the minimum mental health score for students in the 'in_person' program?
CREATE TABLE student_mental_health (student_id INT,program VARCHAR(20),score INT); INSERT INTO student_mental_health (student_id,program,score) VALUES (1,'remote_learning',75),(2,'remote_learning',80),(3,'in_person',85),(4,'in_person',90);
SELECT MIN(score) FROM student_mental_health WHERE program = 'in_person';
Which soccer players in the 'epl_players' table are from England?
CREATE TABLE epl_players (player_id INT,player_name VARCHAR(50),nationality VARCHAR(50),team_name VARCHAR(50));
SELECT player_name FROM epl_players WHERE nationality = 'England';
Create a table named 'otas' to store data about online travel agencies
CREATE TABLE otas (ota_id INT,ota_name VARCHAR(25),region VARCHAR(20));
CREATE TABLE otas (ota_id INT, ota_name VARCHAR(25), region VARCHAR(20));
What is the total waste generation and recycling rate for each continent in the year 2022?
CREATE TABLE WasteGenerationByContinent (continent VARCHAR(255),year INT,waste_quantity INT); INSERT INTO WasteGenerationByContinent (continent,year,waste_quantity) VALUES ('Asia',2022,1500000),('Africa',2022,1200000),('Europe',2022,1800000); CREATE TABLE RecyclingRatesByContinent (continent VARCHAR(255),year INT,recycling_rate DECIMAL(5,2)); INSERT INTO RecyclingRatesByContinent (continent,year,recycling_rate) VALUES ('Asia',2022,0.45),('Africa',2022,0.55),('Europe',2022,0.65);
SELECT wg.continent, wg.year, wg.waste_quantity, rr.recycling_rate FROM WasteGenerationByContinent wg INNER JOIN RecyclingRatesByContinent rr ON wg.continent = rr.continent WHERE wg.year = 2022;
What is the average production cost of garments in the 'organic_cotton' material?
CREATE TABLE ProductionCosts (id INT,garment_id INT,material VARCHAR(20),cost DECIMAL(5,2));CREATE TABLE Garments (id INT,name VARCHAR(50)); INSERT INTO ProductionCosts (id,garment_id,material,cost) VALUES (1,1001,'organic_cotton',25.99),(2,1002,'organic_cotton',22.49),(3,1003,'recycled_polyester',18.99); INSERT INTO Garments (id,name) VALUES (1001,'Eco T-Shirt'),(1002,'Green Sweater'),(1003,'Circular Hoodie');
SELECT AVG(cost) FROM ProductionCosts JOIN Garments ON ProductionCosts.garment_id = Garments.id WHERE material = 'organic_cotton';
How many units of each product were sold in the top 10 best-selling days?
CREATE TABLE sales (sale_id INT,product_id INT,sale_date DATE,units_sold INT); INSERT INTO sales (sale_id,product_id,sale_date,units_sold) VALUES (1,1,'2022-01-01',200),(2,2,'2022-01-02',150),(3,3,'2022-01-03',250),(4,1,'2022-01-04',300),(5,2,'2022-01-05',120),(6,3,'2022-01-06',270),(7,1,'2022-01-07',280),(8,2,'2022-01-08',180),(9,3,'2022-01-09',300),(10,1,'2022-01-10',350);
SELECT product_id, SUM(units_sold) AS total_units_sold FROM (SELECT product_id, sale_date, units_sold, ROW_NUMBER() OVER (ORDER BY units_sold DESC) AS sale_rank FROM sales) AS top_sales WHERE sale_rank <= 10 GROUP BY product_id;
Find the number of public hospitals in the United Kingdom and Ireland.
CREATE SCHEMA uk_ireland_schema;CREATE TABLE uk_ireland_schema.hospitals (country VARCHAR(20),hospital_type VARCHAR(20),num_hospitals INT);INSERT INTO uk_ireland_schema.hospitals (country,hospital_type,num_hospitals) VALUES ('United Kingdom','Public Hospitals',6000),('Ireland','Public Hospitals',1000);
SELECT country, num_hospitals FROM uk_ireland_schema.hospitals WHERE (country = 'United Kingdom' OR country = 'Ireland') AND hospital_type = 'Public Hospitals';
Display the minimum billing amount for cases in the 'Personal Injury' category
CREATE TABLE cases (case_id INT,category VARCHAR(50),billing_amount INT); INSERT INTO cases (case_id,category,billing_amount) VALUES (1,'Personal Injury',5000),(2,'Civil Litigation',7000);
SELECT MIN(billing_amount) FROM cases WHERE category = 'Personal Injury';
What is the average attendance at events organized by cultural organizations in Paris?
CREATE TABLE cultural_orgs (id INT,name VARCHAR(255),city VARCHAR(255)); INSERT INTO cultural_orgs (id,name,city) VALUES (1,'Louvre Museum','Paris'),(2,'Pompidou Centre','Paris'),(3,'Versailles Palace','Paris'); CREATE TABLE events (id INT,org_id INT,attendees INT); INSERT INTO events (id,org_id,attendees) VALUES (1,1,15000),(2,1,12000),(3,2,8000),(4,3,7000),(5,3,6000);
SELECT AVG(e.attendees) FROM events e JOIN cultural_orgs o ON e.org_id = o.id WHERE o.city = 'Paris';
What is the recycling rate for Eastern Europe?
CREATE TABLE recycling_rates (country VARCHAR(255),recycling_rate FLOAT); INSERT INTO recycling_rates (country,recycling_rate) VALUES ('Poland',0.42),('Czech Republic',0.38),('Romania',0.20);
SELECT AVG(recycling_rate) FROM recycling_rates WHERE country IN ('Poland', 'Czech Republic', 'Romania');
How many financial capability programs were offered to female clients in Q3 2021?
CREATE TABLE financial_capability_programs (id INT,program_name VARCHAR(255),client_gender VARCHAR(10),date DATE);
SELECT COUNT(*) FROM financial_capability_programs WHERE client_gender = 'female' AND date BETWEEN '2021-07-01' AND '2021-09-30';
What is the total number of fraudulent transactions in the past month?
CREATE TABLE transactions (id INT,customer_id INT,amount DECIMAL(10,2),is_fraudulent BOOLEAN); INSERT INTO transactions (id,customer_id,amount,is_fraudulent) VALUES (1,1,100.00,true),(2,2,200.00,false),(3,3,300.00,false);
SELECT COUNT(*) FROM transactions WHERE is_fraudulent = true AND transaction_date >= CURRENT_DATE - INTERVAL '1 month';
What are the total R&D expenditures for all drugs approved in 'Year2'?
CREATE TABLE r_d_expenditure (drug_name TEXT,expenditure INTEGER,approval_year TEXT); INSERT INTO r_d_expenditure (drug_name,expenditure,approval_year) VALUES ('Drug1',3000,'Year1'),('Drug2',4000,'Year2'),('Drug3',5000,'Year2'),('Drug4',6000,'Year3');
SELECT SUM(expenditure) FROM r_d_expenditure WHERE approval_year = 'Year2';
Find the top 3 fashion brands with the highest revenue in the women's clothing category.
CREATE TABLE Revenue (brand TEXT,category TEXT,revenue FLOAT); INSERT INTO Revenue (brand,category,revenue) VALUES ('BrandA','Women''s Clothing',50000),('BrandB','Men''s Clothing',35000),('BrandC','Women''s Clothing',60000),('BrandD','Women''s Clothing',45000);
SELECT brand, SUM(revenue) as total_revenue FROM Revenue WHERE category = 'Women''s Clothing' GROUP BY brand ORDER BY total_revenue DESC LIMIT 3;
What is the total number of security incidents in the 'finance' sector?
CREATE TABLE security_incidents (id INT,sector VARCHAR(255)); INSERT INTO security_incidents (id,sector) VALUES (1,'finance'),(2,'retail');
SELECT COUNT(*) FROM security_incidents WHERE sector = 'finance';
What is the number of circular economy initiatives by city in Canada in 2019?
CREATE TABLE circular_economy (city VARCHAR(20),year INT,initiatives INT); INSERT INTO circular_economy (city,year,initiatives) VALUES ('Toronto',2019,5),('Montreal',2019,4),('Vancouver',2019,6),('Calgary',2019,3),('Ottawa',2019,5);
SELECT city, SUM(initiatives) as total_initiatives FROM circular_economy WHERE year = 2019 GROUP BY city;
Who are the top 2 technology providers for social good in Africa?
CREATE TABLE social_good_providers (provider VARCHAR(20),region VARCHAR(20),impact FLOAT); INSERT INTO social_good_providers (provider,region,impact) VALUES ('Tech for Good Africa','Africa',7.50),('Ashoka Africa','Africa',8.20),('Social Tech Trust Africa','Africa',8.00);
SELECT provider FROM social_good_providers WHERE region = 'Africa' ORDER BY impact DESC LIMIT 2;
How many students with visual impairments have utilized screen readers as accommodations in the past year?
CREATE TABLE accommodations (id INT,student_id INT,type TEXT,date DATE); INSERT INTO accommodations (id,student_id,type,date) VALUES (1,4,'screen reader','2022-04-01'); INSERT INTO accommodations (id,student_id,type,date) VALUES (2,5,'note taker','2022-05-01');
SELECT COUNT(DISTINCT student_id) FROM accommodations WHERE type = 'screen reader' AND date >= DATE_SUB(NOW(), INTERVAL 1 YEAR) AND EXISTS (SELECT * FROM students WHERE students.id = accommodations.student_id AND students.disability = 'visual impairment');
Display community engagement events and heritage sites in each country.
CREATE TABLE CountryInfo (Country VARCHAR(20),HeritageSites INT,CommunityEvents INT); INSERT INTO CountryInfo VALUES ('Brazil',5,3),('Argentina',2,1); CREATE TABLE HeritageSites (Country VARCHAR(20),SiteName VARCHAR(30)); INSERT INTO HeritageSites VALUES ('Brazil','Iguazu Falls'),('Argentina','Perito Moreno Glacier'); CREATE TABLE CommunityEngagement (Country VARCHAR(20),EventName VARCHAR(30)); INSERT INTO CommunityEngagement VALUES ('Brazil','Carnival'),('Argentina','Tango Festival');
SELECT i.Country, h.SiteName, e.EventName FROM CountryInfo i JOIN HeritageSites h ON i.Country = h.Country JOIN CommunityEngagement e ON i.Country = e.Country;
What is the average transaction value for social impact investments in specific countries and ESG categories?
CREATE TABLE social_impact_investments (id INT,country VARCHAR(50),category VARCHAR(50),transaction_value FLOAT); INSERT INTO social_impact_investments (id,country,category,transaction_value) VALUES (1,'United States','ESG1',5000.0),(2,'Canada','ESG2',7000.0),(3,'United Kingdom','ESG1',10000.0),(4,'Germany','ESG3',3000.0); CREATE TABLE esg_categories (id INT,category VARCHAR(50)); INSERT INTO esg_categories (id,category) VALUES (1,'ESG1'),(2,'ESG2'),(3,'ESG3');
SELECT AVG(transaction_value) FROM social_impact_investments WHERE country IN ('United States', 'Canada') AND category IN ('ESG1', 'ESG2')
What is the total quantity of items shipped from Hong Kong to the USA?
CREATE TABLE Warehouse (id INT,city VARCHAR(50),country VARCHAR(50)); INSERT INTO Warehouse (id,city,country) VALUES (1,'Hong Kong','China'); CREATE TABLE Shipment (id INT,quantity INT,warehouse_id INT,destination_country VARCHAR(50)); INSERT INTO Shipment (id,quantity,warehouse_id,destination_country) VALUES (1,500,1,'USA');
SELECT SUM(quantity) FROM Shipment INNER JOIN Warehouse ON Shipment.warehouse_id = Warehouse.id WHERE Warehouse.city = 'Hong Kong' AND Shipment.destination_country = 'USA';
List the total count of doctors and nurses in each state?
use rural_health; CREATE TABLE staff (id int,name text,title text,state text); INSERT INTO staff (id,name,title,state) VALUES (1,'Dr. John','Doctor','MO'); INSERT INTO staff (id,name,title,state) VALUES (2,'Nurse Lisa','Nurse','MO'); INSERT INTO staff (id,name,title,state) VALUES (3,'Dr. Mark','Doctor','KS');
SELECT title, COUNT(*) as total, state FROM rural_health.staff GROUP BY state, title;
What is the average number of kills per game for players from Japan in the game "Call of Duty"?
CREATE TABLE players (id INT,name VARCHAR(50),country VARCHAR(50),game_id INT,kills_per_game DECIMAL(10,2)); INSERT INTO players (id,name,country,game_id,kills_per_game) VALUES (1,'Player1','Japan',1,12.5),(2,'Player2','Japan',1,15.0),(3,'Player3','USA',1,18.0);
SELECT AVG(kills_per_game) FROM players WHERE country = 'Japan' AND game_id = 1;
What is the total funding received by biotech startups located in France?
CREATE TABLE startups (id INT,name VARCHAR(50),location VARCHAR(50),funding FLOAT); INSERT INTO startups (id,name,location,funding) VALUES (1,'Genomic Solutions','USA',5000000),(2,'BioTech Innovations','Europe',7000000),(3,'Medical Innovations','UK',6000000),(4,'Innovative Biotech','India',8000000),(5,'BioGenesis','France',9000000);
SELECT SUM(funding) FROM startups WHERE location = 'France';
Who are the top 5 customers with the highest total quantity of returns for ethically produced clothing items?
CREATE TABLE customers (id INT PRIMARY KEY,name VARCHAR(255),email VARCHAR(255)); CREATE TABLE returns (id INT PRIMARY KEY,product_id INT,customer_id INT,return_date DATE,FOREIGN KEY (product_id) REFERENCES products(id),FOREIGN KEY (customer_id) REFERENCES customers(id)); CREATE TABLE products (id INT PRIMARY KEY,name VARCHAR(255),category VARCHAR(255),is_ethical BOOLEAN,FOREIGN KEY (category) REFERENCES categories(name)); CREATE TABLE categories (name VARCHAR(255) PRIMARY KEY); CREATE VIEW returned_ethical_clothing AS SELECT customers.name AS customer_name,SUM(quantity) AS total_returned_quantity FROM returns JOIN products ON returns.product_id = products.id JOIN categories ON products.category = categories.name WHERE categories.name = 'Clothing' AND products.is_ethical = TRUE GROUP BY customers.name;
SELECT customer_name, total_returned_quantity FROM returned_ethical_clothing ORDER BY total_returned_quantity DESC LIMIT 5;
Delete all records in the 'Incidents' table where the 'IncidentType' is 'TrafficAccident' and the 'ResponseTime' is greater than 120 minutes
CREATE TABLE Incidents (IncidentID INT PRIMARY KEY,IncidentType VARCHAR(50),ResponseTime INT);
DELETE FROM Incidents WHERE IncidentType = 'TrafficAccident' AND ResponseTime > 120;
Delete the record of landfill capacity for the city of Rio de Janeiro in 2022.
CREATE TABLE landfill_capacity(city VARCHAR(20),year INT,capacity INT); INSERT INTO landfill_capacity VALUES('Rio de Janeiro',2022,600000);
DELETE FROM landfill_capacity WHERE city = 'Rio de Janeiro' AND year = 2022;
How many fish were added to the Salmon farm each month in 2020?
CREATE TABLE FarmStock (farm_id INT,date DATE,action VARCHAR(10),quantity INT); INSERT INTO FarmStock (farm_id,date,action,quantity) VALUES (2,'2020-01-01','added',300),(2,'2020-01-05','added',250);
SELECT EXTRACT(MONTH FROM date) month, SUM(quantity) quantity FROM FarmStock WHERE farm_id = 2 AND YEAR(date) = 2020 AND action = 'added' GROUP BY month;
List all machines located in the USA
CREATE TABLE machines (id INT PRIMARY KEY,name VARCHAR(50),model VARCHAR(50),year INT,location VARCHAR(50)); INSERT INTO machines (id,name,model,year,location) VALUES (1,'Machine A','Model X',2015,'USA'),(2,'Machine B','Model Y',2017,'Canada'),(3,'Machine C','Model Z',2019,'Mexico');
SELECT * FROM machines WHERE location = 'USA';
What is the average mental health score for students who took the exam on or after the 15th day of the month, ordered by district_id and then by the average mental health score?
CREATE TABLE student_mental_health (student_id INT,district_id INT,exam_date DATE,mental_health_score INT); INSERT INTO student_mental_health (student_id,district_id,exam_date,mental_health_score) VALUES (1,101,'2022-01-01',85),(2,101,'2022-02-15',82),(3,102,'2022-03-03',90),(4,102,'2022-04-07',92),(5,103,'2022-05-02',78);
SELECT district_id, AVG(mental_health_score) as avg_score FROM student_mental_health WHERE DAY(exam_date) >= 15 GROUP BY district_id ORDER BY district_id, avg_score;
Insert new records for players 'Diana' and 'Eric' with player_ids 4 and 5 respectively in the 'players' table.
CREATE TABLE players (player_id INT,name VARCHAR(50)); INSERT INTO players VALUES (1,'Amina'); INSERT INTO players VALUES (2,'Brian'); INSERT INTO players VALUES (3,'Chloe');
INSERT INTO players (player_id, name) VALUES (4, 'Diana'), (5, 'Eric');
List all digital assets and their regulatory status in the US.
CREATE TABLE DigitalAssets (AssetId INT,AssetName VARCHAR(50),RegulatorId INT); CREATE TABLE Regulators (RegulatorId INT,RegulatorName VARCHAR(50),Region VARCHAR(50)); INSERT INTO DigitalAssets (AssetId,AssetName,RegulatorId) VALUES (1,'ETH',1); INSERT INTO DigitalAssets (AssetId,AssetName,RegulatorId) VALUES (2,'BTC',2); INSERT INTO Regulators (RegulatorId,RegulatorName,Region) VALUES (1,'Regulator1','EU'); INSERT INTO Regulators (RegulatorId,RegulatorName,Region) VALUES (2,'Regulator2','US'); INSERT INTO Regulators (RegulatorId,RegulatorName,Region) VALUES (3,'Regulator3','US');
SELECT da.AssetName, r.RegulatorName FROM DigitalAssets da INNER JOIN Regulators r ON da.RegulatorId = r.RegulatorId WHERE r.Region = 'US';
How many safety inspections were performed in 2020 and 2021?
CREATE TABLE IF NOT EXISTS vessel_safety (id INT PRIMARY KEY,vessel_name VARCHAR(255),safety_inspection_date DATE); INSERT INTO vessel_safety (id,vessel_name,safety_inspection_date) VALUES (1,'SS Great Britain','2021-03-15'),(2,'Queen Mary 2','2021-06-23'),(3,'Titanic','2021-09-11'),(4,'Canberra','2020-12-10'),(5,'France','2020-08-18');
SELECT COUNT(*) FROM vessel_safety WHERE YEAR(safety_inspection_date) IN (2020, 2021);
Update the Samarium production quantity to 1000.0 for the row with the latest production date.
CREATE TABLE samarium_production (id INT,name VARCHAR(255),element VARCHAR(10),country VARCHAR(100),production_date DATE,quantity FLOAT); INSERT INTO samarium_production (id,name,element,country,production_date,quantity) VALUES (1,'Company A','Sm','China','2022-01-01',800.0),(2,'Company B','Sm','Australia','2022-02-01',900.0),(3,'Company C','Sm','Malaysia','2022-03-01',1000.0);
UPDATE samarium_production SET quantity = 1000.0 WHERE id = (SELECT id FROM samarium_production WHERE production_date = (SELECT MAX(production_date) FROM samarium_production));
Which countries have invested in climate mitigation in Africa?
CREATE TABLE MitigationActions (Country TEXT,Investment_Amount NUMERIC); INSERT INTO MitigationActions (Country,Investment_Amount) VALUES ('South Africa',2000000),('Egypt',1500000),('Morocco',1000000);
SELECT DISTINCT Country FROM MitigationActions WHERE Investment_Amount IS NOT NULL;
What is the average energy efficiency rating of residential buildings in California, grouped by city and construction period?
CREATE TABLE residential_buildings (id INT,city VARCHAR(100),state VARCHAR(50),energy_efficiency_rating FLOAT,construction_period DATE); INSERT INTO residential_buildings (id,city,state,energy_efficiency_rating,construction_period) VALUES (1,'City A','California',80,'2000-01-01'); INSERT INTO residential_buildings (id,city,state,energy_efficiency_rating,construction_period) VALUES (2,'City B','California',85,'2005-01-01');
SELECT city, YEAR(construction_period) AS construction_year, AVG(energy_efficiency_rating) AS avg_rating FROM residential_buildings WHERE state = 'California' GROUP BY city, YEAR(construction_period);
What is the total revenue generated from wheelchair accessible taxis in New York city?
CREATE TABLE taxi_trips (trip_id INT,vehicle_type VARCHAR(20),total_fare DECIMAL(10,2)); CREATE TABLE vehicles (vehicle_id INT,vehicle_type VARCHAR(20),is_wheelchair_accessible BOOLEAN); INSERT INTO taxi_trips (trip_id,vehicle_type,total_fare) VALUES (1,'Taxi',25.00),(2,'Wheelchair Accessible Taxi',30.00); INSERT INTO vehicles (vehicle_id,vehicle_type,is_wheelchair_accessible) VALUES (1,'Taxi',false),(2,'Wheelchair Accessible Taxi',true);
SELECT SUM(tt.total_fare) FROM taxi_trips tt JOIN vehicles v ON tt.vehicle_type = v.vehicle_type WHERE v.is_wheelchair_accessible = true AND tt.vehicle_type = 'Wheelchair Accessible Taxi';
List all the unique IP addresses that attempted a brute force attack in the last week, and the corresponding attack type.
CREATE TABLE brute_force_attacks (id INT,ip_address VARCHAR(50),attack_type VARCHAR(50),timestamp TIMESTAMP); INSERT INTO brute_force_attacks (id,ip_address,attack_type,timestamp) VALUES (1,'192.168.1.100','ssh','2022-01-01 10:00:00'),(2,'10.0.0.2','ftp','2022-01-02 12:00:00');
SELECT DISTINCT ip_address, attack_type FROM brute_force_attacks WHERE timestamp >= DATE_SUB(CURRENT_TIMESTAMP(), INTERVAL 1 WEEK);
What are the total assets under management (AUM) for each investment strategy, including a 3% management fee?
CREATE TABLE Investment_Strategies (strategy_id INT,strategy_name VARCHAR(30),AUM DECIMAL(12,2)); INSERT INTO Investment_Strategies (strategy_id,strategy_name,AUM) VALUES (1,'Equity',5000000.00),(2,'Fixed Income',3000000.00),(3,'Alternatives',2000000.00);
SELECT strategy_name, SUM(AUM * 1.03) AS total_AUM FROM Investment_Strategies GROUP BY strategy_name;
Delete records for biotech startups from India that received no funding.
CREATE TABLE biotech_startups(id INT,company_name TEXT,location TEXT,funding_amount DECIMAL(10,2),quarter INT,year INT);
DELETE FROM biotech_startups WHERE location = 'India' AND funding_amount = 0;
List the top 2 community development initiatives by the number of participants, in descending order, for each year in the 'community_development' schema?
CREATE TABLE community_development (id INT,initiative_name TEXT,year INT,participants INT); INSERT INTO community_development (id,initiative_name,year,participants) VALUES (1,'Adult Literacy Program',2020,500),(2,'Youth Job Training',2020,300),(3,'Solar Energy Workshop',2021,400),(4,'Women in Agriculture Conference',2021,600);
SELECT initiative_name, year, participants, RANK() OVER (PARTITION BY year ORDER BY participants DESC) AS rank FROM community_development;
How many inclusive housing units are available in each city?
CREATE TABLE housing_units (id INT,city VARCHAR(20),units INT); INSERT INTO housing_units (id,city,units) VALUES (1,'New York',200),(2,'Seattle',100),(3,'Oakland',300),(4,'Berkeley',150);
SELECT city, SUM(units) FROM housing_units GROUP BY city;
What is the total runtime of the TV shows produced in Mexico and released after 2015, categorized by genre?
CREATE TABLE tv_shows (id INT,title VARCHAR(255),runtime INT,release_year INT,country VARCHAR(50),genre VARCHAR(50)); INSERT INTO tv_shows (id,title,runtime,release_year,country,genre) VALUES (1,'Show1',120,2016,'Mexico','Comedy'),(2,'Show2',90,2017,'Mexico','Drama'),(3,'Show3',105,2018,'Mexico','Action');
SELECT genre, SUM(runtime) FROM tv_shows WHERE release_year > 2015 AND country = 'Mexico' GROUP BY genre;
Who is the oldest football player in the NFL?
CREATE TABLE football_players (id INT,name VARCHAR(50),age INT,sport VARCHAR(50));
SELECT name FROM (SELECT name, ROW_NUMBER() OVER (ORDER BY age DESC) as rank FROM football_players WHERE sport = 'NFL') subquery WHERE rank = 1;
Which cities have a higher number of schools than libraries?
CREATE TABLE city_education (city TEXT,num_schools INTEGER,num_libraries INTEGER); INSERT INTO city_education (city,num_schools,num_libraries) VALUES ('CityA',35,20),('CityB',20,30),('CityC',40,15),('CityD',10,35);
SELECT city FROM city_education WHERE num_schools > num_libraries;
What is the total sales of drug Y in Canada?
CREATE TABLE sales_figures (drug VARCHAR(255),country VARCHAR(255),sales INT); INSERT INTO sales_figures (drug,country,sales) VALUES ('Drug Y','Canada',1000000);
SELECT drug, SUM(sales) FROM sales_figures WHERE drug = 'Drug Y' AND country = 'Canada';
What is the total number of properties in each city that have sustainable features?
CREATE TABLE Cities (City varchar(20)); CREATE TABLE Properties (PropertyID int,City varchar(20),Sustainable varchar(5)); INSERT INTO Cities (City) VALUES ('Seattle'); INSERT INTO Properties (PropertyID,City,Sustainable) VALUES (1,'Seattle','Yes'); INSERT INTO Properties (PropertyID,City,Sustainable) VALUES (2,'Portland','No'); INSERT INTO Properties (PropertyID,City,Sustainable) VALUES (3,'Seattle','Yes');
SELECT Properties.City, COUNT(Properties.PropertyID) FROM Properties INNER JOIN Cities ON Properties.City = Cities.City WHERE Properties.Sustainable = 'Yes' GROUP BY Properties.City;
What is the average age of clients in the 'Florida' region?
CREATE TABLE clients (id INT,name TEXT,age INT,region TEXT); INSERT INTO clients (id,name,age,region) VALUES (1,'Fatima Fernandez',40,'Florida'); CREATE TABLE attorneys (id INT,name TEXT,region TEXT,title TEXT); INSERT INTO attorneys (id,name,region,title) VALUES (1,'Ricardo Rodriguez','Florida','Partner');
SELECT AVG(age) FROM clients WHERE region = 'Florida';
Show the total weight of organic products supplied by each supplier.
CREATE TABLE products (id INT,name VARCHAR(255),organic BOOLEAN,weight FLOAT,supplier_id INT);
SELECT s.name, SUM(p.weight) FROM suppliers s INNER JOIN products p ON s.id = p.supplier_id WHERE p.organic = 't' GROUP BY s.name;
How many climate adaptation projects have been implemented in Small Island Developing States?
CREATE TABLE climate_projects (id INT,project_name VARCHAR(50),location VARCHAR(50),sector VARCHAR(50));
SELECT COUNT(*) FROM climate_projects WHERE location LIKE '%Small Island Developing States%' AND sector = 'adaptation';
Delete all records from the environmental_impact table that have a value less than 5 for the impact_score column
CREATE TABLE environmental_impact (id INT PRIMARY KEY,element VARCHAR(10),impact_score INT);
DELETE FROM environmental_impact WHERE impact_score < 5;
Insert new records for an exhibition held at the Tate Modern in London.
CREATE TABLE museums (museum_id INT,name VARCHAR(50),city VARCHAR(50),opening_year INT); INSERT INTO museums (museum_id,name,city,opening_year) VALUES (1,'Tate Modern','London',2000); CREATE TABLE exhibitions (exhibition_id INT,title VARCHAR(50),year INT,museum_id INT,art_count INT); INSERT INTO exhibitions (exhibition_id,title,year,museum_id,art_count) VALUES (1,'First Exhibition',2000,1,100);
INSERT INTO exhibitions (exhibition_id, title, year, museum_id, art_count) VALUES (2, 'New Artists', 2023, 1, 75);
What is the number of clients who have made a transaction on their birthday in Q3 2023?
CREATE TABLE clients (client_id INT,name VARCHAR(50),dob DATE);CREATE TABLE transactions (transaction_id INT,client_id INT,transaction_date DATE);
SELECT COUNT(*) FROM clients c INNER JOIN transactions t ON c.client_id = t.client_id WHERE DATE_FORMAT(t.transaction_date, '%Y') - DATE_FORMAT(c.dob, '%Y') = (YEAR(CURDATE()) - YEAR(c.dob)) AND MONTH(t.transaction_date) = MONTH(c.dob) AND DAY(t.transaction_date) = DAY(c.dob) AND t.transaction_date BETWEEN '2023-07-01' AND '2023-09-30'
How many community policing events were held in each neighborhood in the last year?
CREATE TABLE neighborhoods (nid INT,name VARCHAR(255)); CREATE TABLE events (eid INT,nid INT,date DATE,type VARCHAR(255)); INSERT INTO neighborhoods VALUES (1,'Westside'),(2,'Eastside'); INSERT INTO events VALUES (1,1,'2021-01-01','Community meeting'),(2,2,'2021-02-01','Neighborhood watch');
SELECT n.name, YEAR(e.date) as year, COUNT(e.eid) as num_events FROM neighborhoods n JOIN events e ON n.nid = e.nid WHERE e.date >= '2021-01-01' GROUP BY n.nid, year;
What is the average rating for each garment manufacturer?
CREATE TABLE products (product_id INT,product_name VARCHAR(50),manufacturer VARCHAR(50),rating DECIMAL(3,2));
SELECT manufacturer, AVG(rating) as avg_rating FROM products GROUP BY manufacturer;
What is the total salary cost for the HR department in 2021?
CREATE TABLE Employees (EmployeeID INT,Gender VARCHAR(10),Department VARCHAR(20),Salary FLOAT,HireDate DATE); INSERT INTO Employees (EmployeeID,Gender,Department,Salary,HireDate) VALUES (1,'Male','IT',70000,'2021-01-01'),(2,'Female','IT',65000,'2021-01-01'),(3,'Male','HR',60000,'2021-01-01'),(4,'Female','Marketing',80000,'2021-01-01');
SELECT SUM(Salary) FROM Employees WHERE Department = 'HR' AND YEAR(HireDate) = 2021;
What is the average data usage per mobile subscriber in the 'urban' geographic area, grouped by network type?
CREATE TABLE network_type (network_type VARCHAR(20)); INSERT INTO network_type (network_type) VALUES ('5G'),('4G'),('3G'); CREATE TABLE customers (customer_id INT,name VARCHAR(50),geographic_area VARCHAR(20),network_type VARCHAR(20)); INSERT INTO customers (customer_id,name,geographic_area,network_type) VALUES (1,'John Doe','urban','5G'); CREATE TABLE mobile_data_usage (customer_id INT,month INT,data_usage INT); INSERT INTO mobile_data_usage (customer_id,month,data_usage) VALUES (1,1,1500);
SELECT network_type, AVG(data_usage) FROM mobile_data_usage JOIN customers ON mobile_data_usage.customer_id = customers.customer_id JOIN network_type ON customers.network_type = network_type.network_type WHERE customers.geographic_area = 'urban' GROUP BY network_type;
What is the average flight time for Airbus A320 aircraft?
CREATE TABLE Flight_Data (flight_date DATE,aircraft_model VARCHAR(255),flight_time TIME); INSERT INTO Flight_Data (flight_date,aircraft_model,flight_time) VALUES ('2020-01-01','Airbus A320','05:00:00'),('2020-02-01','Boeing 737','04:00:00'),('2020-03-01','Airbus A320','05:30:00'),('2020-04-01','Boeing 747','07:00:00'),('2020-05-01','Airbus A320','04:45:00');
SELECT AVG(EXTRACT(EPOCH FROM flight_time)) / 60.0 AS avg_flight_time FROM Flight_Data WHERE aircraft_model = 'Airbus A320';
What is the minimum funding obtained by startups in the biotechnology sector located in France?
CREATE TABLE startups (id INT,name VARCHAR(50),location VARCHAR(50),sector VARCHAR(50),funding FLOAT); INSERT INTO startups (id,name,location,sector,funding) VALUES (3,'StartupC','France','Biotechnology',3000000);
SELECT MIN(funding) FROM startups WHERE sector = 'Biotechnology' AND location = 'France';
Who are the journalists with more than 10 years of experience?
CREATE TABLE journalists_extended (name VARCHAR(50),gender VARCHAR(10),years_experience INT,salary DECIMAL(10,2)); INSERT INTO journalists_extended (name,gender,years_experience,salary) VALUES ('Alice Johnson','Female',12,55000.00),('Bob Smith','Male',8,45000.00),('Charlie Brown','Male',15,65000.00),('Dana Rogers','Female',20,75000.00),('Evan Green','Male',7,35000.00);
SELECT name, years_experience FROM journalists_extended WHERE years_experience > 10;
How many community education programs were held in 2021 and 2022?
CREATE TABLE education_programs (id INT,year INT,programs INT); INSERT INTO education_programs (id,year,programs) VALUES (1,2019,120),(2,2020,150),(3,2021,250),(4,2022,300);
SELECT SUM(programs) FROM education_programs WHERE year IN (2021, 2022);
What is the minimum fare for public transportation in CityG?
CREATE TABLE CityG_Fares (fare_id INT,fare FLOAT,payment_type VARCHAR(20),route_type VARCHAR(20)); INSERT INTO CityG_Fares (fare_id,fare,payment_type,route_type) VALUES (1,2.5,'Cash','Bus'),(2,3.2,'Card','Train'),(3,1.8,'Cash','Tram'),(4,4.1,'Card','Bus');
SELECT MIN(fare) FROM CityG_Fares;
What is the average temperature recorded for corn crops in India over the last month?
CREATE TABLE crop_temperature (id INT,crop VARCHAR(50),temperature FLOAT,record_date DATE); INSERT INTO crop_temperature (id,crop,temperature,record_date) VALUES (1,'Corn',30.5,'2022-04-01'),(2,'Soybeans',20.2,'2022-04-01'),(3,'Cotton',40.0,'2022-04-01'),(4,'Wheat',15.7,'2022-04-01'),(5,'Corn',32.1,'2022-04-02'),(6,'Soybeans',22.8,'2022-04-02'),(7,'Cotton',41.5,'2022-04-02'),(8,'Wheat',17.3,'2022-04-02'),(9,'Corn',35.0,'2022-04-03'),(10,'Soybeans',25.6,'2022-04-03');
SELECT AVG(temperature) FROM crop_temperature WHERE crop = 'Corn' AND record_date IN (SELECT record_date FROM satellite_images WHERE farm_id IN (SELECT id FROM farmers WHERE location = 'India')) AND record_date >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH);
What is the maximum response time for emergency calls in each city, in minutes?
CREATE TABLE cities (id INT,name TEXT);CREATE TABLE emergencies (id INT,city_id INT,response_time INT);
SELECT c.name, MAX(e.response_time)/60.0 AS max_response_time_minutes FROM cities c JOIN emergencies e ON c.id = e.city_id GROUP BY c.id;
How can I update the recycling rate for 'Glass' material to 45%?
CREATE TABLE waste_materials (id INT,name VARCHAR(255),recycling_rate DECIMAL(5,2)); INSERT INTO waste_materials (id,name,recycling_rate) VALUES (1,'Glass',40),(2,'Plastic',25),(3,'Paper',60),(4,'Metal',70);
UPDATE waste_materials SET recycling_rate = 45 WHERE name = 'Glass';
What is the average rating for each exhibition from visitors who have completed a survey?
CREATE TABLE Exhibitions (ExhibitionID INT,ExhibitionName VARCHAR(255)); INSERT INTO Exhibitions (ExhibitionID,ExhibitionName) VALUES (1,'Modern Art'); INSERT INTO Exhibitions (ExhibitionID,ExhibitionName) VALUES (2,'Natural History'); CREATE TABLE Visitors (VisitorID INT,ExhibitionID INT,HasCompletedSurvey BOOLEAN); INSERT INTO Visitors (VisitorID,ExhibitionID,HasCompletedSurvey) VALUES (1,1,true); INSERT INTO Visitors (VisitorID,ExhibitionID,HasCompletedSurvey) VALUES (2,1,false); INSERT INTO Visitors (VisitorID,ExhibitionID,HasCompletedSurvey) VALUES (3,2,true); CREATE TABLE SurveyResults (SurveyID INT,VisitorID INT,ExhibitionRating INT); INSERT INTO SurveyResults (SurveyID,VisitorID,ExhibitionRating) VALUES (1,1,9); INSERT INTO SurveyResults (SurveyID,VisitorID,ExhibitionRating) VALUES (2,3,8);
SELECT E.ExhibitionName, AVG(SR.ExhibitionRating) as AverageRating FROM Exhibitions E INNER JOIN Visitors V ON E.ExhibitionID = V.ExhibitionID INNER JOIN SurveyResults SR ON V.VisitorID = SR.VisitorID WHERE V.HasCompletedSurvey = true GROUP BY E.ExhibitionName;
What is the average duration of podcasts in the podcasts table published by 'Eva'?
CREATE TABLE podcasts (title VARCHAR(255),host VARCHAR(255),date DATE,duration INT);
SELECT AVG(duration) FROM podcasts WHERE host = 'Eva';
List all transactions associated with smart contracts in the 'Asia' region.
CREATE TABLE regulatory_frameworks (asset_name VARCHAR(255),regulation_name VARCHAR(255),region VARCHAR(255)); INSERT INTO regulatory_frameworks (asset_name,regulation_name,region) VALUES ('CryptoKitties','CK Regulation 1.0','Global'),('CryptoPunks','CP Regulation 1.0','Asia');
SELECT t.tx_hash FROM transactions t INNER JOIN smart_contracts s ON t.smart_contract_id = s.id INNER JOIN regulatory_frameworks r ON s.asset_name = r.asset_name WHERE r.region = 'Asia';
Count the number of volunteers who engaged in each program in H1 2022, grouped by program.
CREATE TABLE Volunteers (VolunteerID int,VolunteerDate date,Program varchar(50)); INSERT INTO Volunteers (VolunteerID,VolunteerDate,Program) VALUES (1,'2022-01-01','Education'),(2,'2022-02-01','Healthcare'),(3,'2022-01-15','Food Support');
SELECT Program, COUNT(*) as NumberOfVolunteers FROM Volunteers WHERE YEAR(VolunteerDate) = 2022 AND MONTH(VolunteerDate) <= 6 GROUP BY Program;
List all deep-sea creatures discovered since 2010.
CREATE TABLE deep_sea_creatures (id INT,creature_name TEXT,discovery_date DATE); INSERT INTO deep_sea_creatures (id,creature_name,discovery_date) VALUES (1,'Snailfish','2014-08-04'); INSERT INTO deep_sea_creatures (id,creature_name,discovery_date) VALUES (2,'Yeti Crab','2005-03-26');
SELECT creature_name FROM deep_sea_creatures WHERE discovery_date >= '2010-01-01';
What is the total number of academic publications by female faculty members?
CREATE TABLE academic_publications (id INT,faculty_id INT,author_gender VARCHAR(50)); INSERT INTO academic_publications (id,faculty_id,author_gender) VALUES (1,1,'Female'),(2,2,'Male'),(3,3,'Non-binary'),(4,4,'Female'),(5,5,'Male');
SELECT COUNT(*) FROM academic_publications WHERE author_gender = 'Female';
Identify the top 3 donors by total donation amount in Q1 2021.
CREATE TABLE Donors (DonorID INT,DonorName TEXT,TotalDonation FLOAT); INSERT INTO Donors (DonorID,DonorName,TotalDonation) VALUES (1,'John Doe',500.00),(2,'Jane Smith',350.00),(3,'Alice Johnson',800.00);
SELECT DonorName, SUM(TotalDonation) AS TotalDonation FROM Donors WHERE DonationDate BETWEEN '2021-01-01' AND '2021-03-31' GROUP BY DonorName ORDER BY TotalDonation DESC LIMIT 3;
What is the average age of community health workers who have completed cultural competency training?
CREATE TABLE completed_training (worker_id INT,training_type VARCHAR(50)); INSERT INTO completed_training (worker_id,training_type) VALUES (1,'Cultural Competency'),(2,'Cultural Competency'),(3,'Cultural Competency'),(4,'Diversity Training');
SELECT AVG(age) as avg_age FROM community_health_workers chw INNER JOIN completed_training ct ON chw.worker_id = ct.worker_id;
What is the minimum salary for employees who identify as Indigenous and have completed cultural sensitivity training?
CREATE TABLE EmployeeTraining (EmployeeID INT,Ethnicity VARCHAR(20),Training VARCHAR(30),Salary DECIMAL(10,2)); INSERT INTO EmployeeTraining (EmployeeID,Ethnicity,Training,Salary) VALUES (1,'Indigenous','Cultural Sensitivity',70000.00),(2,'African','Cultural Sensitivity',75000.00);
SELECT MIN(Salary) FROM EmployeeTraining WHERE Ethnicity = 'Indigenous' AND Training = 'Cultural Sensitivity';
Display the earliest recorded date in the 'ocean_temperature_data' table.
CREATE TABLE ocean_temperature_data (data_id INT,date DATE,temperature FLOAT);
SELECT MIN(date) FROM ocean_temperature_data;
Insert a new record for a baseball game between the "Yankees" and "Red Sox" into the "games" table
CREATE TABLE games (game_id INT PRIMARY KEY,home_team VARCHAR(50),away_team VARCHAR(50),city VARCHAR(50),stadium VARCHAR(50),game_date DATE);
INSERT INTO games (game_id, home_team, away_team, city, stadium, game_date) VALUES (101, 'Yankees', 'Red Sox', 'New York', 'Yankee Stadium', '2022-07-01');
What are the total installed solar capacities for all renewable energy projects in the renewable_energy schema?
CREATE SCHEMA renewable_energy; CREATE TABLE solar_projects (project_name VARCHAR(255),installed_capacity INT); INSERT INTO solar_projects (project_name,installed_capacity) VALUES ('Sunrise Solar Farm',100000),('Windy Solar Park',120000),('Solar Bliss Ranch',75000);
SELECT SUM(installed_capacity) FROM renewable_energy.solar_projects;
What is the average number of animals adopted by users in 'urban' areas?
CREATE TABLE users (user_id INT,name VARCHAR(50),address VARCHAR(50)); INSERT INTO users (user_id,name,address) VALUES (1,'John Doe','rural'),(2,'Jane Smith','urban'); CREATE TABLE adoptions (adoption_id INT,animal_id INT,user_id INT); INSERT INTO adoptions (adoption_id,animal_id,user_id) VALUES (1,101,1),(2,102,2); CREATE TABLE animals (animal_id INT,animal_name VARCHAR(50)); INSERT INTO animals (animal_id,animal_name) VALUES (101,'Dog'),(102,'Cat');
SELECT AVG(adoptions.adoption_id) FROM adoptions INNER JOIN users ON adoptions.user_id = users.user_id WHERE users.address = 'urban';
Insert new records into the 'victims' table with victim_id 2001, 2002, first_name 'Victoria', 'Victor', last_name 'Martin'
CREATE TABLE victims (victim_id INT,first_name VARCHAR(20),last_name VARCHAR(20));
INSERT INTO victims (victim_id, first_name, last_name) VALUES (2001, 'Victoria', 'Martin'), (2002, 'Victor', 'Martin');
What is the average rating of movies produced by studios located in 'Los Angeles'?
CREATE TABLE Studio (studio_id INT,studio_name VARCHAR(50),city VARCHAR(50)); INSERT INTO Studio (studio_id,studio_name,city) VALUES (1,'DreamWorks','Los Angeles'),(2,'Warner Bros.','Los Angeles'); CREATE TABLE Movie (movie_id INT,title VARCHAR(50),rating DECIMAL(2,1),studio_id INT); INSERT INTO Movie (movie_id,title,rating,studio_id) VALUES (1,'Shrek',7.8,1),(2,'The Matrix',8.7,1),(3,'Casablanca',8.5,2);
SELECT AVG(m.rating) FROM Movie m JOIN Studio s ON m.studio_id = s.studio_id WHERE s.city = 'Los Angeles';
What is the total number of registered voters in the "VoterData" table, per state, for voters who are over 70 years old?
CREATE TABLE VoterData (id INT,name VARCHAR(50),age INT,state VARCHAR(50),registered BOOLEAN); INSERT INTO VoterData (id,name,age,state,registered) VALUES (1,'John Doe',75,'New York',true),(2,'Jane Smith',45,'California',true),(3,'Bob Johnson',72,'Florida',true),(4,'Alice Williams',55,'Texas',false),(5,'Jim Brown',71,'New York',true);
SELECT state, COUNT(*) as num_voters FROM VoterData WHERE age > 70 AND registered = true GROUP BY state;
Compare the CO2 emissions of the transportation sector in Japan and South Africa.
CREATE TABLE co2_emissions (country VARCHAR(20),sector VARCHAR(20),co2_emissions INT); INSERT INTO co2_emissions (country,sector,co2_emissions) VALUES ('Japan','transportation',240000),('South Africa','transportation',180000);
SELECT co2_emissions FROM co2_emissions WHERE country = 'Japan' INTERSECT SELECT co2_emissions FROM co2_emissions WHERE country = 'South Africa';
How many members joined in each month of 2021?
CREATE TABLE membership_data (member_id INT,join_date DATE); INSERT INTO membership_data (member_id,join_date) VALUES (1,'2021-01-05'),(2,'2021-02-12'),(3,'2021-03-20'),(4,'2021-04-28'),(5,'2021-05-03');
SELECT EXTRACT(MONTH FROM join_date) AS month, COUNT(*) AS members_joined FROM membership_data WHERE join_date >= '2021-01-01' AND join_date < '2022-01-01' GROUP BY month;
What is the average runtime of animated movies released between 2010 and 2015?
CREATE TABLE Genres (id INT,genre VARCHAR(50)); CREATE TABLE Movies (id INT,title VARCHAR(100),genre_id INT,runtime INT,release_year INT); INSERT INTO Genres (id,genre) VALUES (1,'Animated'),(2,'Action'); INSERT INTO Movies (id,title,genre_id,runtime,release_year) VALUES (1,'Movie1',1,80,2012),(2,'Movie2',1,100,2013),(3,'Movie3',2,120,2016);
SELECT AVG(runtime) FROM Movies WHERE genre_id = (SELECT id FROM Genres WHERE genre = 'Animated') AND release_year BETWEEN 2010 AND 2015;
List all garment manufacturers that use eco-friendly materials, ordered alphabetically.
CREATE TABLE manufacturers (id INT PRIMARY KEY,name VARCHAR(50),eco_friendly BOOLEAN);
SELECT name FROM manufacturers WHERE eco_friendly = TRUE ORDER BY name;