instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the average depth of all trenches?
CREATE TABLE ocean_trenches (id INT,name TEXT,avg_depth FLOAT); INSERT INTO ocean_trenches (id,name,avg_depth) VALUES (1,'Mariana Trench',8176),(2,'Tonga Trench',7373),(3,'Kermadec Trench',7236);
SELECT AVG(avg_depth) FROM ocean_trenches;
How many shipwrecks have been recorded in the Caribbean Sea?
CREATE TABLE caribbean_sea (id INT,year INT,shipwreck TEXT); INSERT INTO caribbean_sea (id,year,shipwreck) VALUES (1,1650,'Santa Maria');
SELECT COUNT(shipwreck) FROM caribbean_sea;
Find the number of players who have played a game in each region and the percentage of players who have played a game in that region, ordered by the percentage in descending order.
CREATE TABLE players (id INT,region VARCHAR(255)); INSERT INTO players (id,region) VALUES (1,'NA'),(2,'EU'),(3,'ASIA'),(4,'NA'),(5,'EU'),(6,'ASIA'),(7,'NA'),(8,'EU'); CREATE TABLE games (id INT,player_id INT,name VARCHAR(255)); INSERT INTO games (id,player_id,name) VALUES (1,1,'Game1'),(2,2,'Game2'),(3,3,'Game3'),(4,4,'Game1'),(5,5,'Game2'),(6,6,'Game3'),(7,7,'Game4'),(8,8,'Game4');
SELECT region, COUNT(DISTINCT players.id) as num_players, COUNT(DISTINCT players.id) * 100.0 / (SELECT COUNT(DISTINCT players.id) FROM players) as percentage FROM players JOIN games ON players.id = games.player_id GROUP BY region ORDER BY percentage DESC;
Delete the planet 'Pluto' from the table
CREATE TABLE planets (id INT PRIMARY KEY,name VARCHAR(50),distance_to_sun FLOAT); INSERT INTO planets (id,name,distance_to_sun) VALUES (1,'Mercury',0.39),(2,'Venus',0.72),(3,'Earth',1),(4,'Mars',1.52),(5,'Pluto',3.67);
DELETE FROM planets WHERE name = 'Pluto';
Delete least popular tracks released before 2000
CREATE TABLE tracks (id INT PRIMARY KEY,title VARCHAR(255),release_year INT,popularity INT,album_id INT,FOREIGN KEY (album_id) REFERENCES albums(id));
DELETE FROM tracks WHERE release_year < 2000 AND popularity < (SELECT AVG(popularity) FROM tracks WHERE release_year >= 2000);
What is the minimum number of military technology patents filed by Russia in a single year?
CREATE TABLE tech_patents (country VARCHAR(255),year INT,num_patents INT); INSERT INTO tech_patents (country,year,num_patents) VALUES ('Russia',2015,500),('Russia',2016,600),('China',2015,1000),('China',2016,1200);
SELECT MIN(num_patents) FROM tech_patents WHERE country = 'Russia';
What is the name of the vulnerability with the highest severity in the 'vulnerabilities' table?
CREATE TABLE vulnerabilities (id INT,name VARCHAR(255),severity VARCHAR(50),description TEXT,affected_products TEXT,date_discovered DATE);
SELECT name FROM vulnerabilities WHERE severity = (SELECT MAX(severity) FROM vulnerabilities);
How many donors are there in each country, ranked by the total donation amount?
CREATE TABLE Donations (DonationID int,DonorID int,Country varchar(50),DonationAmount numeric); INSERT INTO Donations (DonationID,DonorID,Country,DonationAmount) VALUES (1,1,'USA',500),(2,1,'Canada',300),(3,2,'Germany',800),(4,2,'France',900),(5,3,'India',700);
SELECT Country, COUNT(DonorID) NumDonors, SUM(DonationAmount) TotalDonations, RANK() OVER (ORDER BY SUM(DonationAmount) DESC) DonorRank FROM Donations GROUP BY Country;
What is the average number of visitors per exhibition in Beijing, grouped by year?
CREATE TABLE Exhibitions (id INT,city VARCHAR(255),visitors INT,year INT); INSERT INTO Exhibitions (id,city,visitors,year) VALUES (1,'New York',2500,2018),(2,'Los Angeles',1800,2019),(3,'Chicago',2200,2018),(4,'Beijing',1500,2018),(5,'Beijing',2000,2019),(6,'Beijing',1200,2019);
SELECT year, AVG(visitors) FROM Exhibitions WHERE city = 'Beijing' GROUP BY year;
What is the average budget allocated for accessible technology initiatives by organizations in the healthcare sector?
CREATE TABLE org_accessibility_budget (org_name TEXT,sector TEXT,budget_accessible_tech INT); INSERT INTO org_accessibility_budget (org_name,sector,budget_accessible_tech) VALUES ('OrgA','healthcare',300000),('OrgB','healthcare',400000),('OrgC','healthcare',500000);
SELECT AVG(budget_accessible_tech) FROM org_accessibility_budget WHERE sector = 'healthcare';
How many projects are there in the transportation division?
CREATE TABLE Projects (id INT,division VARCHAR(20)); INSERT INTO Projects (id,division) VALUES (1,'water'),(2,'transportation'),(3,'water'),(4,'transportation'),(5,'transportation'),(6,'transportation');
SELECT COUNT(*) FROM Projects WHERE division = 'transportation';
What is the total number of cultural heritage sites in the American region?
CREATE TABLE sites_america (site_id INT,site_name VARCHAR(255),country_name VARCHAR(255),region VARCHAR(255)); INSERT INTO sites_america (site_id,site_name,country_name,region) VALUES (1,'Statue of Liberty','USA','America');
SELECT COUNT(*) FROM sites_america WHERE region = 'America';
How many cases were handled by attorneys from the firm 'Smith & Johnson'?
CREATE TABLE firms (firm_id INT,name TEXT); INSERT INTO firms (firm_id,name) VALUES (1,'Smith & Johnson'); CREATE TABLE attorneys (attorney_id INT,firm_id INT); CREATE TABLE cases (case_id INT,attorney_id INT);
SELECT COUNT(DISTINCT cases.case_id) FROM cases INNER JOIN attorneys ON cases.attorney_id = attorneys.attorney_id INNER JOIN firms ON attorneys.firm_id = firms.firm_id WHERE firms.name = 'Smith & Johnson';
What is the total revenue generated from sustainable fashion products in Q4 2021?
CREATE TABLE sales (id INT,product_type VARCHAR(20),date DATE,revenue DECIMAL); INSERT INTO sales (id,product_type,date,revenue) VALUES (1,'sustainable','2021-10-01',100.00),(2,'regular','2021-10-02',200.00),(3,'sustainable','2021-11-01',300.00),(4,'regular','2021-11-02',400.00),(5,'sustainable','2021-12-01',500.00);
SELECT SUM(revenue) FROM sales WHERE product_type = 'sustainable' AND date >= '2021-10-01' AND date < '2022-01-01';
Find the bike sharing programs with more bikes than scooter sharing programs.
CREATE TABLE BikeSharing (id INT,company VARCHAR(20),bike_type VARCHAR(20),num_bikes INT); INSERT INTO BikeSharing (id,company,bike_type,num_bikes) VALUES (1,'CitiBike','Standard',1000),(2,'Jump','E-Bike',500),(3,'Lime','Standard',300); CREATE TABLE ScooterSharing (id INT,company VARCHAR(20),scooter_type VARCHAR(20),num_scooters INT); INSERT INTO ScooterSharing (id,company,scooter_type,num_scooters) VALUES (1,'Bird','E-Scooter',700),(2,'Lime','E-Scooter',800),(3,'Spin','E-Scooter',600);
SELECT company FROM BikeSharing WHERE num_bikes > (SELECT SUM(num_scooters) FROM ScooterSharing);
List the number of mental health facilities in each state
CREATE TABLE mental_health_facilities(id INT,name TEXT,state TEXT,type TEXT); INSERT INTO mental_health_facilities(id,name,state,type) VALUES (1,'Mental Health Hospital','California','Hospital'),(2,'Community Mental Health Center','California','Community Health Center'),(3,'Mental Health Clinic','New York','Community Clinic'),(4,'Mental Health Hospital','New York','Hospital'),(5,'Mental Health Clinic','Texas','Community Clinic'),(6,'Mental Health Hospital','Texas','Hospital');
SELECT state, COUNT(*) FROM mental_health_facilities GROUP BY state;
What is the total revenue for 'Budget' hotels in 'Asia' for '2022'?
CREATE TABLE hotels (hotel_type VARCHAR(20),region VARCHAR(20),revenue DECIMAL(10,2),timestamp TIMESTAMP); INSERT INTO hotels (hotel_type,region,revenue,timestamp) VALUES ('Budget','Asia',5000.00,'2022-01-01 00:00:00'),('Luxury','Europe',8000.00,'2022-02-01 00:00:00');
SELECT SUM(revenue) FROM hotels WHERE hotel_type = 'Budget' AND region = 'Asia' AND EXTRACT(YEAR FROM timestamp) = 2022;
How many unique heroes have been played in competitive mode in each region?
CREATE TABLE Games (id INT,name VARCHAR(50),mode ENUM('Singleplayer','Multiplayer','Competitive')); INSERT INTO Games (id,name,mode) VALUES (1,'Game1','Competitive'),(2,'Game2','Singleplayer'),(3,'Game3','Multiplayer'),(4,'Game4','Competitive'); CREATE TABLE Heroes (id INT,game_id INT,name VARCHAR(50)); INSERT INTO Heroes (id,game_id,name) VALUES (1,1,'Hero1'),(2,1,'Hero2'),(3,1,'Hero3'),(4,1,'Hero4'),(5,2,'Hero5'),(6,2,'Hero6'),(7,4,'Hero1'),(8,4,'Hero2'),(9,4,'Hero3'); CREATE TABLE Competitive_Matches (id INT,player_id INT,hero_id INT,game_id INT); INSERT INTO Competitive_Matches (id,player_id,hero_id,game_id) VALUES (1,1,1,1),(2,1,2,1),(3,2,1,1),(4,2,3,1),(5,3,2,1),(6,3,4,1),(7,4,3,4),(8,4,1,4),(9,5,2,4),(10,5,4,4);
SELECT R.name AS region, COUNT(DISTINCT H.id) AS unique_heroes FROM Competitive_Matches CM JOIN Games G ON CM.game_id = G.id JOIN Heroes H ON CM.hero_id = H.id JOIN Regions R ON G.mode = 'Competitive' GROUP BY R.name;
What is the average cultural competency score per state?
CREATE TABLE cultural_competency_scores (state VARCHAR(2),score INT);
SELECT state, AVG(score) FROM cultural_competency_scores GROUP BY state;
Which clinical trials have a 'COMPLETED' status for drug 'D002'?
CREATE TABLE clinical_trials (drug_id VARCHAR(10),trial_status VARCHAR(10));
SELECT * FROM clinical_trials WHERE drug_id = 'D002' AND trial_status = 'COMPLETED';
What is the percentage of network infrastructure investments in African countries compared to Asian countries?
CREATE TABLE network_investments (investment_id INT,investment_amount FLOAT,country VARCHAR(255)); INSERT INTO network_investments (investment_id,investment_amount,country) VALUES (1,1000000,'Nigeria'),(2,800000,'India'),(3,1200000,'Egypt'),(4,700000,'China');
SELECT (SUM(CASE WHEN country IN ('Nigeria', 'Egypt') THEN investment_amount ELSE 0 END) / SUM(investment_amount)) * 100 AS african_percentage, (SUM(CASE WHEN country IN ('India', 'China') THEN investment_amount ELSE 0 END) / SUM(investment_amount)) * 100 AS asian_percentage FROM network_investments;
How many cases were handled by female attorneys in 'Texas'?
CREATE TABLE attorneys (id INT,name VARCHAR(20),gender VARCHAR(6),state VARCHAR(2)); INSERT INTO attorneys (id,name,gender,state) VALUES (1,'Garcia','Female','TX'),(2,'Smith','Male','NY'),(3,'Kim','Male','IL'); CREATE TABLE cases (id INT,attorney_id INT,case_type VARCHAR(10));
SELECT COUNT(*) FROM cases INNER JOIN attorneys ON cases.attorney_id = attorneys.id WHERE attorneys.gender = 'Female' AND attorneys.state = 'TX';
Who were the top 5 donors for the education department in Q1 2022?
CREATE TABLE Donations (Donor VARCHAR(50),Department VARCHAR(50),Donation DECIMAL(10,2),DonationDate DATE); INSERT INTO Donations (Donor,Department,Donation,DonationDate) VALUES ('Alice Johnson','Education',12000,'2022-02-28'),('Mohammed Ahmed','Healthcare',10000,'2022-01-03');
SELECT Donor, SUM(Donation) as TotalDonated FROM Donations WHERE DonationDate BETWEEN '2022-01-01' AND '2022-03-31' AND Department = 'Education' GROUP BY Donor ORDER BY TotalDonated DESC LIMIT 5;
What is the total number of hospitals and clinics in the rural healthcare system?
CREATE TABLE Hospitals (ID INT,Name TEXT,Location TEXT,Type TEXT); INSERT INTO Hospitals VALUES (1,'Rural General Hospital','Smalltown','Hospital'); INSERT INTO Hospitals VALUES (2,'Rural Health Clinic','Village','Clinic');
SELECT COUNT(*) FROM Hospitals WHERE Type IN ('Hospital', 'Clinic');
How many patients have been treated with cognitive behavioral therapy (CBT) in New York?
CREATE TABLE patients (id INT,name TEXT,state TEXT);CREATE TABLE treatments (id INT,patient_id INT,therapy TEXT);INSERT INTO patients (id,name,state) VALUES (1,'Fatima Patel','New York'),(2,'Raj Patel','New York');INSERT INTO treatments (id,patient_id,therapy) VALUES (1,1,'CBT'),(2,2,'CBT');
SELECT COUNT(DISTINCT patients.id) FROM patients INNER JOIN treatments ON patients.id = treatments.patient_id WHERE patients.state = 'New York' AND treatments.therapy = 'CBT';
List all investments with a risk level above 5 made by Impact Fund 1
CREATE TABLE investments (id INT,fund_name VARCHAR(255),company_name VARCHAR(255),risk_level INT);
SELECT * FROM investments WHERE fund_name = 'Impact Fund 1' AND risk_level > 5;
What is the average fare for bus routes in the 'west' region?
CREATE TABLE bus_routes (route_id INT,region VARCHAR(10)); INSERT INTO bus_routes (route_id,region) VALUES (1,'west'),(2,'west'),(3,'east'); CREATE TABLE fares (fare_id INT,route_id INT,price DECIMAL(5,2)); INSERT INTO fares (fare_id,route_id,price) VALUES (1,1,2.50),(2,1,2.50),(3,2,3.00),(4,3,1.50);
SELECT AVG(f.price) FROM fares f JOIN bus_routes br ON f.route_id = br.route_id WHERE br.region = 'west';
Create a table named 'audience_demographics' with columns 'gender', 'age_range', 'ethnicity', and 'zip_code'
CREATE TABLE audience_demographics (gender VARCHAR(255),age_range VARCHAR(255),ethnicity VARCHAR(255),zip_code VARCHAR(255));
CREATE TABLE audience_demographics (gender VARCHAR(255), age_range VARCHAR(255), ethnicity VARCHAR(255), zip_code VARCHAR(255));
Delete all artists who are younger than 25.
CREATE TABLE artists (artist_id INT,age INT); INSERT INTO artists (artist_id,age) VALUES (1,35),(2,28),(3,42),(4,22),(5,32);
DELETE FROM artists WHERE age < 25;
What is the average weight of organic ingredients in lotion sold in Germany?
CREATE TABLE organic_ingredients(product_name TEXT,organic_weight DECIMAL(5,2),ingredient TEXT,country TEXT); INSERT INTO organic_ingredients VALUES ('Lotion',1.0,'Organic Aloe Vera','Germany'); INSERT INTO organic_ingredients VALUES ('Lotion',0.5,'Organic Coconut Oil','Germany'); INSERT INTO organic_ingredients VALUES ('Lotion',0.5,'Organic Shea Butter','Germany');
SELECT AVG(organic_weight) FROM organic_ingredients WHERE country = 'Germany' AND ingredient LIKE 'Organic%';
Which player scored the most points in a single NBA game in the 2020-2021 season?
CREATE TABLE nba_scores (game_id INT,player_name VARCHAR(50),team VARCHAR(50),points INT);
SELECT player_name, points FROM nba_scores WHERE points = (SELECT MAX(points) FROM nba_scores WHERE season_year = 2021) AND season_year = 2021;
What is the maximum budget for AI projects?
CREATE TABLE ai_projects (sector VARCHAR(20),budget INT); INSERT INTO ai_projects (sector,budget) VALUES ('Education',200000),('Healthcare',500000),('Finance',1000000);
SELECT MAX(budget) FROM ai_projects;
What is the number of unique factories producing sustainable materials, by continent?
CREATE SCHEMA ethical_fashion; CREATE TABLE factories (factory_id INT,country VARCHAR(255),continent VARCHAR(255),produces_sustainable BOOLEAN); INSERT INTO factories VALUES (1,'USA','North America',TRUE),(2,'Mexico','North America',FALSE),(3,'Brazil','South America',TRUE),(4,'Argentina','South America',FALSE),(5,'China','Asia',FALSE),(6,'India','Asia',TRUE);
SELECT continent, COUNT(DISTINCT factory_id) FROM ethical_fashion.factories WHERE produces_sustainable = TRUE GROUP BY continent;
How many spacecraft were built by SpaceTech Incorporated?
CREATE TABLE spacecraft (id INT,name VARCHAR(255),manufacturer VARCHAR(255)); INSERT INTO spacecraft (id,name,manufacturer) VALUES (1,'Voyager 1','SpaceTech Incorporated');
SELECT COUNT(*) FROM spacecraft WHERE manufacturer = 'SpaceTech Incorporated';
What is the total number of satellites deployed per year and the percentage change in satellite deployment from the previous year, by country?
CREATE SCHEMA Satellite;CREATE TABLE Satellite.SatelliteDeployment (country VARCHAR(50),year INT,num_satellites INT);INSERT INTO Satellite.SatelliteDeployment (country,year,num_satellites) VALUES ('USA',2010,100),('China',2010,50),('Russia',2010,40),('India',2010,30),('USA',2011,120),('China',2011,60),('Russia',2011,45),('India',2011,35);
SELECT s1.country, s1.year, s1.num_satellites, (s1.num_satellites - COALESCE(s2.num_satellites, 0)) * 100.0 / COALESCE(s2.num_satellites, 1) AS percentage_change FROM Satellite.SatelliteDeployment s1 LEFT JOIN Satellite.SatelliteDeployment s2 ON s1.country = s2.country AND s1.year = s2.year + 1;
What is the maximum number of clinical trials and their outcomes for each drug that has been approved by the FDA, including the drug name and approval date?
CREATE TABLE drugs (drug_id INT,name VARCHAR(255),approval_date DATE);CREATE TABLE clinical_trials (trial_id INT,drug_id INT,outcome VARCHAR(255));
SELECT d.name, d.approval_date, COUNT(ct.trial_id) as num_trials, MAX(ct.trial_id) as max_trial, STRING_AGG(ct.outcome, ',') as outcomes FROM drugs d JOIN clinical_trials ct ON d.drug_id = ct.drug_id GROUP BY d.name, d.approval_date;
Delete user comments older than 30 days
CREATE TABLE comments (id INT,post_id INT,user_id INT,comment TEXT,posted_at TIMESTAMP); INSERT INTO comments (id,post_id,user_id,comment,posted_at) VALUES (1,1,3,'Nice post!','2021-02-15 10:31:00'),(2,2,4,'Great content!','2021-01-18 14:46:00');
DELETE FROM comments WHERE posted_at < DATE_SUB(CURRENT_TIMESTAMP(), INTERVAL 30 DAY);
Display the top 5 accounts with the most staked tokens in the Tezos blockchain.
CREATE TABLE tezos_accounts (account_address VARCHAR(36),staked_tokens INTEGER);
SELECT account_address, staked_tokens FROM tezos_accounts ORDER BY staked_tokens DESC LIMIT 5;
List the top 5 producers of corn by yield in the 'agriculture' database.
CREATE TABLE crop (id INT,type VARCHAR(255),yield FLOAT); INSERT INTO crop (id,type,yield) VALUES (1,'corn',150.3),(2,'wheat',120.5),(3,'rice',180.7),(4,'corn',165.2),(5,'corn',145.8);
SELECT type, yield FROM crop WHERE type = 'corn' ORDER BY yield DESC LIMIT 5;
How many users live in each country?
CREATE TABLE users (id INT,age INT,gender TEXT,country TEXT); INSERT INTO users (id,age,gender,country) VALUES (1,25,'female','United States'),(2,35,'male','Canada'),(3,30,'non-binary','Mexico'),(4,45,'male','Brazil'),(5,50,'female','Argentina');
SELECT country, COUNT(DISTINCT id) as user_count FROM users GROUP BY country;
List the names and number of works for all artists who have created more works than 'Degas'.
CREATE TABLE artists (id INT,name TEXT,num_works INT); INSERT INTO artists (id,name,num_works) VALUES (1,'Picasso',550),(2,'Van Gogh',210),(3,'Monet',690),(4,'Degas',400);
SELECT name, num_works FROM artists WHERE num_works > (SELECT num_works FROM artists WHERE name = 'Degas');
How many buildings of each type are there?
CREATE TABLE Buildings (BuildingID INT,BuildingType VARCHAR(50)); INSERT INTO Buildings (BuildingID,BuildingType) VALUES (1,'Residential'),(2,'Commercial'),(3,'Residential');
SELECT BuildingType, COUNT(*) AS BuildingCount FROM Buildings GROUP BY BuildingType;
What is the total number of international tourists visiting Canada, grouped by continent of origin?
CREATE TABLE visitors (visitor_country VARCHAR(50),continent VARCHAR(50),total_visits INT); INSERT INTO visitors (visitor_country,continent,total_visits) VALUES ('Canada','North America',25000);
SELECT continent, SUM(total_visits) FROM visitors WHERE visitor_country = 'Canada' GROUP BY continent;
How many new donors from India made a donation in 2021?
CREATE TABLE donors (id INT,name TEXT,country TEXT,signup_date DATE); CREATE TABLE donations (id INT,donor_id INT,amount DECIMAL(10,2),donation_date DATE); INSERT INTO donors (id,name,country,signup_date) VALUES (1,'Rajesh Patel','India','2021-01-10'),(2,'Priya Gupta','India','2020-12-02'),(3,'John Smith','Canada','2021-06-15'),(4,'Kim Lee','South Korea','2021-08-28'); INSERT INTO donations (id,donor_id,amount,donation_date) VALUES (1,1,100.00,'2021-02-05'),(2,1,200.00,'2021-09-15'),(3,3,50.00,'2021-07-30'),(4,4,75.00,'2021-11-10');
SELECT COUNT(DISTINCT donors.id) FROM donors INNER JOIN donations ON donors.id = donations.donor_id WHERE donors.country = 'India' AND YEAR(donation_date) = 2021 AND donors.signup_date <= donation_date;
How many renewable energy projects are there in each project type in the 'RenewableEnergyProjects' table?
CREATE TABLE RenewableEnergyProjects (id INT,project_name VARCHAR(50),city VARCHAR(50),project_type VARCHAR(50));
SELECT project_type, COUNT(*) as project_count FROM RenewableEnergyProjects GROUP BY project_type;
What is the maximum soil moisture value in Kenya this month?
CREATE TABLE if NOT EXISTS soil_moisture (id int,location varchar(50),moisture float,timestamp datetime); INSERT INTO soil_moisture (id,location,moisture,timestamp) VALUES (1,'Kenya',45.3,'2022-02-03 10:00:00');
SELECT MAX(moisture) FROM soil_moisture WHERE location = 'Kenya' AND timestamp >= DATE_SUB(NOW(), INTERVAL 1 MONTH);
What is the maximum salary of workers in the 'retail' industry who are part of a union?
CREATE TABLE workers (id INT,name VARCHAR(255),industry VARCHAR(255),salary DECIMAL(10,2)); CREATE TABLE unions (id INT,worker_id INT,union VARCHAR(255)); INSERT INTO workers (id,name,industry,salary) VALUES (1,'Bob Smith','retail',45000.00);
SELECT MAX(workers.salary) FROM workers INNER JOIN unions ON workers.id = unions.worker_id WHERE workers.industry = 'retail' AND unions.union = 'yes';
What is the average billing amount for cases in the 'Civil' category?
CREATE TABLE cases (case_id INT,category VARCHAR(20),billing_amount INT); INSERT INTO cases (case_id,category,billing_amount) VALUES (1,'Civil',5000),(2,'Criminal',7000),(3,'Civil',4000);
SELECT AVG(billing_amount) FROM cases WHERE category = 'Civil';
What's the total number of vegetarian and vegan entrees in the menu?
CREATE TABLE menu (item_id INT,item_name VARCHAR(50),category VARCHAR(50),cuisine VARCHAR(50),price DECIMAL(5,2));
SELECT COUNT(*) FROM menu WHERE category IN ('vegetarian', 'vegan');
Identify the maritime laws governing the Indian and Pacific oceans that have penalties exceeding $100,000.
CREATE TABLE maritime_laws (id INT,ocean VARCHAR(255),law VARCHAR(255),penalty INT); INSERT INTO maritime_laws VALUES (1,'Indian Ocean','Law A',50000); INSERT INTO maritime_laws VALUES (2,'Pacific Ocean','Law B',150000); INSERT INTO maritime_laws VALUES (3,'Indian Ocean','Law C',200000);
SELECT law FROM maritime_laws WHERE ocean IN ('Indian Ocean', 'Pacific Ocean') AND penalty > 100000;
What is the total cost of manufacturing spacecrafts for each country?
CREATE TABLE SpacecraftManufacturing (id INT,country VARCHAR,cost FLOAT);
SELECT country, SUM(cost) FROM SpacecraftManufacturing GROUP BY country;
What is the total number of construction permits issued in the state of Washington?
CREATE TABLE ConstructionPermits (PermitID INT,State TEXT,IssueDate DATE); INSERT INTO ConstructionPermits (PermitID,State,IssueDate) VALUES (101,'Washington','2023-01-01'),(102,'Oregon','2023-01-02'),(103,'Washington','2023-01-03');
SELECT COUNT(PermitID) FROM ConstructionPermits WHERE State = 'Washington';
How many episodes of Mexican TV shows have more than 1 million views?
CREATE TABLE tv_show (id INT PRIMARY KEY,title VARCHAR(255),country VARCHAR(255),num_episodes INT); CREATE TABLE episode (id INT PRIMARY KEY,tv_show_id INT,episode_number INT,views INT); INSERT INTO tv_show (id,title,country,num_episodes) VALUES (1,'TVShowA','Mexico',12),(2,'TVShowB','Mexico',15),(3,'TVShowC','Mexico',20); INSERT INTO episode (id,tv_show_id,episode_number,views) VALUES (1,1,1,1200000),(2,1,2,1500000),(3,2,1,1000000),(4,3,1,2000000),(5,3,2,1800000);
SELECT COUNT(*) FROM episode WHERE episode.tv_show_id IN (SELECT id FROM tv_show WHERE country = 'Mexico') AND views > 1000000;
Insert a new record into the agency table with agency_id as 10, agency_name as 'Green Transit', agency_url as 'https://www.greentransit.com', and agency_timezone as 'America/New_York'
CREATE TABLE agency (agency_id INT,agency_name VARCHAR(255),agency_url VARCHAR(255),agency_timezone VARCHAR(255));
INSERT INTO agency (agency_id, agency_name, agency_url, agency_timezone) VALUES (10, 'Green Transit', 'https://www.greentransit.com', 'America/New_York');
Who are the male faculty members in the Humanities department?
CREATE TABLE faculty (id INT,name VARCHAR(50),gender VARCHAR(10),department VARCHAR(50)); INSERT INTO faculty (id,name,gender,department) VALUES (1,'Ahmed','Male','Humanities'),(2,'Bella','Female','Arts'),(3,'Carlos','Male','Engineering'),(4,'Delia','Non-binary','Social Sciences');
SELECT name FROM faculty WHERE gender = 'Male' AND department = 'Humanities';
What is the minimum and maximum number of members in unions in the retail industry, and how many unions are there in this industry?
CREATE TABLE union_retail (union_id INT,union_name TEXT,industry TEXT,members INT); INSERT INTO union_retail (union_id,union_name,industry,members) VALUES (1,'Union O','Retail',5000),(2,'Union P','Retail',3000),(3,'Union Q','Retail',9000);
SELECT industry, MIN(members), MAX(members), COUNT(*) FROM union_retail WHERE industry = 'Retail' GROUP BY industry;
Find the maximum total production of silver in Mexico for mines with a production rate greater than or equal to 50,000 ounces.
CREATE TABLE silver_mines (id INT,name TEXT,location TEXT,production_rate INT,total_production INT); INSERT INTO silver_mines (id,name,location,production_rate,total_production) VALUES (1,'San Xavier Mine','Mexico',75000,3000000); INSERT INTO silver_mines (id,name,location,production_rate,total_production) VALUES (2,'La Colorada Mine','Mexico',45000,2500000);
SELECT MAX(total_production) FROM silver_mines WHERE location = 'Mexico' AND production_rate >= 50000;
What is the total number of affordable and accessible housing units in Seoul, grouped by district?
CREATE TABLE Seoul_Housing (District VARCHAR(255),Affordable BOOLEAN,Accessible BOOLEAN,Units INT); INSERT INTO Seoul_Housing (District,Affordable,Accessible,Units) VALUES ('Gangnam',true,true,50),('Mapo',false,true,60),('Yongsan',true,false,70);
SELECT District, SUM(Units) FROM Seoul_Housing WHERE Affordable = true AND Accessible = true GROUP BY District;
What is the average number of publications per faculty member in each department?
CREATE TABLE departments (id INT,name TEXT,budget INT); INSERT INTO departments (id,name,budget) VALUES (1,'Computer Science',1000000),(2,'Mathematics',750000); CREATE TABLE faculty (id INT,name TEXT,department TEXT,publications INT); INSERT INTO faculty (id,name,department,publications) VALUES (1,'John Doe','Computer Science',2),(2,'Jane Smith','Mathematics',3),(3,'Alice Johnson','Computer Science',1);
SELECT d.name, AVG(f.publications) FROM departments d INNER JOIN faculty f ON d.name = f.department GROUP BY d.name;
Which countries have the highest and lowest sales of sustainable products?
CREATE TABLE countries (country_id INT,country_name VARCHAR(20),sustainable_products BOOLEAN,sale_date DATE); INSERT INTO countries (country_id,country_name,sustainable_products,sale_date) VALUES (1,'USA',true,'2020-01-01'),(2,'Canada',false,'2020-01-01'),(3,'Mexico',true,'2020-02-01'),(4,'Brazil',false,'2020-03-01');
SELECT country_name, SUM(CASE WHEN sustainable_products THEN 1 ELSE 0 END) AS total_sustainable_sales, COUNT(*) AS total_sales FROM countries GROUP BY country_name ORDER BY total_sustainable_sales DESC, total_sales DESC;
How many affordable housing units are available in each city?
CREATE TABLE affordable_housing (id INT,city VARCHAR(50),num_units INT); INSERT INTO affordable_housing (id,city,num_units) VALUES (1,'Austin',1000),(2,'Denver',1500),(3,'Austin',800);
SELECT city, SUM(num_units) FROM affordable_housing GROUP BY city;
Identify the number of marine life research projects and their respective budgets in the last 1 year?
CREATE SCHEMA Research; CREATE TABLE Projects (id INT,name TEXT,start_date DATE,end_date DATE,budget FLOAT);
SELECT COUNT(*), SUM(budget) FROM Research.Projects WHERE start_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR);
What is the average citizen feedback score for public services in Madrid in 2019?
CREATE TABLE Feedback (City VARCHAR(20),Year INT,Category VARCHAR(20),Score INT); INSERT INTO Feedback (City,Year,Category,Score) VALUES ('Madrid',2019,'Public Services',80),('Madrid',2019,'Public Services',85);
SELECT AVG(Score) FROM Feedback WHERE City = 'Madrid' AND Year = 2019 AND Category = 'Public Services';
What is the average depth of all marine protected areas in the Pacific region, grouped by country?
CREATE TABLE marine_protected_areas (id INT,name VARCHAR(255),depth FLOAT,region VARCHAR(255)); INSERT INTO marine_protected_areas (id,name,depth,region) VALUES (1,'Galapagos Islands',2000,'Pacific'); INSERT INTO marine_protected_areas (id,name,depth,region) VALUES (2,'Palau National Marine Sanctuary',5000,'Pacific');
SELECT region, country, AVG(depth) as avg_depth FROM (SELECT region, SUBSTRING(name, 1, (INSTR(name, ' ') - 1)) as country, depth FROM marine_protected_areas WHERE region = 'Pacific') GROUP BY region, country;
How many conservation projects were completed in the Arctic region between 2016 and 2021?
CREATE TABLE conservation_efforts (id INT,project_name VARCHAR(255),location VARCHAR(255),start_date DATE,end_date DATE); INSERT INTO conservation_efforts (id,project_name,location,start_date,end_date) VALUES (1,'Coral Reef Restoration','Florida Keys','2010-01-01','2022-12-31'); INSERT INTO conservation_efforts (id,project_name,location,start_date,end_date) VALUES (2,'Turtle Nesting Protection','Costa Rica','2015-06-01','2023-05-31'); INSERT INTO conservation_efforts (id,project_name,location,start_date,end_date) VALUES (3,'Polar Bear Protection','Arctic','2016-01-01','2021-12-31');
SELECT COUNT(*) as total_projects FROM conservation_efforts WHERE location = 'Arctic' AND YEAR(start_date) BETWEEN 2016 AND 2021 AND YEAR(end_date) BETWEEN 2016 AND 2021;
How many members have a membership older than 5 years?
CREATE TABLE members (member_id INT,name VARCHAR(50),gender VARCHAR(10),dob DATE,membership_start_date DATE); INSERT INTO members (member_id,name,gender,dob,membership_start_date) VALUES (1,'Pablo Rodriguez','Male','1997-03-09','2017-03-15'); INSERT INTO members (member_id,name,gender,dob,membership_start_date) VALUES (2,'Quinn Walker','Non-binary','2004-11-29','2020-11-30'); INSERT INTO members (member_id,name,gender,dob,membership_start_date) VALUES (3,'Rachel Nguyen','Female','2001-08-14','2021-08-17');
SELECT COUNT(*) AS members_older_than_5_years FROM members WHERE DATEDIFF(CURRENT_DATE, membership_start_date) > 1825;
How many policy advocacy initiatives were implemented in the Middle East in 2020?
CREATE TABLE policy_advocacy (id INT,initiative TEXT,region TEXT,year INT); INSERT INTO policy_advocacy (id,initiative,region,year) VALUES (1,'Inclusion Program','Middle East',2019),(2,'Accessible Education','Middle East',2020);
SELECT COUNT(*) FROM policy_advocacy WHERE region = 'Middle East' AND year = 2020;
What is the total revenue from concert ticket sales for a given artist, grouped by year?
CREATE TABLE Concerts (id INT,artist_id INT,city VARCHAR(50),revenue DECIMAL(10,2),year INT);
SELECT artist_id, year, SUM(revenue) AS total_revenue FROM Concerts WHERE artist_id = 1 GROUP BY year;
What are the names and artists of artworks exhibited in Germany in 2010?
CREATE TABLE Artworks (ArtworkID INT,Name VARCHAR(100),Artist VARCHAR(100),Year INT); INSERT INTO Artworks (ArtworkID,Name,Artist,Year) VALUES (1,'Starry Night','Vincent van Gogh',1889);
SELECT Artworks.Name, Artworks.Artist FROM Artworks
Identify the number of unique cargo types handled by 'Port of Oakland' in the last month.
CREATE TABLE ports (id INT,name TEXT,last_modified DATE); CREATE TABLE cargo (id INT,type TEXT,port_id INT,handled DATE); INSERT INTO ports (id,name,last_modified) VALUES (1,'Port of Oakland',DATE('2022-03-01')); INSERT INTO cargo (id,type,port_id,handled) VALUES (1,'Electronics',1,DATE('2022-02-28')),(2,'Furniture',1,DATE('2022-03-05'));
SELECT COUNT(DISTINCT type) FROM cargo INNER JOIN ports ON cargo.port_id = ports.id WHERE ports.name = 'Port of Oakland' AND cargo.handled >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH);
What is the median duration of closed cases for each attorney in the "criminal_defense" department?
CREATE TABLE attorneys (attorney_id INT,name VARCHAR(50),department VARCHAR(50)); INSERT INTO attorneys (attorney_id,name,department) VALUES (1,'John Doe','criminal_defense'); INSERT INTO attorneys (attorney_id,name,department) VALUES (2,'Jane Smith','criminal_defense'); CREATE TABLE cases (case_id INT,attorney_id INT,status VARCHAR(50),duration INT); INSERT INTO cases (case_id,attorney_id,status,duration) VALUES (1,1,'closed',25); INSERT INTO cases (case_id,attorney_id,status,duration) VALUES (2,1,'closed',30); INSERT INTO cases (case_id,attorney_id,status,duration) VALUES (3,2,'closed',40);
SELECT attorney_id, MEDIAN(duration) OVER (PARTITION BY attorney_id) as median_duration FROM cases WHERE status = 'closed';
What is the minimum coral cover for the last 10 years?
CREATE TABLE coral_cover (year INT,coral_cover FLOAT); INSERT INTO coral_cover (year,coral_cover) VALUES (2011,25.0),(2012,23.5),(2013,22.2),(2014,21.9),(2015,21.1),(2016,20.4),(2017,19.8),(2018,19.2),(2019,18.8),(2020,18.5);
SELECT MIN(coral_cover) FROM coral_cover WHERE year BETWEEN (YEAR(CURRENT_DATE) - 10) AND YEAR(CURRENT_DATE);
What is the average CO2 emission of ride-hailing vehicles in Singapore?
CREATE TABLE SGRideHailing (id INT,company VARCHAR(20),co2_emission DECIMAL(5,2));
SELECT AVG(co2_emission) FROM SGRideHailing WHERE company = 'Grab';
What is the maximum depth of all stations owned by the MarineLife Research Institute?
CREATE TABLE OceanicStations (id INT,owner TEXT,name TEXT,latitude REAL,longitude REAL,depth REAL);INSERT INTO OceanicStations (id,owner,name,latitude,longitude,depth) VALUES (1,'MarineLife Research Institute','Station X',45.3211,-122.4567,500); INSERT INTO OceanicStations (id,owner,name,latitude,longitude,depth) VALUES (2,'Oceanographers United','Station Y',23.6789,-87.3456,400);
SELECT MAX(depth) FROM OceanicStations WHERE owner = 'MarineLife Research Institute';
Determine the maximum sea surface temperature in the Indian Ocean in the past 2 years.
CREATE TABLE sea_surface_temperature (id INT,region VARCHAR(255),date DATE,temperature FLOAT); INSERT INTO sea_surface_temperature (id,region,date,temperature) VALUES (1,'Indian Ocean','2021-04-01',29.5),(2,'Indian Ocean','2022-02-15',30.2),(3,'Atlantic Ocean','2022-05-28',28.8);
SELECT MAX(temperature) FROM sea_surface_temperature WHERE region = 'Indian Ocean' AND date >= DATE_SUB(CURDATE(), INTERVAL 2 YEAR);
Calculate the percentage of successful security incidents, out of the total number of incidents, for each month in the current year.
CREATE TABLE security_incidents (id INT,incident_date DATE,incident_type VARCHAR(255),success BOOLEAN); INSERT INTO security_incidents (id,incident_date,incident_type,success) VALUES (1,'2022-01-01','Phishing',true),(2,'2022-01-02','Malware',false);
SELECT EXTRACT(MONTH FROM incident_date) as month, COUNT(*) FILTER (WHERE success) * 100.0 / COUNT(*) as success_percentage FROM security_incidents WHERE incident_date >= DATE(NOW()) - INTERVAL '1 year' GROUP BY EXTRACT(MONTH FROM incident_date);
List all sculptures from the 20th century with their material and the name of the museum they are exhibited in, if available, sorted by the sculpture's creation date. If no museum is available, order by material.
CREATE TABLE Sculptures (SculptureID INT,Title VARCHAR(50),CreationDate DATE,Material VARCHAR(50),MuseumID INT); CREATE TABLE Museums (MuseumID INT,Name VARCHAR(50)); INSERT INTO Sculptures VALUES (1,'Bird in Space','1923','Bronze',1); INSERT INTO Museums VALUES (1,'Museum of Modern Art');
SELECT s.Title, s.CreationDate, s.Material, m.Name FROM Sculptures s LEFT JOIN Museums m ON s.MuseumID = m.MuseumID WHERE YEAR(s.CreationDate) >= 1900 ORDER BY s.CreationDate, s.Material;
What is the total funding for projects in the last year, grouped by category?
CREATE TABLE projects (id INT,name VARCHAR(50),category VARCHAR(20),funding DECIMAL(10,2),published_date DATE); CREATE VIEW recent_projects AS SELECT * FROM projects WHERE published_date >= DATEADD(year,-1,GETDATE());
SELECT category, SUM(funding) FROM recent_projects GROUP BY category;
How many artworks are in the 'Modern Art' gallery?
CREATE TABLE Artworks (artwork_id INT,gallery_name VARCHAR(50)); INSERT INTO Artworks (artwork_id,gallery_name) VALUES (1,'Modern Art'),(2,'Modern Art'),(3,'Contemporary Art');
SELECT COUNT(*) FROM Artworks WHERE gallery_name = 'Modern Art';
What is the total revenue for each genre of music in Canada for the year 2021?
CREATE TABLE music_genres (genre VARCHAR(255),country VARCHAR(255),revenue FLOAT); INSERT INTO music_genres (genre,country,revenue) VALUES ('Pop','Canada',9000.0),('Rock','Canada',7000.0),('Jazz','Canada',4000.0);
SELECT genre, SUM(revenue) as total_revenue FROM music_genres WHERE country = 'Canada' AND YEAR(event_date) = 2021 GROUP BY genre;
Calculate the total sales revenue for each day of the week.
CREATE TABLE Sales (SaleID int,SaleDate date,Revenue decimal(5,2)); INSERT INTO Sales (SaleID,SaleDate,Revenue) VALUES (1,'2022-01-01',500),(2,'2022-01-02',750),(3,'2022-01-03',300),(4,'2022-01-04',800),(5,'2022-01-05',600),(6,'2022-01-06',900),(7,'2022-01-07',1200);
SELECT DATEPART(dw, SaleDate) AS DayOfWeek, SUM(Revenue) AS TotalRevenue FROM Sales GROUP BY DATEPART(dw, SaleDate);
What is the maximum timeline for completing construction projects in Chicago, categorized by project type?
CREATE TABLE Project_Timelines_Chicago (ProjectID INT,City VARCHAR(50),ProjectType VARCHAR(50),Timeline INT);
SELECT ProjectType, MAX(Timeline) FROM Project_Timelines_Chicago WHERE City = 'Chicago' GROUP BY ProjectType;
What is the maximum membership fee in each state?
CREATE TABLE memberships (id INT,member_state VARCHAR(50),membership_start_date DATE,membership_fee FLOAT); INSERT INTO memberships (id,member_state,membership_start_date,membership_fee) VALUES (1,'New York','2022-01-05',50.0),(2,'California','2022-01-10',75.0);
SELECT member_state, MAX(membership_fee) FROM memberships GROUP BY member_state;
Delete the record of the mining engineer with ID 1.
CREATE TABLE mine_operators (id INT PRIMARY KEY,name VARCHAR(50),role VARCHAR(50),gender VARCHAR(10),years_of_experience INT); INSERT INTO mine_operators (id,name,role,gender,years_of_experience) VALUES (1,'John Doe','Mining Engineer','Female',7);
DELETE FROM mine_operators WHERE id = 1;
Which destinations had more than 500 visitors in 2021?
CREATE TABLE destination (destination_code CHAR(5),destination_name VARCHAR(50)); INSERT INTO destination VALUES ('PARIS','Paris'),('LOND','London'); CREATE TABLE visit_summary (destination_code CHAR(5),year INT,visitor_count INT); INSERT INTO visit_summary VALUES ('PARIS',2021,700),('PARIS',2020,600),('LOND',2021,650),('LOND',2020,550);
SELECT destination_code, year, visitor_count FROM visit_summary WHERE visitor_count > 500 AND year = 2021;
What is the average number of research publications per faculty member in the Biology department in the past 2 years?
CREATE TABLE if NOT EXISTS publications (id INT,facultyid INT,department VARCHAR(20),type VARCHAR(20),pubdate DATE); CREATE TABLE if NOT EXISTS faculty (id INT,name VARCHAR(50),department VARCHAR(20),rank VARCHAR(20),salary INT);
SELECT AVG(num_publications) FROM (SELECT facultyid, COUNT(*) as num_publications FROM publications WHERE department='Biology' AND pubdate >= DATE_SUB(CURRENT_DATE, INTERVAL 2 YEAR) GROUP BY facultyid) AS subquery INNER JOIN faculty ON subquery.facultyid = faculty.id WHERE department='Biology';
What is the minimum temperature in all shrimp farms in South America?
CREATE TABLE Shrimp_Farms (id INT,region VARCHAR(255),temperature DECIMAL(5,2)); INSERT INTO Shrimp_Farms (id,region,temperature) VALUES (1,'South America',12.5),(2,'South America',11.2),(3,'Europe',18.1),(4,'South America',14.9);
SELECT MIN(Shrimp_Farms.temperature) FROM Shrimp_Farms WHERE Shrimp_Farms.region = 'South America';
List all projects in the 'resilience' table that have a 'completion_date' within the next 6 months.
CREATE TABLE resilience (id INT,project_name VARCHAR(50),location VARCHAR(50),completion_date DATE); INSERT INTO resilience (id,project_name,location,completion_date) VALUES (1,'Flood Control System','Area I','2023-02-28'),(2,'Seismic Retrofitting','City J','2023-10-15');
SELECT project_name, location, completion_date FROM resilience WHERE completion_date >= CURDATE() AND completion_date <= DATE_ADD(CURDATE(), INTERVAL 6 MONTH);
Which aircraft has the highest flight hours for BlueSky airlines?
CREATE TABLE Aircraft (id INT,tail_number VARCHAR(20),model VARCHAR(100),airline VARCHAR(100),flight_hours DECIMAL(10,2)); INSERT INTO Aircraft (id,tail_number,model,airline,flight_hours) VALUES (1,'N12345','737-800','BlueSky',12345.67); INSERT INTO Aircraft (id,tail_number,model,airline,flight_hours) VALUES (2,'N23456','787-900','BlueSky',15000.00);
SELECT model, MAX(flight_hours) FROM Aircraft WHERE airline = 'BlueSky';
Which broadband subscribers have the top 3 highest voice usage in each country?
CREATE TABLE broadband_subscribers (subscriber_id INT,name VARCHAR(50),voice_usage_minutes FLOAT,country VARCHAR(50)); INSERT INTO broadband_subscribers (subscriber_id,name,voice_usage_minutes,country) VALUES (1,'Aarav Patel',500,'India'),(2,'Priya Shah',700,'India'),(3,'Sophia Lee',800,'South Korea'),(4,'Jun Park',900,'South Korea');
SELECT country, subscriber_id, name, voice_usage_minutes, NTILE(3) OVER (PARTITION BY country ORDER BY voice_usage_minutes DESC) as tier FROM broadband_subscribers ORDER BY country, tier;
How has user consumption of music and movies changed over time?
CREATE TABLE MediaConsumption (UserId INT,ConsumptionTime DATETIME,MediaType VARCHAR(50),MediaId INT); INSERT INTO MediaConsumption (UserId,ConsumptionTime,MediaType,MediaId) VALUES (1,'2021-06-01 15:00:00','Movie',1),(2,'2021-06-02 10:00:00','Music',2),(3,'2021-06-03 18:00:00','Movie',3);
SELECT DATEPART(YEAR, ConsumptionTime) AS Year, DATEPART(MONTH, ConsumptionTime) AS Month, MediaType, COUNT(*) AS ConsumptionCount FROM MediaConsumption GROUP BY Year, Month, MediaType;
What is the daily ridership of the metro system in Mexico City, Mexico?
CREATE TABLE metro_ridership (metro_id INT,station_id INT,entry_time TIMESTAMP,exit_time TIMESTAMP,station_name TEXT,city TEXT,daily_ridership INT);
SELECT SUM(daily_ridership) FROM metro_ridership WHERE city = 'Mexico City';
List the names and total funding of the top 3 faculty members who received the most research funding in the past 3 years, including their faculty rank.
CREATE TABLE Faculty (id INT,name VARCHAR(255),rank VARCHAR(255),department VARCHAR(255),funding DECIMAL(10,2),year INT);
SELECT name, SUM(funding) as total_funding, rank FROM Faculty WHERE department LIKE 'Science%' AND year BETWEEN 2019 AND 2021 GROUP BY name, rank ORDER BY total_funding DESC LIMIT 3;
What is the average sustainability rating of the attractions in 'North America'?
CREATE TABLE Attractions (AttractionID INTEGER,AttractionName TEXT,Location TEXT,SustainabilityRating INTEGER); INSERT INTO Attractions (AttractionID,AttractionName,Location,SustainabilityRating) VALUES (1,'Theme Park','Florida',2),(2,'Water Park','Texas',2),(3,'Zoo','California',3),(4,'Aquarium','New York',4),(5,'Sustainable Park','Colorado',5);
SELECT AVG(SustainabilityRating) FROM Attractions WHERE Location = 'North America';
How many startups were founded by Latinx individuals in the technology sector?
CREATE TABLE innovation_trends(id INT,company_id INT,technology_adopted TEXT,innovation_score INT); INSERT INTO innovation_trends (id,company_id,technology_adopted,innovation_score) VALUES (1,5,'AI',85); INSERT INTO innovation_trends (id,company_id,technology_adopted,innovation_score) VALUES (2,6,'Blockchain',90);
SELECT COUNT(*) FROM companies INNER JOIN diversity_metrics ON companies.id = diversity_metrics.company_id WHERE companies.industry = 'Technology' AND diversity_metrics.founder_race = 'Latinx'
What is the total funding raised by organizations working on ethical AI initiatives since 2018?
CREATE TABLE organizations (org_id INT,org_name VARCHAR(100),industry VARCHAR(50)); INSERT INTO organizations VALUES (1,'AI Ethics Inc.','ethical AI'),(2,'Tech for Good Corp.','technology for social good'),(3,'Digital Divide Co.','digital divide'); CREATE TABLE funding (funding_id INT,org_id INT,amount DECIMAL(10,2),funding_year INT); INSERT INTO funding VALUES (1,1,50000.00,2018),(2,1,75000.00,2019),(3,2,30000.00,2019),(4,3,60000.00,2018);
SELECT SUM(amount) FROM funding INNER JOIN organizations ON funding.org_id = organizations.org_id WHERE funding_year >= 2018 AND industry = 'ethical AI';
What is the average price of artworks in each art category?
CREATE TABLE Artworks (id INT,art_category VARCHAR(255),artist_name VARCHAR(255),year INT,art_medium VARCHAR(255),price DECIMAL(10,2));
SELECT art_category, AVG(price) as avg_price FROM Artworks GROUP BY art_category;
What is the total revenue from gluten-free dishes in the past month?
CREATE TABLE Restaurant (id INT,dish_type VARCHAR(10),revenue DECIMAL(10,2)); INSERT INTO Restaurant (id,dish_type,revenue) VALUES (1,'gluten-free',300.00),(2,'regular',800.00);
SELECT SUM(revenue) FROM Restaurant WHERE dish_type = 'gluten-free' AND date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH);
What is the total number of space missions that have been successful vs unsuccessful?
CREATE TABLE missions (id INT,mission_name VARCHAR(50),mission_status VARCHAR(50),year INT); INSERT INTO missions (id,mission_name,mission_status,year) VALUES (1,'Apollo 11','Success',1969),(2,'Salyut 1','Success',1971),(3,'Skylab 1','Failure',1973),(4,'Soyuz T-10-1','Failure',1983),(5,'Challenger','Failure',1986),(6,'Columbia','Failure',2003),(7,'Mars Orbiter Mission','Success',2013),(8,'ExoMars Trace Gas Orbiter','Success',2016);
SELECT mission_status, COUNT(id) as total_missions FROM missions GROUP BY mission_status;
Which brands have not yet implemented fair labor practices?
CREATE TABLE labor_practices (id INT,brand VARCHAR(255),certified BOOLEAN);
SELECT brand FROM labor_practices WHERE certified = false;