instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the average budget for healthcare services in coastal districts?
CREATE TABLE districts (id INT,name TEXT,type TEXT,budget FLOAT); INSERT INTO districts (id,name,type,budget) VALUES (1,'City A','urban-coastal',6000000),(2,'Town B','urban-inland',2500000),(3,'Village C','rural',1200000);
SELECT AVG(budget) FROM districts WHERE type LIKE '%coastal%';
What is the minimum energy production cost of geothermal plants in Indonesia?
CREATE TABLE geothermal_costs (id INT,name TEXT,country TEXT,energy_production_cost FLOAT); INSERT INTO geothermal_costs (id,name,country,energy_production_cost) VALUES (1,'Sarulla','Indonesia',0.065),(2,'Cameron','Indonesia',0.070);
SELECT MIN(energy_production_cost) FROM geothermal_costs WHERE country = 'Indonesia';
What are the top 3 preferred lipstick colors by consumers in the US?
CREATE TABLE cosmetics.lipstick_preferences (consumer_id INT,lipstick_color VARCHAR(20)); INSERT INTO cosmetics.lipstick_preferences (consumer_id,lipstick_color) VALUES (1,'Red'),(2,'Pink'),(3,'Nude'),(4,'Red'),(5,'Pink');
SELECT lipstick_color, COUNT(*) as countOfPreference FROM cosmetics.lipstick_preferences WHERE lipstick_color IN ('Red', 'Pink', 'Nude') GROUP BY lipstick_color ORDER BY countOfPreference DESC LIMIT 3;
List all the suppliers that have provided goods for a specific product, along with the total quantity and total revenue generated from those goods.
CREATE TABLE products (id INT,name TEXT,supplier TEXT); CREATE TABLE sales (id INT,product_id INT,quantity INT,revenue FLOAT);
SELECT p.supplier, SUM(s.quantity) as total_quantity, SUM(s.revenue) as total_revenue FROM products p JOIN sales s ON p.id = s.product_id WHERE p.name = 'specific product' GROUP BY p.supplier;
Calculate the percentage of items that are sustainable
CREATE TABLE inventory (id INT,item_name VARCHAR(20),is_sustainable BOOLEAN,quantity INT); INSERT INTO inventory (id,item_name,is_sustainable,quantity) VALUES (1,'t-shirt',false,100),(2,'blouse',true,50),(3,'jeans',true,75),(4,'skirt',false,150),(5,'jacket',true,100);
SELECT (COUNT(CASE WHEN is_sustainable = true THEN 1 END) * 100.0 / COUNT(*)) AS percentage FROM inventory;
What is the total transaction value for all customers in the Asia-Pacific region?
CREATE TABLE transactions (customer_id INT,region VARCHAR(20),transaction_value DECIMAL(10,2)); INSERT INTO transactions (customer_id,region,transaction_value) VALUES (1,'Asia-Pacific',120.50),(2,'Europe',75.30);
SELECT SUM(transaction_value) FROM transactions WHERE region = 'Asia-Pacific';
Identify farms in France using Drip irrigation with a duration greater than 20 minutes.
CREATE TABLE Farmers (id INT,name VARCHAR(50),age INT,country VARCHAR(50)); INSERT INTO Farmers (id,name,age,country) VALUES (1,'Jane Smith',45,'France'); CREATE TABLE Irrigation (id INT,Farm_id INT,irrigation_type VARCHAR(50),duration INT); INSERT INTO Irrigation (id,Farm_id,irrigation_type,duration) VALUES (1,1,'Drip',35);
SELECT f.name FROM Farmers f JOIN Irrigation i ON f.id = i.Farm_id WHERE f.country = 'France' AND i.irrigation_type = 'Drip' AND i.duration > 20;
What is the average mass of spacecrafts manufactured in the US, grouped by manufacturer?
CREATE TABLE spacecraft_manufacturers (manufacturer_id INT,name TEXT,country TEXT); INSERT INTO spacecraft_manufacturers (manufacturer_id,name,country) VALUES (1,'NASA','USA'),(2,'SpaceX','USA'); CREATE TABLE spacecrafts (spacecraft_id INT,name TEXT,manufacturer_id INT,mass FLOAT); INSERT INTO spacecrafts (spacecraft_id,name,manufacturer_id,mass) VALUES (1,'Orion',1,18000),(2,'Starship',2,1200000),(3,'Crew Dragon',2,12500);
SELECT sm.name, AVG(s.mass) FROM spacecrafts s JOIN spacecraft_manufacturers sm ON s.manufacturer_id = sm.manufacturer_id WHERE sm.country = 'USA' GROUP BY sm.name;
What is the average rating of TV shows produced by companies based in Japan?
CREATE TABLE tv_studios (studio_id INT,studio_name TEXT,country TEXT); INSERT INTO tv_studios (studio_id,studio_name,country) VALUES (1,'Studio H','Japan'),(2,'Studio I','USA'),(3,'Studio J','Germany'); CREATE TABLE tv_shows (show_id INT,title TEXT,rating DECIMAL(2,1),studio_id INT); INSERT INTO tv_shows (show_id,title,rating,studio_id) VALUES (1,'Show 7',8.2,1),(2,'Show 8',7.5,1),(3,'Show 9',6.9,2);
SELECT AVG(tv_shows.rating) FROM tv_shows JOIN tv_studios ON tv_shows.studio_id = tv_studios.studio_id WHERE tv_studios.country = 'Japan';
Find the number of visitors who are repeat attendees for theater events.
CREATE TABLE repeat_visitors (id INT,name TEXT,visited INT); INSERT INTO repeat_visitors VALUES (1,'Oliver',2);
SELECT COUNT(DISTINCT repeat_visitors.name) FROM repeat_visitors WHERE repeat_visitors.visited > 1 AND repeat_visitors.id IN (SELECT t.id FROM theater_events t);
What is the total cost of sustainable construction projects in Florida, grouped by building type?
CREATE TABLE sustainable_projects (project_id INT,state VARCHAR(2),building_type VARCHAR(20),project_cost DECIMAL(7,2)); INSERT INTO sustainable_projects (project_id,state,building_type,project_cost) VALUES (1,'FL','Residential',50000.00),(2,'FL','Residential',55000.50),(3,'FL','Commercial',100000.00);
SELECT building_type, SUM(project_cost) FROM sustainable_projects WHERE state = 'FL' GROUP BY building_type;
What are the maximum and minimum salaries for employees who identify as male and work in the HR department?
SAME AS ABOVE
SELECT MAX(Salary), MIN(Salary) FROM Employees WHERE Gender = 'Male' AND Department = 'HR';
Find the top 2 countries with the most number of organic farms, and the number of organic farms in those countries.
CREATE TABLE Farm (FarmID int,FarmType varchar(20),Country varchar(50)); INSERT INTO Farm (FarmID,FarmType,Country) VALUES (1,'Organic','USA'),(2,'Conventional','Canada'),(3,'Urban','Mexico'),(4,'Organic','USA'),(5,'Organic','Mexico');
SELECT Country, COUNT(*) as NumOrgFarms FROM Farm WHERE FarmType = 'Organic' GROUP BY Country ORDER BY NumOrgFarms DESC LIMIT 2;
Display the number of female and male employees in each department from 'employee_demographics'
CREATE TABLE employee_demographics (id INT PRIMARY KEY,employee_id INT,name VARCHAR(255),gender VARCHAR(255),department VARCHAR(255),region VARCHAR(255)); INSERT INTO employee_demographics (id,employee_id,name,gender,department,region) VALUES (1,101,'Jamal Johnson','Male','Marketing','Northwest'),(2,102,'Sofia Garcia','Female','IT','Northeast');
SELECT department, gender, COUNT(*) FROM employee_demographics GROUP BY department, gender;
Display the names and sentences of all inmates who have been incarcerated for more than 5 years
CREATE TABLE inmates (inmate_id INT,inmate_name VARCHAR(255),sentence_length INT,PRIMARY KEY (inmate_id)); INSERT INTO inmates (inmate_id,inmate_name,sentence_length) VALUES (1,'Inmate 1',60),(2,'Inmate 2',36),(3,'Inmate 3',72);
SELECT inmate_name, sentence_length FROM inmates WHERE sentence_length > 60;
Calculate the median age of members who have participated in yoga workouts.
CREATE TABLE MemberWorkout (member_id INT,workout_id INT); INSERT INTO MemberWorkout (member_id,workout_id) VALUES (1001,3001);
SELECT AVG(DATEDIFF('day', dob, CURDATE()))/365 as median_age FROM Member m JOIN MemberWorkout mw ON m.id = mw.member_id JOIN WorkoutType wt ON mw.workout_id = wt.id WHERE wt.workout_name = 'Yoga' GROUP BY m.id ORDER BY median_age;
What is the total number of Moderna vaccines administered in Texas?
CREATE TABLE vaccine_administered (patient_id INT,vaccine_name VARCHAR(255),state VARCHAR(255)); INSERT INTO vaccine_administered (patient_id,vaccine_name,state) VALUES (1,'Moderna','Texas'),(2,'Pfizer','Texas');
SELECT COUNT(*) FROM vaccine_administered WHERE vaccine_name = 'Moderna' AND state = 'Texas';
What is the total number of military innovation projects in each country, ordered alphabetically by country name?
CREATE TABLE military_innovation_2 (id INT,country VARCHAR(255),project VARCHAR(255)); INSERT INTO military_innovation_2 (id,country,project) VALUES (1,'USA','Stealth Helicopter'),(2,'Russia','Hypersonic Missile'),(3,'China','Artificial Intelligence'),(4,'USA','Directed Energy Weapon'),(5,'France','Cybersecurity Defense'),(6,'China','Quantum Computing'),(7,'Russia','Underwater Drone'),(8,'USA','Smart Munitions'),(9,'France','Electronic Warfare'),(10,'China','5G Network');
SELECT country, COUNT(project) AS total_projects FROM military_innovation_2 GROUP BY country ORDER BY country;
How many financial capability training sessions were held in each region?
CREATE TABLE financial_capability (session_id INT,region VARCHAR(255),date DATE); INSERT INTO financial_capability (session_id,region,date) VALUES (1,'North','2022-01-01'),(2,'South','2022-02-01'),(3,'East','2022-03-01'),(4,'West','2022-04-01'),(5,'North','2022-05-01'),(6,'South','2022-06-01');
SELECT region, COUNT(*) FROM financial_capability GROUP BY region;
What is the average number of publications per faculty member, for each department, in descending order of average publications?
CREATE TABLE departments (dept_id INT,dept_name VARCHAR(255));CREATE TABLE faculties (faculty_id INT,name VARCHAR(255),dept_id INT,num_publications INT);
SELECT dept_name, AVG(num_publications) AS avg_publications FROM faculties f JOIN departments d ON f.dept_id = d.dept_id GROUP BY dept_name ORDER BY avg_publications DESC;
What is the highest number of points scored by a player in a single NHL game?
CREATE TABLE highest_nhl_scores (player VARCHAR(100),team VARCHAR(50),points INT); INSERT INTO highest_nhl_scores (player,team,points) VALUES ('Wayne Gretzky','Edmonton Oilers',13),('Mario Lemieux','Pittsburgh Penguins',10);
SELECT MAX(points) FROM highest_nhl_scores;
Update the salary of the community health worker with ID 1 to $60,000.
CREATE TABLE community_health_workers (id INT,name VARCHAR(50),ethnicity VARCHAR(50),salary INT); INSERT INTO community_health_workers (id,name,ethnicity,salary) VALUES (1,'John Doe','Hispanic',50000),(2,'Jane Smith','African American',55000);
UPDATE community_health_workers SET salary = 60000 WHERE id = 1;
What is the minimum timeline for a sustainable construction project in Colorado?
CREATE TABLE Sustainable_Projects_CO (project_id INT,project_name VARCHAR(50),state VARCHAR(2),timeline INT,is_sustainable BOOLEAN); INSERT INTO Sustainable_Projects_CO VALUES (1,'Denver Eco-Tower','CO',30,true);
SELECT MIN(timeline) FROM Sustainable_Projects_CO WHERE state = 'CO' AND is_sustainable = true;
What is the average number of likes on posts by users in the United States, for users who have posted at least 5 times in the last month?
CREATE TABLE users (user_id INT,user_name VARCHAR(255),country VARCHAR(255));CREATE TABLE posts (post_id INT,user_id INT,likes INT,timestamp TIMESTAMP); INSERT INTO users (user_id,user_name,country) VALUES (1,'Alice','USA'),(2,'Bob','Canada'); INSERT INTO posts (post_id,user_id,likes,timestamp) VALUES (1,1,10,'2022-01-01 10:00:00'),(2,1,15,'2022-01-02 10:00:00'),(3,2,5,'2022-01-01 10:00:00');
SELECT AVG(posts.likes) FROM users INNER JOIN posts ON users.user_id = posts.user_id WHERE users.country = 'USA' AND COUNT(posts.post_id) >= 5 AND posts.timestamp >= NOW() - INTERVAL 1 MONTH;
How many climate adaptation projects were completed in Africa in 2019?
CREATE TABLE climate_adaptation (region VARCHAR(50),year INT,projects INT); INSERT INTO climate_adaptation (region,year,projects) VALUES ('Africa',2019,120),('Asia',2019,150),('South America',2019,100);
SELECT projects FROM climate_adaptation WHERE region = 'Africa' AND year = 2019;
What is the average weight of sustainable materials used in production per item?
CREATE TABLE Production (item_id INT,material VARCHAR(255),weight DECIMAL(5,2),sustainable BOOLEAN); INSERT INTO Production (item_id,material,weight,sustainable) VALUES (1,'Organic Cotton',2.5,true),(2,'Polyester',1.5,false),(3,'Recycled Wool',3.0,true);
SELECT AVG(weight) FROM Production WHERE sustainable = true;
What is the maximum connection speed for rural broadband customers?
CREATE TABLE broadband_subscribers (id INT,name VARCHAR(50),connection_speed FLOAT,plan_type VARCHAR(10),region VARCHAR(10)); INSERT INTO broadband_subscribers (id,name,connection_speed,plan_type,region) VALUES (1,'Priya Patel',120,'rural','Rural'); INSERT INTO broadband_subscribers (id,name,connection_speed,plan_type,region) VALUES (2,'Ravi Verma',135,'rural','Rural');
SELECT MAX(connection_speed) FROM broadband_subscribers WHERE plan_type = 'rural' AND region = 'Rural';
What is the total biomass of mammals, birds, and reptiles in the 'arctic_biodiversity' table?
CREATE TABLE arctic_biodiversity (id INTEGER,species_name TEXT,biomass FLOAT,animal_class TEXT);
SELECT animal_class, SUM(biomass) as total_biomass FROM arctic_biodiversity WHERE animal_class IN ('mammals', 'birds', 'reptiles') GROUP BY animal_class;
What is the name and location of all dams with a height greater than 50 meters in the state of California, USA?
CREATE TABLE Dams (DamID INT,Name TEXT,Height FLOAT,Location TEXT,State TEXT); INSERT INTO Dams (DamID,Name,Height,Location,State) VALUES (1,'Oroville Dam',230.0,'Oroville,California','CA');
SELECT Dams.Name, Dams.Location FROM Dams WHERE Dams.Height > 50.0 AND Dams.State = 'CA'
What is the percentage of students who have completed lifelong learning programs?
CREATE TABLE students (id INT,name VARCHAR(255),num_lifelong_learning_programs INT); CREATE TABLE lifelong_learning_programs (id INT,name VARCHAR(255),num_students INT); INSERT INTO students (id,name,num_lifelong_learning_programs) VALUES (1,'Student A',2),(2,'Student B',1),(3,'Student C',0); INSERT INTO lifelong_learning_programs (id,name,num_students) VALUES (1,'Program 1',3),(2,'Program 2',2);
SELECT 100.0 * SUM(CASE WHEN s.num_lifelong_learning_programs > 0 THEN 1 ELSE 0 END) / COUNT(s.id) AS pct_completed_programs FROM students s;
Identify the top 3 decentralized applications with the highest number of transactions, along with the total number of transactions for the smart contracts associated with each application.
CREATE TABLE dapps (dapp_id INT,dapp_name VARCHAR(255),total_transactions INT); CREATE TABLE contracts_dapps (contract_id INT,dapp_id INT); CREATE TABLE smart_contracts (contract_id INT,contract_name VARCHAR(255),total_transactions INT);
SELECT d.dapp_name, sc.contract_name, SUM(sc.total_transactions) as total_transactions FROM dapps d JOIN contracts_dapps cd ON d.dapp_id = cd.dapp_id JOIN smart_contracts sc ON cd.contract_id = sc.contract_id GROUP BY d.dapp_id, sc.contract_name ORDER BY total_transactions DESC, d.dapp_id DESC LIMIT 3;
How many energy storage projects were completed in California in 2019, by technology?
CREATE TABLE california_energy_storage (id INT PRIMARY KEY,year INT,technology VARCHAR(30),num_projects INT); INSERT INTO california_energy_storage (id,year,technology,num_projects) VALUES (1,2019,'Batteries',7),(2,2019,'Pumped Hydro',3),(3,2019,'Flywheels',2);
SELECT year, technology, SUM(num_projects) as total_projects FROM california_energy_storage WHERE year = 2019 GROUP BY year, technology;
What is the increase in employment due to cultural heritage preservation in Italy?
CREATE TABLE Employment (EmploymentID INT,Country VARCHAR(50),Change INT); INSERT INTO Employment (EmploymentID,Country,Change) VALUES (1,'Italy',500),(2,'Italy',600);
SELECT SUM(Change) FROM Employment WHERE Country = 'Italy';
How many Shariah-compliant savings accounts are offered by financial institutions in the Middle East?
CREATE TABLE products (id INT,name VARCHAR(50),type VARCHAR(20),state VARCHAR(2)); INSERT INTO products (id,name,type,state) VALUES (1,'Savings Account','Shariah','ME'); CREATE TABLE financial_institutions (id INT,name VARCHAR(50),state VARCHAR(2)); INSERT INTO financial_institutions (id,name,state) VALUES (1,'Al Baraka Bank','ME');
SELECT COUNT(products.id) FROM products INNER JOIN financial_institutions ON products.state = financial_institutions.state WHERE products.type = 'Shariah';
Calculate the total revenue for each manufacturer in the year 2020
CREATE TABLE Manufacturers (id INT,name VARCHAR(255)); INSERT INTO Manufacturers (id,name) VALUES (1,'Manufacturer A'),(2,'Manufacturer B'); CREATE TABLE Production (id INT,manufacturer_id INT,quantity INT,production_date DATE,price DECIMAL(5,2)); INSERT INTO Production (id,manufacturer_id,quantity,production_date,price) VALUES (1,1,500,'2020-01-01',10.00),(2,1,700,'2020-02-01',12.00),(3,2,300,'2020-01-15',15.00),(4,2,400,'2020-03-10',18.00);
SELECT m.name, SUM(p.quantity * p.price) as total_revenue FROM Manufacturers m JOIN Production p ON m.id = p.manufacturer_id WHERE YEAR(p.production_date) = 2020 GROUP BY m.name;
Update the 'crops' table to set the 'organic' column to '1' for all entries where the crop_name is 'Quinoa'.
CREATE TABLE crops (id INT,crop_name VARCHAR(255),organic INT); INSERT INTO crops (id,crop_name,organic) VALUES (1,'Quinoa',0),(2,'Rice',1),(3,'Wheat',0);
UPDATE crops SET organic = 1 WHERE crop_name = 'Quinoa';
Insert a new record for recycling rate in Istanbul in 2021.
CREATE TABLE recycling_rates (city VARCHAR(255),year INT,recycling_rate FLOAT);
INSERT INTO recycling_rates (city, year, recycling_rate) VALUES ('Istanbul', 2021, 25);
List the number of vehicles of each type in the Seoul Metro fleet
CREATE TABLE seoul_metro_inventory (inventory_id int,vehicle_type varchar(255),model varchar(255)); INSERT INTO seoul_metro_inventory (inventory_id,vehicle_type,model) VALUES (1,'Train','Type A'),(2,'Train','Type B'),(3,'Tram','Type C');
SELECT vehicle_type, COUNT(*) AS count FROM seoul_metro_inventory GROUP BY vehicle_type;
List the names of models with a safety score greater than 0.85.
CREATE TABLE models (model_id INT,name VARCHAR(50),safety FLOAT); INSERT INTO models (model_id,name,safety) VALUES (1,'ModelA',0.91),(2,'ModelB',0.78),(3,'ModelC',0.87),(4,'ModelD',0.65);
SELECT name FROM models WHERE safety > 0.85;
What is the rank of diversity metrics for each company?
CREATE TABLE diversity_metrics (id INT,company_id INT,gender VARCHAR(10),ethnicity VARCHAR(20),percentage DECIMAL(5,2)); INSERT INTO diversity_metrics (id,company_id,gender,ethnicity,percentage) VALUES (1,1,'Female','Caucasian',0.35),(2,1,'Male','Caucasian',0.65),(3,2,'Female','Asian',0.45),(4,2,'Male','Asian',0.55),(5,3,'Female','African',0.5),(6,3,'Male','African',0.5);
SELECT company_id, gender, ethnicity, percentage, RANK() OVER(ORDER BY percentage DESC) as rank FROM diversity_metrics;
Identify the traditional art forms that are unique to each language's native region.
CREATE TABLE TraditionalArtForms (id INT,name VARCHAR(50),language VARCHAR(50),region VARCHAR(50)); CREATE TABLE ArtPieces (id INT,art_form_id INT,site_id INT); CREATE TABLE HeritageSites (id INT,name VARCHAR(50),site_id INT,region VARCHAR(50));
SELECT TAF.name, TAF.region FROM TraditionalArtForms TAF INNER JOIN ArtPieces AP ON TAF.id = AP.art_form_id INNER JOIN HeritageSites HS ON AP.site_id = HS.id WHERE TAF.region = HS.region GROUP BY TAF.name, TAF.region HAVING COUNT(*) = 1;
Find the total grant amount awarded to faculty members in the College of Science who are not from the United States.
CREATE TABLE faculty (id INT,name VARCHAR(50),department VARCHAR(50),country VARCHAR(50)); CREATE TABLE grants (id INT,faculty_id INT,amount INT); INSERT INTO faculty VALUES (1,'Penelope','Science','USA'),(2,'Quinn','Science','Canada'),(3,'Riley','Science','USA'); INSERT INTO grants VALUES (1,1,5000),(2,1,7000),(3,2,6000),(4,3,4000);
SELECT SUM(amount) FROM grants INNER JOIN faculty ON grants.faculty_id = faculty.id WHERE country != 'USA';
What is the number of unique customers who purchased size 18 garments in Brazil?
CREATE TABLE Customers (id INT,customerID INT,country VARCHAR(50)); INSERT INTO Customers (id,customerID,country) VALUES (1,4001,'Brazil'),(2,4002,'Argentina'),(3,4003,'Brazil'),(4,4004,'Chile'); CREATE TABLE Sales (id INT,customerID INT,garmentID INT,quantity INT,saleDate DATE); INSERT INTO Sales (id,customerID,garmentID,quantity,saleDate) VALUES (1,4001,405,1,'2021-01-10'),(2,4002,406,2,'2021-02-15'),(3,4003,407,1,'2021-03-20'),(4,4004,408,3,'2021-04-12'); CREATE TABLE Garments (id INT,garmentID INT,size INT,country VARCHAR(50)); INSERT INTO Garments (id,garmentID,size,country) VALUES (1,405,18,'Brazil'),(2,406,12,'Argentina'),(3,407,10,'Chile'),(4,408,16,'Brazil');
SELECT COUNT(DISTINCT Customers.customerID) FROM Customers INNER JOIN Sales ON Customers.customerID = Sales.customerID INNER JOIN Garments ON Sales.garmentID = Garments.garmentID WHERE Garments.size = 18 AND Customers.country = 'Brazil';
Update the name of the 'Rural Electrification' project to 'Electrification for Rural Development' in the 'rural_infrastructure' table.
CREATE SCHEMA if not exists rural_development; use rural_development; CREATE TABLE IF NOT EXISTS rural_infrastructure (id INT,name VARCHAR(255),cost FLOAT,PRIMARY KEY (id)); INSERT INTO rural_infrastructure (id,name,cost) VALUES (1,'Rural Electrification',150000.00),(2,'Irrigation System',75000.00),(3,'Rural Telecommunications',200000.00);
UPDATE rural_infrastructure SET name = 'Electrification for Rural Development' WHERE name = 'Rural Electrification';
What is the highest scoring game for the Golden State Warriors?
CREATE TABLE teams (id INT,name TEXT,city TEXT); INSERT INTO teams (id,name,city) VALUES (2,'Golden State Warriors','Oakland'); CREATE TABLE games (id INT,home_team_id INT,away_team_id INT,points_home INT,points_away INT);
SELECT MAX(GREATEST(points_home, points_away)) FROM games WHERE home_team_id = (SELECT id FROM teams WHERE name = 'Golden State Warriors' AND city = 'Oakland') OR away_team_id = (SELECT id FROM teams WHERE name = 'Golden State Warriors' AND city = 'Oakland');
Count unique patients treated with CBT or medication
CREATE TABLE patients (id INT,name VARCHAR(50),treatment VARCHAR(50)); CREATE TABLE treatments (treatment VARCHAR(50),cost INT);
SELECT COUNT(DISTINCT p.name) FROM patients p JOIN treatments t ON p.treatment = t.treatment WHERE t.treatment IN ('CBT', 'medication');
List all biotech startups that received funding in the last 6 months.
CREATE SCHEMA if not exists biotech;CREATE TABLE biotech.startups_funding (id INT,startup_name VARCHAR(50),funding_date DATE,funding_amount DECIMAL(10,2));INSERT INTO biotech.startups_funding (id,startup_name,funding_date,funding_amount) VALUES (1,'StartupA','2022-01-15',5000000.00),(2,'StartupB','2022-06-30',3000000.00),(3,'StartupC','2021-12-31',2000000.00);
SELECT * FROM biotech.startups_funding WHERE funding_date >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH);
What is the minimum, maximum, and average training time for models that use different algorithms?
CREATE TABLE training_times (id INT,model_name VARCHAR(50),algorithm VARCHAR(50),training_time FLOAT); INSERT INTO training_times (id,model_name,algorithm,training_time) VALUES (1,'ModelA','Neural Network',2.1),(2,'ModelB','Decision Tree',1.5),(3,'ModelC','Neural Network',2.9);
SELECT algorithm, MIN(training_time) as min_training_time, MAX(training_time) as max_training_time, AVG(training_time) as avg_training_time FROM training_times GROUP BY algorithm;
How many community development initiatives are in the 'community_development' table?
CREATE TABLE community_development (id INT,initiative VARCHAR(50),status VARCHAR(50)); INSERT INTO community_development (id,initiative,status) VALUES (1,'Youth Education','Completed'); INSERT INTO community_development (id,initiative,status) VALUES (2,'Women Empowerment','In Progress');
SELECT COUNT(*) FROM community_development;
What is the distribution of news channels by language?
CREATE TABLE news_channels (channel_language VARCHAR(50),channel_name VARCHAR(50),country VARCHAR(50)); INSERT INTO news_channels (channel_language,channel_name,country) VALUES ('English','CNN','USA'); INSERT INTO news_channels (channel_language,channel_name,country) VALUES ('Arabic','Al Jazeera','Qatar');
SELECT channel_language, COUNT(*) as channel_count FROM news_channels GROUP BY channel_language;
What is the average number of vulnerabilities recorded per department?
CREATE TABLE department (id INT,name VARCHAR(255)); CREATE TABLE department_vulnerabilities (department_id INT,vulnerability_count INT); INSERT INTO department (id,name) VALUES (1,'Finance'),(2,'IT'); INSERT INTO department_vulnerabilities (department_id,vulnerability_count) VALUES (1,2),(2,5);
SELECT AVG(vulnerability_count) FROM department_vulnerabilities;
How many AI safety incidents have been recorded for each AI model, sorted by the number of incidents in descending order?
CREATE TABLE incidents (id INT,model_id INT,incident_type VARCHAR(255)); INSERT INTO incidents (id,model_id,incident_type) VALUES (1,1,'Unintended Consequences'),(2,2,'Lack of Robustness'),(3,1,'Lack of Robustness'),(4,3,'Unintended Consequences');
SELECT model_id, COUNT(*) as incident_count FROM incidents GROUP BY model_id ORDER BY incident_count DESC;
List cities with more than one type of renewable energy project
CREATE TABLE city_renewable_projects (city VARCHAR(50),project_type VARCHAR(50),PRIMARY KEY (city,project_type));
SELECT city FROM city_renewable_projects GROUP BY city HAVING COUNT(DISTINCT project_type) > 1;
Find the number of employees hired in each department for 2021.
CREATE TABLE departments (id INT,name VARCHAR(255));CREATE TABLE employees (id INT,department_id INT,hire_date DATE);
SELECT d.name, COUNT(e.id) AS hires FROM departments d INNER JOIN employees e ON d.id = e.department_id WHERE e.hire_date >= '2021-01-01' AND e.hire_date < '2022-01-01' GROUP BY d.name;
What is the total revenue generated from natural haircare products sold in Japan in 2019?
CREATE TABLE HaircareProducts(productId INT,productName VARCHAR(100),isNatural BOOLEAN,saleYear INT,country VARCHAR(50),price DECIMAL(5,2)); INSERT INTO HaircareProducts(productId,productName,isNatural,saleYear,country,price) VALUES (1,'Rice Water Shampoo',true,2019,'Japan',19.99),(2,'Lavender Conditioner',false,2020,'Japan',14.99);
SELECT SUM(price) FROM HaircareProducts WHERE isNatural = true AND saleYear = 2019 AND country = 'Japan';
List the products in the Inventory table that are not associated with any department.
CREATE TABLE Inventory (InventoryID INT,ProductID INT,ProductName VARCHAR(50),QuantityOnHand INT,ReorderLevel INT,Department VARCHAR(50)); INSERT INTO Inventory (InventoryID,ProductID,ProductName,QuantityOnHand,ReorderLevel,Department) VALUES (1,1001,'Eco-Friendly Parts',500,300,'Manufacturing'); INSERT INTO Inventory (InventoryID,ProductID,ProductName,QuantityOnHand,ReorderLevel,Department) VALUES (2,1002,'Recycled Materials',300,200,'Engineering'); INSERT INTO Inventory (InventoryID,ProductID,ProductName,QuantityOnHand,ReorderLevel) VALUES (3,1003,'Solar Panels',200,150);
SELECT ProductName FROM Inventory WHERE Department IS NULL;
What is the total weight of fish caught by each fishery, grouped by the fishing method and year?
CREATE TABLE FisheryData (FisheryID int,Year int,FishingMethod varchar(50),Weight int);
SELECT FishingMethod, Year, SUM(Weight) FROM FisheryData GROUP BY FishingMethod, Year ORDER BY SUM(Weight) DESC;
What is the average age of players in the 'players' table?
CREATE TABLE players (player_id INT,name VARCHAR(50),age INT,position VARCHAR(20),team_id INT);
SELECT AVG(age) FROM players;
Display the total number of items produced by each clothing manufacturer, and show only those manufacturers with less than 500 items produced.
CREATE TABLE ClothingManufacturers (manufacturer TEXT,item_id INTEGER); INSERT INTO ClothingManufacturers (manufacturer,item_id) VALUES ('Manufacturer1',111),('Manufacturer2',222),('Manufacturer3',333),('Manufacturer4',444),('Manufacturer5',555),('Manufacturer6',666);
SELECT manufacturer, COUNT(*) as total_items FROM ClothingManufacturers GROUP BY manufacturer HAVING COUNT(*) < 500;
Display unique mining permit numbers for Praseodymium.
CREATE TABLE mining_permits (id INT PRIMARY KEY,permit_number VARCHAR(255),company_name VARCHAR(255),mine_location VARCHAR(255),element_type VARCHAR(255));
SELECT DISTINCT permit_number FROM mining_permits WHERE element_type = 'Praseodymium';
What is the maximum age of athletes in the golf_teams table?
CREATE TABLE golf_teams (team_name TEXT,athlete_name TEXT,athlete_age INTEGER);
SELECT MAX(athlete_age) FROM golf_teams;
Delete the records for Texas in 2019.
CREATE TABLE water_usage(state VARCHAR(20),year INT,usage FLOAT);
DELETE FROM water_usage WHERE state='Texas' AND year=2019;
What is the maximum duration of any mental health treatment provided in Washington?
CREATE TABLE treatment_durations (patient_id INT,condition VARCHAR(50),duration INT); INSERT INTO treatment_durations (patient_id,condition,duration) VALUES (1,'Anxiety',12),(2,'Depression',10),(3,'PTSD',25),(4,'Anxiety',18),(5,'Depression',15),(6,'Bipolar Disorder',20),(7,'Washington',22); CREATE TABLE patient_location (patient_id INT,location VARCHAR(50)); INSERT INTO patient_location (patient_id,location) VALUES (1,'Washington'),(2,'Washington'),(3,'California'),(4,'Arizona'),(5,'Florida'),(6,'Texas'),(7,'Washington');
SELECT MAX(duration) FROM treatment_durations JOIN patient_location ON treatment_durations.patient_id = patient_location.patient_id WHERE location = 'Washington';
Insert a new marine species into the species table
CREATE TABLE species (id INT,name VARCHAR(255),ocean VARCHAR(255));
INSERT INTO species (id, name, ocean) VALUES (7, 'Green Sea Turtle', 'Atlantic');
Delete records in the 'renewable_mix' table where the 'energy_source' is 'Geothermal'
CREATE TABLE renewable_mix (id INT PRIMARY KEY,country VARCHAR(50),energy_source VARCHAR(50),percentage FLOAT);
DELETE FROM renewable_mix WHERE energy_source = 'Geothermal';
What is the average number of research grants awarded to faculty members in the Electrical Engineering department who have published in top-tier conferences?
CREATE TABLE faculty (id INT,name VARCHAR(50),department VARCHAR(50),last_publication_date DATE); CREATE TABLE conferences (id INT,name VARCHAR(50),tier VARCHAR(10)); CREATE TABLE research_grants (id INT,faculty_id INT,amount DECIMAL(10,2));
SELECT AVG(g.count) FROM (SELECT COUNT(*) AS count FROM research_grants rg JOIN faculty f ON rg.faculty_id = f.id WHERE f.department = 'Electrical Engineering' AND f.last_publication_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 YEAR) AND f.id IN (SELECT p.faculty_id FROM publications p JOIN conferences c ON p.conference_id = c.id WHERE c.tier = 'Top-tier')) g;
Find the average number of threat intelligence reports generated per month in 2021
CREATE TABLE threat_intelligence_reports (report_id INT,generation_date DATE); INSERT INTO threat_intelligence_reports (report_id,generation_date) VALUES (1,'2021-01-01'),(2,'2021-02-01'),(3,'2021-12-31');
SELECT AVG(num_reports_per_month) FROM (SELECT MONTH(generation_date) AS month, COUNT(*) AS num_reports_per_month FROM threat_intelligence_reports WHERE generation_date >= '2021-01-01' AND generation_date < '2022-01-01' GROUP BY month) AS subquery;
Identify the top 5 mobile network towers with the highest number of connected devices, in descending order, in the United Kingdom.
CREATE TABLE network_towers (tower_id INT,connected_devices INT,country VARCHAR(20)); INSERT INTO network_towers (tower_id,connected_devices,country) VALUES (1,50,'UK'); INSERT INTO network_towers (tower_id,connected_devices,country) VALUES (2,75,'UK');
SELECT tower_id, connected_devices FROM (SELECT tower_id, connected_devices, ROW_NUMBER() OVER (ORDER BY connected_devices DESC) AS rn FROM network_towers WHERE country = 'UK') subquery WHERE rn <= 5;
What is the minimum temperature per month in the Arctic Research Lab?
CREATE TABLE ArcticResearchLab (id INT,year INT,month INT,temperature FLOAT); INSERT INTO ArcticResearchLab (id,year,month,temperature) VALUES (1,2000,1,-10.5),(2,2000,2,-12.3),(3,2000,3,-13.1);
SELECT month, MIN(temperature) FROM ArcticResearchLab GROUP BY year, month;
What is the maximum selling price of cruelty-free skincare products in Australia, broken down by brand?
CREATE TABLE SkincareBrands (brand TEXT,product_name TEXT,price DECIMAL(5,2),sale_location TEXT); INSERT INTO SkincareBrands (brand,product_name,price,sale_location) VALUES ('Brand A','Cruelty-free Cleanser',29.99,'Australia'),('Brand B','Vegan Moisturizer',39.99,'Australia'),('Brand A','Organic Serum',49.99,'Australia'),('Brand C','Cruelty-free Toner',24.99,'Australia'),('Brand B','Natural Sunscreen',19.99,'Australia'),('Brand C','Cruelty-free Scrub',34.99,'Australia');
SELECT brand, MAX(price) FROM SkincareBrands WHERE product_name LIKE '%cruelty-free%' GROUP BY brand;
Determine the number of roads in each location in the Road_Maintenance table
CREATE TABLE Road_Maintenance (road_id INT,road_name VARCHAR(50),location VARCHAR(50),maintenance_date DATE);
SELECT location, COUNT(*) FROM Road_Maintenance GROUP BY location;
List all union names and their member counts in Canada.
CREATE TABLE UnionMembers (id INT,union_name VARCHAR(50),country VARCHAR(50),member_count INT); INSERT INTO UnionMembers (id,union_name,country,member_count) VALUES (1,'United Steelworkers','USA',200000),(2,'UNITE HERE','USA',300000),(3,'TUC','UK',6000000),(4,'CUPE','Canada',650000),(5,'USW','Canada',120000);
SELECT union_name, member_count FROM UnionMembers WHERE country = 'Canada';
How many mobile and broadband subscribers are there in each continent?
CREATE TABLE continents (continent_id INT PRIMARY KEY,continent_name VARCHAR(255)); INSERT INTO continents (continent_id,continent_name) VALUES (1,'Asia'),(2,'Africa'),(3,'Europe'),(4,'North America'),(5,'South America'),(6,'Australia'); CREATE TABLE mobile_subscribers (subscriber_id INT PRIMARY KEY,continent_id INT); INSERT INTO mobile_subscribers (subscriber_id,continent_id) VALUES (1,1),(2,1),(3,2),(4,3),(5,3),(6,4),(7,4),(8,5),(9,5),(10,6); CREATE TABLE broadband_subscribers (subscriber_id INT PRIMARY KEY,continent_id INT); INSERT INTO broadband_subscribers (subscriber_id,continent_id) VALUES (1,1),(2,2),(3,2),(4,3),(5,3),(6,4),(7,4),(8,5),(9,5),(10,6);
SELECT c.continent_name, COUNT(m.subscriber_id) + COUNT(b.subscriber_id) as total_subscribers FROM continents c LEFT JOIN mobile_subscribers m ON c.continent_id = m.continent_id LEFT JOIN broadband_subscribers b ON c.continent_id = b.continent_id GROUP BY c.continent_name;
What is the average rating of eco-friendly hotels in Tokyo?
CREATE TABLE eco_hotels (hotel_id INT,name TEXT,city TEXT,rating FLOAT); INSERT INTO eco_hotels (hotel_id,name,city,rating) VALUES (1,'Green Hotel','Tokyo',4.2),(2,'Eco Lodge','Tokyo',4.5);
SELECT AVG(rating) FROM eco_hotels WHERE city = 'Tokyo';
What is the average donation amount for each country in Q2 2022?
CREATE TABLE Donors (DonorID INT,DonorName TEXT,Country TEXT); INSERT INTO Donors (DonorID,DonorName,Country) VALUES (1,'Mateo','Argentina'); INSERT INTO Donors (DonorID,DonorName,Country) VALUES (2,'Heidi','Germany'); CREATE TABLE Donations (DonationID INT,DonorID INT,DonationAmount DECIMAL,DonationDate DATE); INSERT INTO Donations (DonationID,DonorID,DonationAmount,DonationDate) VALUES (1,1,100.00,'2022-04-15'); INSERT INTO Donations (DonationID,DonorID,DonationAmount,DonationDate) VALUES (2,2,200.00,'2022-06-30');
SELECT Donors.Country, AVG(Donations.DonationAmount) AS AverageDonationAmount FROM Donors INNER JOIN Donations ON Donors.DonorID = Donations.DonorID WHERE QUARTER(Donations.DonationDate) = 2 AND YEAR(Donations.DonationDate) = 2022 GROUP BY Donors.Country;
What is the lowest number of art collections does each artist have in 'Berlin'?
CREATE TABLE artists (id INT,city VARCHAR(20),collections INT); INSERT INTO artists (id,city,collections) VALUES (1,'Berlin',2),(2,'Berlin',3),(3,'Berlin',1),(4,'Berlin',4),(5,'Berlin',5);
SELECT city, MIN(collections) FROM artists WHERE city = 'Berlin';
Find the number of animals and conservation efforts for 'endangered_species' and 'community_outreach' programs in Asia.
CREATE TABLE endangered_species (id INT,animal_name VARCHAR(50),population INT,region VARCHAR(50)); INSERT INTO endangered_species VALUES (1,'Tiger',2000,'Asia'); CREATE TABLE community_outreach (id INT,animal_name VARCHAR(50),education INT,region VARCHAR(50)); INSERT INTO community_outreach VALUES (1,'Tiger',1000,'Asia');
SELECT population FROM endangered_species WHERE region = 'Asia' UNION SELECT education FROM community_outreach WHERE region = 'Asia';
What is the average number of artworks created per year for each artist in the 'artist_demographics' table?
CREATE TABLE artist_demographics (id INT,name VARCHAR(50),age INT,gender VARCHAR(10),nationality VARCHAR(50));CREATE TABLE artwork (id INT,title VARCHAR(50),year INT,artist_id INT,medium VARCHAR(50));
SELECT artist_id, AVG(artwork_per_year) FROM (SELECT artist_id, year, COUNT(*) AS artwork_per_year FROM artwork GROUP BY artist_id, year) AS subquery GROUP BY artist_id;
List all community development initiatives in Peru that were completed after 2017 and their completion dates.
CREATE TABLE Community_Development_Initiatives (Initiative_ID INT,Initiative_Name TEXT,Location TEXT,Status TEXT,Completion_Date DATE); INSERT INTO Community_Development_Initiatives (Initiative_ID,Initiative_Name,Location,Status,Completion_Date) VALUES (1,'Rural Water Supply Project','Peru','Completed','2018-06-30');
SELECT Initiative_Name, Completion_Date FROM Community_Development_Initiatives WHERE Status = 'Completed' AND Location = 'Peru' AND Completion_Date > '2017-12-31';
Insert new records for a cargo ship named 'Atlantic Explorer' with an ID of 4, owned by the Global Shipping company, and a capacity of 180,000.
CREATE TABLE cargo_ships (id INT,name VARCHAR(50),capacity INT,owner_id INT); INSERT INTO cargo_ships (id,name,capacity,owner_id) VALUES (1,'Sea Titan',150000,1),(2,'Ocean Marvel',200000,1),(3,'Cargo Master',120000,2); CREATE TABLE owners (id INT,name VARCHAR(50)); INSERT INTO owners (id,name) VALUES (1,'ACME Corporation'),(2,'Global Shipping');
INSERT INTO cargo_ships (id, name, capacity, owner_id) VALUES (4, 'Atlantic Explorer', 180000, (SELECT id FROM owners WHERE name = 'Global Shipping'));
What is the maximum number of streams for a single song in the rock genre?
CREATE TABLE songs (id INT,title VARCHAR(255),genre VARCHAR(255),release_year INT); CREATE TABLE streams (stream_id INT,song_id INT,user_id INT,timestamp TIMESTAMP); INSERT INTO songs (id,title,genre,release_year) VALUES (1,'Song1','Rock',2010),(2,'Song2','Hip Hop',2015),(3,'Song3','Rock',2012); INSERT INTO streams (stream_id,song_id,user_id,timestamp) VALUES (1,1,1,'2022-01-01 10:00:00'),(2,2,2,'2022-01-02 10:00:00'),(3,1,3,'2022-01-03 10:00:00'),(4,3,4,'2022-01-04 10:00:00'),(5,1,5,'2022-01-05 10:00:00'),(6,3,6,'2022-01-06 10:00:00');
SELECT MAX(streams_per_song) FROM (SELECT COUNT(*) AS streams_per_song FROM streams JOIN songs ON streams.song_id = songs.id WHERE songs.genre = 'Rock' GROUP BY songs.id) AS subquery;
What is the success rate of medication for patients with PTSD in Florida?
CREATE TABLE patients (patient_id INT,patient_name TEXT,condition TEXT,therapist_id INT,treatment TEXT,success BOOLEAN); INSERT INTO patients (patient_id,patient_name,condition,therapist_id,treatment,success) VALUES (1,'James Johnson','PTSD',1,'Medication',TRUE); INSERT INTO patients (patient_id,patient_name,condition,therapist_id,treatment,success) VALUES (2,'Sophia Lee','PTSD',1,'Meditation',FALSE); CREATE TABLE therapists (therapist_id INT,therapist_name TEXT,state TEXT); INSERT INTO therapists (therapist_id,therapist_name,state) VALUES (1,'Dr. Maria Rodriguez','Florida');
SELECT COUNT(patients.success) * 100.0 / (SELECT COUNT(*) FROM patients WHERE patients.condition = 'PTSD' AND patients.therapist_id = 1) FROM patients WHERE patients.condition = 'PTSD' AND patients.treatment = 'Medication' AND patients.therapist_id = 1;
List the top 3 most visited museums in Italy, ordered by visitor count
CREATE TABLE museums (id INT,name TEXT,country TEXT,visitors INT); INSERT INTO museums (id,name,country,visitors) VALUES (1,'Museum A','Italy',100000),(2,'Museum B','Italy',120000),(3,'Museum C','France',80000);
SELECT name, visitors FROM museums WHERE country = 'Italy' ORDER BY visitors DESC LIMIT 3;
What is the total amount of donations received by each organization in Haiti?
CREATE TABLE organizations (id INT,name TEXT,country TEXT); INSERT INTO organizations VALUES (1,'UNICEF','Haiti'); INSERT INTO organizations VALUES (2,'World Food Programme','Haiti'); CREATE TABLE donations (id INT,organization_id INT,amount DECIMAL); INSERT INTO donations VALUES (1,1,5000); INSERT INTO donations VALUES (2,1,7000); INSERT INTO donations VALUES (3,2,6000);
SELECT o.name, SUM(d.amount) as total_donations FROM organizations o INNER JOIN donations d ON o.id = d.organization_id WHERE o.country = 'Haiti' GROUP BY o.name;
Identify the safety incident with the longest resolution time.
CREATE TABLE incident_resolution (incident_id INT,resolution_time INT,timestamp TIMESTAMP); INSERT INTO incident_resolution (incident_id,resolution_time,timestamp) VALUES (1,120,'2022-01-01 00:00:00'); INSERT INTO incident_resolution (incident_id,resolution_time,timestamp) VALUES (2,150,'2022-01-02 00:00:00');
SELECT incident_id, resolution_time FROM (SELECT incident_id, resolution_time, ROW_NUMBER() OVER (ORDER BY resolution_time DESC) as row_num FROM incident_resolution) as subquery WHERE row_num = 1;
How many military equipment maintenance requests were submitted in Texas in the past year?
CREATE TABLE maintenance_requests (request_id INT,request_date DATE,request_type VARCHAR(255),state VARCHAR(255)); INSERT INTO maintenance_requests (request_id,request_date,request_type,state) VALUES (1,'2021-01-01','Equipment Maintenance','Texas'); INSERT INTO maintenance_requests (request_id,request_date,request_type,state) VALUES (2,'2021-02-01','Facility Maintenance','Texas');
SELECT COUNT(*) as total_requests FROM maintenance_requests WHERE request_type = 'Equipment Maintenance' AND state = 'Texas' AND request_date >= DATEADD(year, -1, GETDATE());
What was the total revenue for all artworks sold by country in 2021?
CREATE TABLE ArtWorkSales (artworkID INT,country VARCHAR(50),saleDate DATE,revenue DECIMAL(10,2));
SELECT country, SUM(revenue) FROM ArtWorkSales WHERE YEAR(saleDate) = 2021 GROUP BY country;
What is the minimum weight of fish in the 'Tilapia' species?
CREATE TABLE Farm (id INT,species TEXT,weight FLOAT,age INT); INSERT INTO Farm (id,species,weight,age) VALUES (1,'Tilapia',500.3,2),(2,'Salmon',300.1,1),(3,'Tilapia',600.5,3),(4,'Tilapia',700.2,2),(5,'Tilapia',800.1,4);
SELECT MIN(weight) FROM Farm WHERE species = 'Tilapia';
List the unique industries for startups that have received funding from both VC Firm A and VC Firm B.
CREATE TABLE startup (id INT,industry TEXT,funding_firm TEXT); INSERT INTO startup (id,industry,funding_firm) VALUES (1,'Software','VC Firm A'),(2,'Hardware','VC Firm B'),(3,'Healthcare','VC Firm A'),(4,'AI','VC Firm B');
SELECT industry FROM startup WHERE funding_firm IN ('VC Firm A', 'VC Firm B') GROUP BY industry HAVING COUNT(DISTINCT funding_firm) = 2;
Which vehicles were showcased at the last auto show in Shanghai?
CREATE TABLE AutoShowInfo (Show VARCHAR(50),City VARCHAR(50),Year INT,Vehicle VARCHAR(50)); INSERT INTO AutoShowInfo (Show,City,Year,Vehicle) VALUES ('Auto China','Shanghai',2021,'Tesla Model Y'),('Auto China','Shanghai',2021,'NIO ES8'),('Auto China','Shanghai',2021,'XPeng P7'),('Paris Motor Show','Paris',2021,'Peugeot e-208'),('Paris Motor Show','Paris',2021,'Renault ZOE');
SELECT Vehicle FROM AutoShowInfo WHERE Show = 'Auto China' AND City = 'Shanghai' AND Year = 2021;
What is the maximum response time for emergency calls in the city of New York, and which type of emergency has the highest response time?
CREATE TABLE ny_emergency_responses (id INT,city VARCHAR(20),type VARCHAR(20),response_time INT); INSERT INTO ny_emergency_responses (id,city,type,response_time) VALUES (1,'New York','emergency',12); INSERT INTO ny_emergency_responses (id,city,type,response_time) VALUES (2,'New York','fire',18);
SELECT type, MAX(response_time) FROM ny_emergency_responses WHERE city = 'New York' GROUP BY type ORDER BY MAX(response_time) DESC LIMIT 1
What is the average depth at which sharks are found in the Sargasso Sea?
CREATE TABLE sharks (id INT,species VARCHAR(255),avg_depth FLOAT,region VARCHAR(255)); INSERT INTO sharks (id,species,avg_depth,region) VALUES (1,'Hammerhead Shark',200,'Sargasso Sea');
SELECT AVG(avg_depth) FROM sharks WHERE region = 'Sargasso Sea';
List the number of IoT sensors in coffee plantations and tea gardens in Japan.
CREATE TABLE IoT_Sensors (farm_type VARCHAR(30),country VARCHAR(20),num_sensors INTEGER); INSERT INTO IoT_Sensors (farm_type,country,num_sensors) VALUES ('Coffee Plantation','Japan',200),('Coffee Plantation','Japan',220),('Tea Garden','Japan',250),('Tea Garden','Japan',280),('Tea Garden','Japan',300);
SELECT farm_type, SUM(num_sensors) FROM IoT_Sensors WHERE country = 'Japan' AND farm_type IN ('Coffee Plantation', 'Tea Garden') GROUP BY farm_type;
List all infectious diseases with their respective cases in cities with a population greater than 1,000,000.
CREATE TABLE infectious_diseases (disease VARCHAR(255),cases INT,city VARCHAR(255),population INT); INSERT INTO infectious_diseases (disease,cases,city,population) VALUES ('Influenza',50,'Chicago',2700000); INSERT INTO infectious_diseases (disease,cases,city,population) VALUES ('COVID-19',100,'Chicago',2700000); CREATE TABLE cities (name VARCHAR(255),population INT); INSERT INTO cities (name,population) VALUES ('Chicago',2700000); INSERT INTO cities (name,population) VALUES ('New York',8500000);
SELECT disease, cases FROM infectious_diseases, cities WHERE infectious_diseases.city = cities.name AND population > 1000000;
How many new members joined the art museum in the past quarter?
CREATE TABLE MemberRegistry (memberID INT,joinDate DATE); INSERT INTO MemberRegistry (memberID,joinDate) VALUES (1,'2022-01-05'),(2,'2022-04-12'),(3,'2022-07-29');
SELECT COUNT(*) FROM MemberRegistry WHERE joinDate >= '2022-01-01' AND joinDate <= '2022-03-31';
What is the total number of virtual tours offered in Paris?
CREATE TABLE virtual_tours (tour_id INT,name TEXT,site TEXT); INSERT INTO virtual_tours (tour_id,name,site) VALUES (1,'Paris Virtual Tour 1','Paris'); INSERT INTO virtual_tours (tour_id,name,site) VALUES (2,'Paris Virtual Tour 2','Paris');
SELECT COUNT(*) FROM virtual_tours WHERE site = 'Paris';
List all mobile subscribers in the Asia-Pacific region who have used their data services more than 50% of the time in the last month.
CREATE TABLE mobile_subscribers (id INT,region VARCHAR(20),data_usage INT,usage_date DATE);
SELECT m.id, m.region, m.data_usage, m.usage_date FROM mobile_subscribers m INNER JOIN (SELECT subscriber_id, SUM(data_usage) AS total_usage FROM mobile_subscribers WHERE usage_date > DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY subscriber_id) d ON m.id = d.subscriber_id WHERE m.region = 'Asia-Pacific' AND m.data_usage > 0.5 * d.total_usage;
What was the landfill capacity utilization in 2021?
CREATE TABLE landfill_capacity (year INT,capacity INT),landfill_utilization (year INT,utilization INT); INSERT INTO landfill_capacity (year,capacity) VALUES (2018,12000),(2019,13000),(2020,14000),(2021,15000); INSERT INTO landfill_utilization (year,utilization) VALUES (2018,8000),(2019,9000),(2020,10000),(2021,NULL);
SELECT utilization FROM landfill_utilization WHERE year = 2021;
What is the average playtime for simulation games?
CREATE TABLE GameData (GameID INT,GameType VARCHAR(10),Playtime INT); INSERT INTO GameData (GameID,GameType,Playtime) VALUES (1,'Adventure',20),(2,'Strategy',30),(3,'Simulation',40);
SELECT AVG(Playtime) FROM GameData WHERE GameType = 'Simulation'
What is the total quantity of 'Corn' and 'Soybeans' harvested in 'Indigenous Communities' in the USA for 2020?
CREATE TABLE US_Harvest (community VARCHAR(30),crop VARCHAR(20),quantity INT,year INT); INSERT INTO US_Harvest (community,crop,quantity,year) VALUES ('Community1','Corn',5000,2020),('Community1','Soybeans',3000,2020);
SELECT SUM(uh.quantity) as total_quantity FROM US_Harvest uh WHERE uh.crop IN ('Corn', 'Soybeans') AND uh.community LIKE 'Indigenous%' AND uh.year = 2020;