instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
Delete records of Cod from the fish_stock table | CREATE TABLE fish_stock (id INT PRIMARY KEY,species VARCHAR(255),quantity INT,location VARCHAR(255)); | DELETE FROM fish_stock WHERE species = 'Cod'; |
Delete records of all cargoes that have been at sea for more than 60 days. | CREATE TABLE cargoes (id INT,name VARCHAR(50),at_sea INT); INSERT INTO cargoes (id,name,at_sea) VALUES (1,'Electronic Goods',35),(2,'Machinery Parts',42),(3,'Clothing Items',20); | DELETE FROM cargoes WHERE at_sea > 60; |
Find the number of cases of measles in each state in 2020? | CREATE TABLE measles_cases (id INT,state TEXT,year INT); INSERT INTO measles_cases (id,state,year) VALUES (1,'California',2020); INSERT INTO measles_cases (id,state,year) VALUES (2,'Texas',2019); INSERT INTO measles_cases (id,state,year) VALUES (3,'New York',2020); | SELECT measles_cases.state, COUNT(measles_cases.id) FROM measles_cases WHERE measles_cases.year = 2020 GROUP BY measles_cases.state; |
Update the recycling rate for the city of Mumbai to 40% in 2023. | CREATE TABLE recycling_rates(city VARCHAR(20),year INT,rate DECIMAL(5,2)); INSERT INTO recycling_rates VALUES('Mumbai',2023,35); | UPDATE recycling_rates SET rate = 40 WHERE city = 'Mumbai' AND year = 2023; |
List the names of visual arts programs with less than 30 attendees in total. | CREATE TABLE programs (id INT,name VARCHAR(50),type VARCHAR(20)); INSERT INTO programs (id,name,type) VALUES (1,'Painting 1','Visual Arts'),(2,'Sculpture 1','Visual Arts'),(3,'Painting 2','Visual Arts'),(4,'Photography 1','Visual Arts'); CREATE TABLE program_attendance (program_id INT,attendee_count INT); INSERT INTO program_attendance (program_id,attendee_count) VALUES (1,25),(2,40),(3,35),(4,10); | SELECT p.name FROM programs p JOIN program_attendance pa ON p.id = pa.program_id WHERE p.type = 'Visual Arts' AND pa.attendee_count < 30; |
How many volunteers are there in each volunteer group? | CREATE TABLE Volunteers (VolunteerGroup VARCHAR(20),VolunteerCount INT); INSERT INTO Volunteers (VolunteerGroup,VolunteerCount) VALUES ('Youth Group',100),('Senior Group',50),('Community Group',150); | SELECT VolunteerGroup, VolunteerCount FROM Volunteers; |
What are the names of all suppliers that provide more than 1000 tons of organic produce? | CREATE TABLE suppliers (id INT,name TEXT,produce_type TEXT,quantity INT,is_organic BOOLEAN); INSERT INTO suppliers (id,name,produce_type,quantity,is_organic) VALUES (1,'Green Earth','Produce',1200,true); INSERT INTO suppliers (id,name,produce_type,quantity,is_organic) VALUES (2,'Farm Fresh','Produce',800,true); | SELECT name FROM suppliers WHERE produce_type = 'Produce' AND is_organic = true AND quantity > 1000; |
Find the total number of unique digital assets that have been traded in the past month. | CREATE TABLE trades (asset_name VARCHAR(10),trade_date DATE); INSERT INTO trades (asset_name,trade_date) VALUES ('BTC','2022-01-01'),('ETH','2022-01-02'),('LTC','2022-01-03'),('BTC','2022-01-04'),('BTC','2022-01-05'),('ETH','2022-01-06'),('BTC','2022-01-07'); | SELECT COUNT(DISTINCT asset_name) FROM trades WHERE trade_date BETWEEN '2022-01-01' AND '2022-01-31'; |
List all albums released by a specific artist | CREATE TABLE artists (id INT PRIMARY KEY,name VARCHAR(100),origin_country VARCHAR(50)); | CREATE TABLE albums (id INT PRIMARY KEY, title VARCHAR(100), artist_id INT, release_year INT); |
What is the average number of safety incidents in the textile industry in India? | CREATE TABLE incidents (id INT,company VARCHAR(50),country VARCHAR(50),industry VARCHAR(50),number INT); | SELECT AVG(number) FROM incidents WHERE country = 'India' AND industry = 'Textile'; |
Get the number of vegetarian and non-vegetarian dishes in each category | CREATE TABLE Menu (menu_id INT,dish_name VARCHAR(100),dish_type VARCHAR(20),dish_category VARCHAR(50)); INSERT INTO Menu (menu_id,dish_name,dish_type,dish_category) VALUES (1,'Quinoa Salad','Vegetarian','Salad'); INSERT INTO Menu (menu_id,dish_name,dish_type,dish_category) VALUES (2,'Grilled Chicken','Non-Vegetarian','Sandwich'); | SELECT dish_category, dish_type, COUNT(*) AS dish_count FROM Menu GROUP BY dish_category, dish_type; |
List the top 3 donors from Asia, Africa, and Europe, in terms of total donated amount. | CREATE TABLE donors (id INT,name TEXT,country TEXT,amount_donated DECIMAL(10,2)); INSERT INTO donors (id,name,country,amount_donated) VALUES (1,'Alice','India',5000.00),(2,'Bob','Nigeria',3000.00),(3,'Charlie','Canada',7000.00),(4,'David','UK',8000.00),(5,'Eve','Germany',9000.00); | SELECT name, SUM(amount_donated) FROM donors WHERE country IN ('India', 'Nigeria', 'UK', 'Germany') GROUP BY name ORDER BY SUM(amount_donated) DESC LIMIT 3; |
Update the participants to 40 for program ID 1 in community engagement. | CREATE TABLE CommunityEngagement (id INT,country VARCHAR(50),program VARCHAR(100),participants INT); INSERT INTO CommunityEngagement (id,country,program,participants) VALUES (1,'Samoa','Fale-building',50),(2,'Samoa','Tapa-making',35); | UPDATE CommunityEngagement SET participants = 40 WHERE id = 1; |
What is the minimum project cost in each region? | CREATE TABLE Projects (region VARCHAR(20),project_cost INT); INSERT INTO Projects (region,project_cost) VALUES ('Northeast',5000000),('Southeast',7000000),('Midwest',6000000),('Southwest',8000000),('West',9000000); | SELECT region, MIN(project_cost) FROM Projects GROUP BY region; |
What is the total number of students and teachers involved in open pedagogy projects for each semester? | CREATE TABLE semesters (semester_id INT,semester_name TEXT); INSERT INTO semesters (semester_id,semester_name) VALUES (1,'Fall'),(2,'Spring'),(3,'Summer'); CREATE TABLE student_open_pedagogy (student_id INT,semester_id INT); CREATE TABLE teacher_open_pedagogy (teacher_id INT,semester_id INT); INSERT INTO student_open_pedagogy (student_id,semester_id) VALUES (1,1),(2,2),(3,3),(4,1); INSERT INTO teacher_open_pedagogy (teacher_id,semester_id) VALUES (1,1),(2,2),(3,3); | SELECT s.semester_name, COUNT(sop.student_id) AS num_students, COUNT(top.teacher_id) AS num_teachers FROM semesters s LEFT JOIN student_open_pedagogy sop ON s.semester_id = sop.semester_id FULL OUTER JOIN teacher_open_pedagogy top ON s.semester_id = top.semester_id GROUP BY s.semester_name; |
Delete records from the "diversity_metrics" table for the company 'Echo Ltd.' | CREATE TABLE diversity_metrics (id INT,company_name VARCHAR(100),region VARCHAR(50),employees_of_color INT,women_in_tech INT); INSERT INTO diversity_metrics (id,company_name,region,employees_of_color,women_in_tech) VALUES (1,'Acme Inc.','Europe',15,22),(2,'Bravo Corp.','North America',35,18),(5,'Echo Ltd.','Asia',12,30); | DELETE FROM diversity_metrics WHERE company_name = 'Echo Ltd.'; |
What is the total funding amount for projects in the 'Health' sector? | CREATE TABLE projects (id INT,sector TEXT,total_funding DECIMAL); INSERT INTO projects (id,sector,total_funding) VALUES (1,'Health',10000.00),(2,'Education',15000.00); | SELECT SUM(total_funding) FROM projects WHERE sector = 'Health'; |
List the names and departments of graduate students who have received more than one research grant in the past year. | CREATE TABLE students (student_id INT PRIMARY KEY,name VARCHAR(50),department VARCHAR(50),grant_recipient BOOLEAN,grant_date DATE); INSERT INTO students (student_id,name,department,grant_recipient,grant_date) VALUES (1,'David','Humanities',TRUE,'2022-01-01'),(2,'Gina','Biology',TRUE,'2021-01-01'),(3,'Harry','Chemistry',TRUE,'2021-01-01'); CREATE TABLE grants (grant_id INT PRIMARY KEY,student_id INT,amount FLOAT); INSERT INTO grants (grant_id,student_id) VALUES (1,1),(2,1),(3,2); | SELECT s.name, s.department FROM students s INNER JOIN grants g ON s.student_id = g.student_id WHERE s.department IN ('Humanities', 'Biology', 'Chemistry') AND s.grant_recipient = TRUE AND g.grant_id IN (SELECT g.grant_id FROM grants g WHERE g.student_id = s.student_id GROUP BY g.student_id HAVING COUNT(*) > 1) AND s.grant_date >= DATEADD(year, -1, GETDATE()); |
What is the number of general hospitals in each state in Rural USA? | CREATE TABLE Hospitals (name TEXT,location TEXT,type TEXT,num_beds INTEGER,state TEXT); INSERT INTO Hospitals (name,location,type,num_beds,state) VALUES ('Hospital A','City A,Rural USA','General',100,'Rural USA'),('Hospital B','City B,Rural USA','Specialty',50,'Rural USA'); | SELECT state, COUNT(*) as general_hospitals_count FROM Hospitals WHERE type = 'General' GROUP BY state; |
What is the average lifespan of different types of satellites and how many have been launched? | CREATE TABLE satellite (id INT,name VARCHAR(255),type VARCHAR(255),country VARCHAR(255),launch_date DATE); INSERT INTO satellite VALUES (3,'GPS Satellite','Navigation','USA','1978-02-22'); | SELECT type, COUNT(id) as total, AVG(DATEDIFF(CURDATE(), launch_date)) as avg_lifespan FROM satellite GROUP BY type; |
Update the price of the 'Veggie Burger' to $12.99 in the 'Lunch Menu' of Restaurant A. | CREATE TABLE menus (menu_id INT,restaurant_id INT,meal_time VARCHAR(255),item VARCHAR(255),price DECIMAL(5,2)); | UPDATE menus SET price = 12.99 WHERE restaurant_id = (SELECT restaurant_id FROM restaurants WHERE name = 'Restaurant A') AND meal_time = 'Lunch' AND item = 'Veggie Burger'; |
What is the total gas production in the North Sea for the year 2022? | CREATE TABLE gas_production (id INT,well_name VARCHAR(50),location VARCHAR(50),company VARCHAR(50),production_type VARCHAR(10),production_quantity INT,production_date DATE); INSERT INTO gas_production VALUES (4,'Well S','North Sea','XYZ Gas','Gas',200000,'2022-01-01'); | SELECT SUM(production_quantity) FROM gas_production WHERE location = 'North Sea' AND production_type = 'Gas' AND production_date BETWEEN '2022-01-01' AND '2022-12-31'; |
What is the total waste generation of each city in the recycling program? | CREATE TABLE Cities (CityID INT,CityName VARCHAR(50),WasteGeneration FLOAT); INSERT INTO Cities VALUES (1,'CityA',1200),(2,'CityB',1800),(3,'CityC',1500); CREATE TABLE RecyclingProgram (CityID INT,ProgramName VARCHAR(50)); INSERT INTO RecyclingProgram VALUES (1,'Program1'),(2,'Program2'),(3,'Program3'); | SELECT Cities.CityName, SUM(Cities.WasteGeneration) as TotalWasteGeneration FROM Cities INNER JOIN RecyclingProgram ON Cities.CityID = RecyclingProgram.CityID GROUP BY Cities.CityName; |
What is the minimum number of wins of players who have played Dota 2 and are from Africa? | CREATE TABLE Players (PlayerID INT,Wins INT,Game VARCHAR(50),Country VARCHAR(50)); INSERT INTO Players (PlayerID,Wins,Game,Country) VALUES (1,22,'Dota 2','Africa'); INSERT INTO Players (PlayerID,Wins,Game,Country) VALUES (2,25,'Dota 2','Africa'); INSERT INTO Players (PlayerID,Wins,Game,Country) VALUES (3,19,'Dota 2','Africa'); INSERT INTO Players (PlayerID,Wins,Game,Country) VALUES (4,15,'Dota 2','Africa'); | SELECT MIN(Wins) as MinWins FROM Players WHERE Game = 'Dota 2' AND Country = 'Africa'; |
What is the total number of marine species research projects in the Atlantic Ocean? | CREATE TABLE research_projects (project_id INT,project_name VARCHAR(255),region VARCHAR(255),focus_area VARCHAR(255),PRIMARY KEY(project_id)); INSERT INTO research_projects (project_id,project_name,region,focus_area) VALUES (1,'Marine Species Research','Atlantic Ocean','Biodiversity'),(2,'Coral Conservation Research','Atlantic Ocean','Coral'); | SELECT COUNT(*) FROM research_projects WHERE region = 'Atlantic Ocean' AND (focus_area = 'Biodiversity' OR focus_area = 'Coral'); |
Who are the top 3 investors in terms of total investment amounts in organizations focused on gender equality? | CREATE TABLE investments (investment_id INT,investor_id INT,org_id INT,investment_amount INT); INSERT INTO investments (investment_id,investor_id,org_id,investment_amount) VALUES (1,1,2,50000),(2,2,3,75000),(3,1,1,100000),(4,3,2,35000),(5,2,1,80000); CREATE TABLE investors (investor_id INT,investor_name TEXT); INSERT INTO investors (investor_id,investor_name) VALUES (1,'Investor A'),(2,'Investor B'),(3,'Investor C'); CREATE TABLE organizations (org_id INT,org_name TEXT,focus_topic TEXT); INSERT INTO organizations (org_id,org_name,focus_topic) VALUES (1,'Org 1','Gender Equality'),(2,'Org 2','Gender Equality'),(3,'Org 3','Climate Change'); | SELECT investor_name, SUM(investment_amount) AS total_invested FROM investments JOIN investors ON investments.investor_id = investors.investor_id JOIN organizations ON investments.org_id = organizations.org_id WHERE focus_topic = 'Gender Equality' GROUP BY investor_name ORDER BY total_invested DESC LIMIT 3; |
What is the number of residential green building projects completed in each month of the year 2022, for the state of New York? | CREATE TABLE residential_green_projects (project_id INT,completion_date DATE,state TEXT); INSERT INTO residential_green_projects (project_id,completion_date,state) VALUES (1,'2022-03-15','New York'),(2,'2022-02-28','New York'),(3,'2022-01-01','New York'); | SELECT EXTRACT(MONTH FROM completion_date), COUNT(*) FROM residential_green_projects WHERE state = 'New York' AND EXTRACT(YEAR FROM completion_date) = 2022 AND permit_type = 'Residential' GROUP BY EXTRACT(MONTH FROM completion_date); |
What is the number of male doctors in the 'healthcare_staff' table? | CREATE TABLE healthcare_staff (name VARCHAR(255),gender VARCHAR(255),position VARCHAR(255),hospital_id INT); INSERT INTO healthcare_staff (name,gender,position,hospital_id) VALUES ('Dr. John Doe','Male','Doctor',1),('Dr. Jane Smith','Female','Doctor',2),('Dr. Maria Garcia','Female','Doctor',3); | SELECT COUNT(*) FROM healthcare_staff WHERE gender = 'Male' AND position = 'Doctor'; |
What is the total quantity of gold and silver extracted by each company? | CREATE TABLE Companies (CompanyID INT,CompanyName VARCHAR(50)); INSERT INTO Companies (CompanyID,CompanyName) VALUES (1,'ACME Mining'),(2,'BIG Excavations'),(3,'Giga Drilling'); CREATE TABLE Extraction (ExtractionID INT,CompanyID INT,Material VARCHAR(50),Quantity INT); INSERT INTO Extraction (ExtractionID,CompanyID,Material,Quantity) VALUES (1,1,'Gold',500),(2,1,'Silver',3000),(3,2,'Gold',7000),(4,3,'Silver',1000); | SELECT CompanyName, SUM(Quantity) FROM Extraction JOIN Companies ON Extraction.CompanyID = Companies.CompanyID WHERE Material IN ('Gold', 'Silver') GROUP BY CompanyName; |
Which countries have the highest teacher turnover rates in the past year? | CREATE TABLE countries (country_code CHAR(2),country_name VARCHAR(50)); INSERT INTO countries VALUES ('US','United States'),('CA','Canada'),('MX','Mexico'); CREATE TABLE teachers (teacher_id INT,country_code CHAR(2),years_of_experience INT); INSERT INTO teachers VALUES (1,'US',5),(2,'CA',3),(3,'MX',8); CREATE TABLE turnover (teacher_id INT,turnover_date DATE); INSERT INTO turnover VALUES (1,'2021-02-01'),(2,'2021-06-01'),(3,'2020-12-01'); | SELECT c.country_name, COUNT(t.teacher_id) AS teacher_count, AVG(t.years_of_experience) AS avg_experience, COUNT(turnover.teacher_id) / COUNT(t.teacher_id) * 100 AS turnover_rate FROM countries c JOIN teachers t ON c.country_code = t.country_code LEFT JOIN turnover ON t.teacher_id = turnover.teacher_id WHERE turnover_date >= DATEADD(year, -1, GETDATE()) GROUP BY c.country_name ORDER BY turnover_rate DESC; |
What is the total revenue for the year 2021 from network infrastructure investments in the region of Asia? | CREATE TABLE network_investments (investment_id INT,region VARCHAR(255),year INT,revenue DECIMAL(10,2)); INSERT INTO network_investments (investment_id,region,year,revenue) VALUES (1,'Asia',2021,800000),(2,'Europe',2020,700000),(3,'Asia',2019,600000); | SELECT SUM(revenue) FROM network_investments WHERE region = 'Asia' AND year = 2021; |
How many shared bicycles were available in Berlin on July 4, 2021? | CREATE TABLE shared_bicycles(bicycle_id INT,availability_status VARCHAR(50),availability_date DATE,city VARCHAR(50)); | SELECT COUNT(*) FROM shared_bicycles WHERE availability_status = 'available' AND availability_date = '2021-07-04' AND city = 'Berlin'; |
What is the total installed capacity (in MW) of renewable energy projects in the United States? | CREATE TABLE renewable_projects (id INT,project_name TEXT,location TEXT,installed_capacity INT); INSERT INTO renewable_projects (id,project_name,location,installed_capacity) VALUES (1,'Solar Farm A','USA',50); CREATE TABLE conventional_projects (id INT,project_name TEXT,location TEXT,installed_capacity INT); | SELECT SUM(renewable_projects.installed_capacity) FROM renewable_projects WHERE renewable_projects.location = 'USA'; |
What is the maximum well depth for wells in the 'Gulf of Mexico'? | CREATE TABLE wells (well_id INT,well_name VARCHAR(255),well_depth FLOAT,region VARCHAR(255)); INSERT INTO wells (well_id,well_name,well_depth,region) VALUES (1,'A1',3000,'North Sea'),(2,'B2',2500,'North Sea'),(3,'C3',4000,'Gulf of Mexico'); | SELECT MAX(well_depth) FROM wells WHERE region = 'Gulf of Mexico'; |
What is the total number of hours spent on open pedagogy projects by students in grade 10? | CREATE TABLE projects (project_id INT,student_id INT,grade_level INT,project_hours INT); INSERT INTO projects (project_id,student_id,grade_level,project_hours) VALUES (1,1,10,5),(2,1,10,3),(3,2,10,6),(4,2,10,7),(5,3,11,4),(6,3,11,8); | SELECT SUM(project_hours) FROM projects WHERE grade_level = 10; |
What was the total amount of funding provided by the World Bank to community development projects in Afghanistan in 2012? | CREATE TABLE community_development (funding_agency VARCHAR(255),project_type VARCHAR(255),country VARCHAR(255),amount DECIMAL(10,2),year INT); | SELECT SUM(amount) FROM community_development WHERE funding_agency = 'World Bank' AND project_type = 'community development' AND country = 'Afghanistan' AND year = 2012; |
List the top 3 oldest cities with the highest average visitor age. | CREATE TABLE Cities (id INT,city VARCHAR(20),avgAge DECIMAL(5,2)); INSERT INTO Cities (id,city,avgAge) VALUES (1,'Paris',40.5),(2,'London',34.0),(3,'Rome',41.0),(4,'Berlin',33.5); | SELECT city, avgAge FROM (SELECT city, AVG(visitorAge) AS avgAge, ROW_NUMBER() OVER (ORDER BY AVG(visitorAge) DESC) as rn FROM Exhibitions GROUP BY city) t WHERE rn <= 3; |
What was the total budget for 'Transportation' sector in the year 2019, including records with a budget more than $500,000? | CREATE TABLE TransportBudget (Sector VARCHAR(50),BudgetAmount NUMERIC(15,2),BudgetYear INT); INSERT INTO TransportBudget (Sector,BudgetAmount,BudgetYear) VALUES ('Transportation',800000,2019),('Transportation',300000,2019),('Transportation',600000,2019); | SELECT SUM(BudgetAmount) FROM TransportBudget WHERE Sector = 'Transportation' AND BudgetYear = 2019 AND BudgetAmount > 500000; |
Find the top 2 artworks with the highest number of reviews and their corresponding artists. | CREATE TABLE Artworks (artwork_id INT,artist_id INT,artwork_name TEXT,rating INT,num_reviews INT); INSERT INTO Artworks (artwork_id,artist_id,artwork_name,rating,num_reviews) VALUES (1,101,'Painting 1',8,30),(2,101,'Painting 2',9,50),(3,102,'Sculpture 1',7,25); CREATE TABLE ArtistDetails (artist_id INT,artist_name TEXT); INSERT INTO ArtistDetails (artist_id,artist_name) VALUES (101,'John Doe'),(102,'Jane Smith'); | SELECT a.artwork_name, a.num_reviews, ad.artist_name FROM Artworks a JOIN ArtistDetails ad ON a.artist_id = ad.artist_id ORDER BY a.num_reviews DESC LIMIT 2 |
Show the three safest vehicle models based on safety test results. | CREATE TABLE safety_tests (id INT,vehicle_model VARCHAR(20),test_result VARCHAR(10),test_score INT); INSERT INTO safety_tests (id,vehicle_model,test_result,test_score) VALUES (1,'Model X','Pass',90),(2,'Model Y','Pass',85),(3,'Model Z','Pass',95),(4,'Model X','Pass',92),(5,'Model Y','Fail',80); | SELECT vehicle_model, AVG(test_score) AS avg_score FROM safety_tests WHERE test_result = 'Pass' GROUP BY vehicle_model ORDER BY avg_score DESC LIMIT 3; |
Which wells had drilling operations completed in 2020? | CREATE TABLE drilling_operations (drill_id INT,well_id INT,start_date DATE,end_date DATE,status VARCHAR(50)); INSERT INTO drilling_operations (drill_id,well_id,start_date,end_date,status) VALUES (1,1,'2020-01-01','2020-04-30','Completed'),(2,2,'2020-02-15','2020-05-25','In Progress'),(4,5,'2020-03-10','2020-08-18','Completed'),(3,3,'2019-12-10','2020-03-18','Completed'); | SELECT well_id FROM drilling_operations WHERE status = 'Completed' AND start_date BETWEEN '2020-01-01' AND '2020-12-31' GROUP BY well_id; |
For each software product, show the number of vulnerabilities discovered in the last 30 days. | CREATE TABLE software (id INT,name VARCHAR(255)); INSERT INTO software (id,name) VALUES (1,'Product A'),(2,'Product B'),(3,'Product C'); CREATE TABLE vulnerabilities (id INT,software_id INT,discovered_on DATE,severity VARCHAR(255)); INSERT INTO vulnerabilities (id,software_id,discovered_on,severity) VALUES (1,1,'2022-01-01','High'),(2,1,'2022-02-01','Medium'),(3,2,'2022-03-01','Low'),(4,2,'2022-03-15','High'),(5,3,'2022-03-30','Medium'); | SELECT software.name, COUNT(vulnerabilities.id) as vulnerabilities_in_last_30_days FROM software LEFT JOIN vulnerabilities ON software.id = vulnerabilities.software_id WHERE vulnerabilities.discovered_on >= DATEADD(day, -30, GETDATE()) GROUP BY software.name; |
What are the names of all intelligence agencies operating in 'Africa'? | CREATE TABLE intelligence_agencies (id INT,agency_name TEXT,region TEXT); INSERT INTO intelligence_agencies (id,agency_name,region) VALUES (1,'National Intelligence Agency','Africa'),(2,'Directorate of Military Intelligence','Africa'),(3,'State Security Agency','Africa'); | SELECT agency_name FROM intelligence_agencies WHERE region = 'Africa'; |
What is the average sentiment score of articles created by female authors in the AI safety domain? | CREATE TABLE authors (id INT,name VARCHAR(50),gender VARCHAR(10),domain VARCHAR(50)); INSERT INTO authors (id,name,gender,domain) VALUES (1,'Alice','Female','AI Safety'); CREATE TABLE articles (id INT,title VARCHAR(100),sentiment FLOAT,author_id INT); INSERT INTO articles (id,title,sentiment,author_id) VALUES (1,'AI Safety: A New Approach',0.6,1); | SELECT AVG(articles.sentiment) FROM articles INNER JOIN authors ON articles.author_id = authors.id WHERE authors.gender = 'Female' AND authors.domain = 'AI Safety'; |
Insert new records into the 'equipment' table for a new bioprocess with the following details: Reactor ID 101, Temperature 37, Pressure 2, Volume 500, Stir_speed 100, pH 7 | CREATE TABLE bioprocess (id INT PRIMARY KEY,name TEXT); CREATE TABLE equipment (bioprocess_id INT,reactor_id INT,temperature INT,pressure INT,volume INT,stir_speed INT,pH REAL,FOREIGN KEY (bioprocess_id) REFERENCES bioprocess(id)); | INSERT INTO bioprocess (name) VALUES ('NewBioprocess'); INSERT INTO equipment (bioprocess_id, reactor_id, temperature, pressure, volume, stir_speed, pH) VALUES ((SELECT id FROM bioprocess WHERE name = 'NewBioprocess'), 101, 37, 2, 500, 100, 7); |
Insert a new organization 'Code Tenderloin' with org_id '10' into the 'Organizations' table | CREATE TABLE Organizations (org_id INT,org_name TEXT); | INSERT INTO Organizations (org_id, org_name) VALUES (10, 'Code Tenderloin'); |
What is the total number of mobile and broadband subscribers in Germany for each network type? | CREATE TABLE germany_data (subscriber_id INT,network_type VARCHAR(10),subscriber_type VARCHAR(10)); INSERT INTO germany_data (subscriber_id,network_type,subscriber_type) VALUES (1,'4G','mobile'),(2,'5G','mobile'),(3,'Fiber','broadband'),(4,'ADSL','broadband'); | SELECT network_type, COUNT(*) as total_subscribers FROM germany_data WHERE subscriber_type IN ('mobile', 'broadband') GROUP BY network_type; |
Calculate the average construction cost per square meter for all completed projects in the 'construction_projects' table, filtered to show only projects completed between 2016 and 2018? | CREATE TABLE construction_projects (id INT,district VARCHAR(50),project_name VARCHAR(100),start_date DATE,end_date DATE,area DECIMAL(10,2),construction_cost DECIMAL(10,2)); | SELECT AVG(construction_cost / area) FROM construction_projects WHERE YEAR(start_date) BETWEEN 2016 AND 2018 AND end_date IS NOT NULL; |
How many projects were completed in each sector by year? | CREATE TABLE Projects (ProjectID int,Sector varchar(50),Year int,Completed int); INSERT INTO Projects (ProjectID,Sector,Year,Completed) VALUES (1,'Health',2018,1),(2,'Education',2017,0),(3,'Health',2019,1),(4,'Infrastructure',2018,1); | SELECT y.Year, s.Sector, COUNT(p.ProjectID) AS CompletedProjects FROM (SELECT DISTINCT Year FROM Projects) y CROSS JOIN (SELECT DISTINCT Sector FROM Projects) s LEFT JOIN Projects p ON y.Year = p.Year AND s.Sector = p.Sector WHERE p.Completed = 1 GROUP BY y.Year, s.Sector; |
Which suppliers have the highest and lowest average carbon footprint for their ingredients? | CREATE TABLE SupplierIngredients (id INT,supplier_id INT,name VARCHAR(255),carbon_footprint INT); | SELECT supplier_id, MAX(carbon_footprint) AS max_carbon_footprint, MIN(carbon_footprint) AS min_carbon_footprint FROM SupplierIngredients GROUP BY supplier_id; |
What is the average price per gram of cannabis for each strain in Oregon, grouped by strain? | CREATE TABLE strains (strain_id INT,name TEXT,state TEXT); INSERT INTO strains (strain_id,name,state) VALUES (1,'Strain X','Oregon'),(2,'Strain Y','Oregon'),(3,'Strain Z','California'); CREATE TABLE sales (sale_id INT,strain_id INT,price DECIMAL,grams INT); INSERT INTO sales (sale_id,strain_id,price,grams) VALUES (1,1,10.00,1),(2,1,12.00,2),(3,2,8.00,1); | SELECT s.name, AVG(s.price / s.grams) AS avg_price_per_gram FROM strains st JOIN sales s ON st.strain_id = s.strain_id WHERE st.state = 'Oregon' GROUP BY s.name; |
How many songs were released in each quarter of the year for the 'Electronic' genre? | CREATE TABLE Songs (id INT,title VARCHAR(100),release_quarter INT,genre VARCHAR(50),streams INT); | SELECT genre, release_quarter, COUNT(*) FROM Songs WHERE genre = 'Electronic' GROUP BY genre, release_quarter; |
Update the nutritional information of a specific dish across all restaurants serving it. | CREATE TABLE Dishes (DishID int,Name varchar(50),Category varchar(50),CaloricContent int); INSERT INTO Dishes (DishID,Name,Category,CaloricContent) VALUES (1,'Quinoa Salad','Organic',350); CREATE TABLE Restaurants (RestaurantID int,Name varchar(50),Location varchar(50)); INSERT INTO Restaurants (RestaurantID,Name,Location) VALUES (1,'Organic Oasis','California'),(2,'Healthy Bites','New York'); | UPDATE Dishes SET CaloricContent = 400 WHERE Name = 'Quinoa Salad'; |
What is the lifelong learning progress of students in grade 6? | CREATE TABLE lifelong_learning (student_id INT,grade INT,progress INT); INSERT INTO lifelong_learning (student_id,grade,progress) VALUES (1,5,30),(2,5,40),(3,6,50),(4,6,60),(5,7,70),(6,7,80); | SELECT grade, progress, RANK() OVER (PARTITION BY grade ORDER BY progress DESC) AS progress_rank FROM lifelong_learning WHERE grade = 6; |
What is the total number of employees from historically underrepresented communities in the Finance department? | CREATE TABLE underrepresented_communities (id INT,name VARCHAR(50),department VARCHAR(50),community VARCHAR(50)); INSERT INTO underrepresented_communities (id,name,department,community) VALUES (1,'Jamal','Finance','African American'),(2,'Alicia','Finance','Latinx'),(3,'Mei-Ling','Finance','Asian American'),(4,'Kevin','Finance','LGBTQ+'); | SELECT COUNT(*) FROM underrepresented_communities WHERE department = 'Finance'; |
What is the average budget for all movies produced in India? | CREATE TABLE indian_movies (id INT,title VARCHAR(255),budget FLOAT,production_country VARCHAR(100)); INSERT INTO indian_movies (id,title,budget,production_country) VALUES (1,'Movie1',5000000,'India'),(2,'Movie2',7000000,'India'),(3,'Movie3',3000000,'India'); | SELECT AVG(budget) FROM indian_movies; |
How many recycling centers are located in New York state and which districts do they serve? | CREATE TABLE recycling_centers (id INT,name VARCHAR(20),location VARCHAR(20),district VARCHAR(20)); | SELECT COUNT(*), district FROM recycling_centers WHERE location = 'New York' GROUP BY district; |
What is the average time between offenses for each offender, ordered by the average time? | CREATE TABLE offenses (offender_id INT,offense_date DATE); INSERT INTO offenses (offender_id,offense_date) VALUES (1,'2018-01-01'),(1,'2019-01-01'),(2,'2017-01-01'); | SELECT offender_id, AVG(DATEDIFF(day, LAG(offense_date) OVER (PARTITION BY offender_id ORDER BY offense_date), offense_date)) AS avg_time_between_offenses FROM offenses GROUP BY offender_id ORDER BY AVG(DATEDIFF(day, LAG(offense_date) OVER (PARTITION BY offender_id ORDER BY offense_date), offense_date)); |
What is the total installed capacity of wind farms in the clean_energy schema? | CREATE TABLE wind_farms (id INT,name VARCHAR(50),location VARCHAR(50),installed_capacity FLOAT); INSERT INTO wind_farms (id,name,location,installed_capacity) VALUES (1,'Wind Farm 1','Country A',120.5); INSERT INTO wind_farms (id,name,location,installed_capacity) VALUES (2,'Wind Farm 2','Country B',250.8); | SELECT SUM(installed_capacity) FROM clean_energy.wind_farms; |
How many vehicles were serviced in the 'Maintenance' workshop between March 15, 2021 and March 31, 2021? | CREATE TABLE maintenance (workshop VARCHAR(20),service_date DATE); INSERT INTO maintenance (workshop,service_date) VALUES ('Maintenance','2021-03-15'),('Body Shop','2021-03-17'),('Maintenance','2021-03-20'),('Tires','2021-03-22'),('Maintenance','2021-03-30'); | SELECT COUNT(*) FROM maintenance WHERE workshop = 'Maintenance' AND service_date BETWEEN '2021-03-15' AND '2021-03-31'; |
Find the total area and production of crops for each farmer in 'farmer_crops' table | CREATE TABLE farmer_crops (farmer_id INT,crop_name VARCHAR(50),area FLOAT,production INT); | SELECT farmer_id, SUM(area) AS total_area, SUM(production) AS total_production FROM farmer_crops GROUP BY farmer_id; |
List unique AI-powered hotel features in the Middle East and South America. | CREATE TABLE hotel_features (hotel_id INT,location VARCHAR(20),feature VARCHAR(30)); | SELECT DISTINCT feature FROM hotel_features WHERE location IN ('Middle East', 'South America') AND feature LIKE '%AI%' |
What is the maximum yield for crops grown by farmers in India since 2020? | CREATE TABLE Farmers (id INT PRIMARY KEY,name VARCHAR(50),age INT,location VARCHAR(50)); INSERT INTO Farmers (id,name,age,location) VALUES (1,'Ramesh Patel',45,'India'); INSERT INTO Farmers (id,name,age,location) VALUES (2,'Sita Devi',50,'Nepal'); CREATE TABLE Crops (id INT PRIMARY KEY,farmer_id INT,crop_name VARCHAR(50),yield INT,year INT); INSERT INTO Crops (id,farmer_id,crop_name,yield,year) VALUES (1,1,'Rice',800,2021); INSERT INTO Crops (id,farmer_id,crop_name,yield,year) VALUES (2,1,'Wheat',600,2020); | SELECT MAX(yield) FROM Crops JOIN Farmers ON Crops.farmer_id = Farmers.id WHERE Farmers.location = 'India' AND year >= 2020; |
What is the maximum temperature recorded in the Antarctic Ocean? | CREATE TABLE antarctic_ocean_temperature (location TEXT,temperature REAL); INSERT INTO antarctic_ocean_temperature (location,temperature) VALUES ('Antarctic Ocean',2.8),('Weddell Sea',1.8),('Ross Sea',0.8); | SELECT MAX(temperature) FROM antarctic_ocean_temperature; |
Find the difference in streams between the most and least streamed songs in the Blues genre. | CREATE TABLE songs (id INT,title TEXT,release_year INT,genre TEXT,streams INT); INSERT INTO songs (id,title,release_year,genre,streams) VALUES (1,'Song1',2021,'Blues',180000); INSERT INTO songs (id,title,release_year,genre,streams) VALUES (2,'Song2',2021,'Blues',160000); INSERT INTO songs (id,title,release_year,genre,streams) VALUES (3,'Song3',2020,'Jazz',150000); CREATE TABLE artists (id INT,artist_name TEXT); | SELECT MAX(streams) - MIN(streams) AS stream_diff FROM songs WHERE genre = 'Blues'; |
Which African countries have the highest water usage? | CREATE TABLE african_countries (country VARCHAR(255),water_usage INT); INSERT INTO african_countries (country,water_usage) VALUES ('Egypt',12000000),('South Africa',15000000),('Nigeria',10000000); | SELECT country, water_usage FROM african_countries ORDER BY water_usage DESC LIMIT 2; |
What percentage of visitors to each exhibition identified as having a disability? | CREATE TABLE Exhibition_Demographics (id INT,exhibition VARCHAR(20),visitor_count INT,disability VARCHAR(20)); INSERT INTO Exhibition_Demographics (id,exhibition,visitor_count,disability) VALUES (1,'Pop Art',1000,'Yes'),(2,'Ancient Civilizations',1200,'No'),(3,'Pop Art',1500,'No'),(4,'Ancient Civilizations',1800,'Yes'); | SELECT exhibition, (SUM(CASE WHEN disability = 'Yes' THEN visitor_count ELSE 0 END) * 100.0 / SUM(visitor_count)) AS pct_disability FROM Exhibition_Demographics GROUP BY exhibition; |
What is the total water consumption in Indonesia in 2017? | CREATE TABLE water_consumption (country VARCHAR(20),year INT,consumption FLOAT); INSERT INTO water_consumption (country,year,consumption) VALUES ('Indonesia',2017,34000000); | SELECT consumption FROM water_consumption WHERE country = 'Indonesia' AND year = 2017; |
Update the recycling rate for 'Contributor D' to 0.3 in the 'recycling_data' table. | CREATE TABLE recycling_data (contributor VARCHAR(20),recycling_rate FLOAT); INSERT INTO recycling_data (contributor,recycling_rate) VALUES ('Contributor A',0.35),('Contributor B',0.27),('Contributor C',0.4),('Contributor D',NULL); | UPDATE recycling_data SET recycling_rate = 0.3 WHERE contributor = 'Contributor D'; |
What is the percentage of sustainable material used out of the total material used by each brand? | CREATE TABLE Brands (BrandID INT,BrandName VARCHAR(50)); INSERT INTO Brands (BrandID,BrandName) VALUES (1,'H&M'),(2,'Zara'),(3,'Levi''s'); CREATE TABLE Materials (MaterialID INT,MaterialName VARCHAR(50),BrandID INT,QuantityUsed INT,TotalQuantity INT); INSERT INTO Materials (MaterialID,MaterialName,BrandID,QuantityUsed,TotalQuantity) VALUES (1,'Organic Cotton',1,5000,10000),(2,'Recycled Polyester',1,3000,10000),(3,'Organic Cotton',2,7000,15000),(4,'Tencel',2,4000,15000),(5,'Recycled Cotton',3,6000,12000),(6,'Hemp',3,2000,12000); | SELECT BrandName, (SUM(QuantityUsed) * 100.0 / SUM(TotalQuantity)) AS Percentage FROM Materials GROUP BY BrandName; |
How many space missions were joint missions? | CREATE TABLE missions(name TEXT,agency TEXT,launch_date TEXT,joint_mission BOOLEAN); INSERT INTO missions(name,agency,launch_date,joint_mission) VALUES('Apollo 11','NASA','1969-07-16',FALSE),('Apollo-Soyuz','NASA','1975-07-15',TRUE); | SELECT COUNT(*) FROM missions WHERE joint_mission = TRUE; |
How many aquaculture farms are located in each country and their total production in metric tons? | CREATE TABLE Farm (farm_id INT,country VARCHAR(50),production DECIMAL(10,2)); INSERT INTO Farm (farm_id,country,production) VALUES (1,'Norway',5000.5),(2,'Chile',3500.3),(3,'Canada',2000.0); | SELECT Farm.country, COUNT(Farm.farm_id) as NumFarms, SUM(Farm.production) as TotalProduction FROM Farm GROUP BY Farm.country; |
How many Mars rovers have been deployed by NASA? | CREATE TABLE mars_rovers (id INT,rover_name VARCHAR(50),agency VARCHAR(50),status VARCHAR(20)); INSERT INTO mars_rovers (id,rover_name,agency,status) VALUES (1,'Spirit','NASA','decommissioned'),(2,'Opportunity','NASA','decommissioned'),(3,'Curiosity','NASA','active'); | SELECT COUNT(*) FROM mars_rovers WHERE agency = 'NASA'; |
What is the average mental health parity violation score for facilities in the Midwest region? | CREATE TABLE mental_health_parity_violations (violation_id INT,region VARCHAR(255),score INT); INSERT INTO mental_health_parity_violations (violation_id,region,score) VALUES (1,'Northeast',80),(2,'Southeast',70),(3,'Midwest',60),(4,'West',90),(5,'Northeast',85),(6,'Southeast',75),(7,'Midwest',65),(8,'West',95); | SELECT AVG(score) as avg_score FROM mental_health_parity_violations WHERE region = 'Midwest'; |
What is the earliest release date for a game with a genre of 'Role-playing' and the number of players who have played it? | CREATE TABLE GamePlay (PlayerID INT,GameID INT); INSERT INTO GamePlay (PlayerID,GameID) VALUES (2,2); CREATE TABLE Games (GameID INT,Name VARCHAR(50),Genre VARCHAR(20),ReleaseDate DATETIME,Publisher VARCHAR(50)); INSERT INTO Games (GameID,Name,Genre,ReleaseDate,Publisher) VALUES (4,'The Elder Scrolls V: Skyrim','Role-playing','2011-11-11','Bethesda Softworks'); | SELECT MIN(ReleaseDate) AS Earliest_Release_Date, COUNT(DISTINCT gp.PlayerID) FROM Games g INNER JOIN GamePlay gp ON g.GameID = gp.GameID WHERE g.Genre = 'Role-playing'; |
How many space missions have been attempted by India? | CREATE TABLE space_exploration (id INT,mission_name VARCHAR(255),country VARCHAR(255),success BOOLEAN); | SELECT COUNT(*) FROM space_exploration WHERE country = 'India'; |
Find the clinic location with the highest total patient wait time, in the "rural_clinics" table with patient wait time data. | CREATE TABLE rural_clinics (clinic_location VARCHAR(255),patient_wait_time INT); INSERT INTO rural_clinics (clinic_location,patient_wait_time) VALUES ('Location1',15),('Location1',20),('Location1',25),('Location2',10),('Location2',12),('Location3',30),('Location3',35),('Location3',40); | SELECT clinic_location, SUM(patient_wait_time) AS total_wait_time FROM rural_clinics GROUP BY clinic_location ORDER BY total_wait_time DESC FETCH FIRST 1 ROW ONLY; |
What was the average number of streams per user for a specific song? | CREATE TABLE Streaming (user INT,song VARCHAR(50),streams INT); INSERT INTO Streaming (user,song,streams) VALUES (1,'Shape of You',10),(1,'Bad Guy',5),(2,'Shape of You',7),(2,'Bad Guy',8),(3,'Shape of You',9),(3,'Bad Guy',6); | SELECT song, AVG(streams) FROM Streaming GROUP BY song; |
Identify the traditional art forms that are unique to each country. | CREATE TABLE TraditionalArtists (id INT,name VARCHAR(50),art VARCHAR(50),country VARCHAR(50)); | SELECT art, country FROM TraditionalArtists GROUP BY art, country HAVING COUNT(*) = 1; |
What is the distribution of customer complaints by category in the 'Asia-Pacific' region in the past month? | CREATE TABLE customer_complaints (complaint_id INT,complaint_category VARCHAR(50),region VARCHAR(50),complaint_date DATE); INSERT INTO customer_complaints (complaint_id,complaint_category,region,complaint_date) VALUES (1,'Billing','Asia-Pacific','2023-03-01'),(2,'Network','Asia-Pacific','2023-03-05'),(3,'Billing','Asia-Pacific','2023-03-10'),(4,'Customer Service','Asia-Pacific','2023-03-15'); | SELECT region, complaint_category, COUNT(*) as complaint_count, PERCENT_RANK() OVER (PARTITION BY region ORDER BY complaint_count DESC) as complaint_percentile FROM customer_complaints WHERE region = 'Asia-Pacific' AND complaint_date >= CURRENT_DATE - INTERVAL '1 month' GROUP BY region, complaint_category; |
Update the country of 'Angkor Wat' to 'Cambodia' | CREATE TABLE HeritageSites (Id INT,Name TEXT,Country TEXT); INSERT INTO HeritageSites (Id,Name,Country) VALUES (1,'Angkor Wat','Thailand'); | UPDATE HeritageSites SET Country = 'Cambodia' WHERE Name = 'Angkor Wat'; |
Insert a new record for an exhibition 'Indigenous Art' starting from 2025-01-01 until 2025-12-31. | CREATE TABLE Exhibitions (exhibition_id INT,exhibition_name VARCHAR(50),start_date DATE,end_date DATE); | INSERT INTO Exhibitions (exhibition_id, exhibition_name, start_date, end_date) VALUES (5, 'Indigenous Art', '2025-01-01', '2025-12-31'); |
List the number of hospitals, clinics, and pharmacies in each state of Mexico, sorted by the total number of rural healthcare facilities. | CREATE TABLE facilities (id INT,name VARCHAR,facility_type VARCHAR); INSERT INTO facilities (id,name,facility_type) VALUES (1,'Rural General Hospital','hospital'),(2,'Urban Community Clinic','clinic'),(3,'Remote Pharmacy','pharmacy'); CREATE TABLE state_codes (id INT,state VARCHAR,country VARCHAR); INSERT INTO state_codes (id,state,country) VALUES (1,'Oaxaca','Mexico'),(2,'CDMX','Mexico'); | SELECT state_codes.country, state_codes.state, COUNT(facilities.id), SUM(facilities.id) FROM facilities INNER JOIN state_codes ON facilities.id = state_codes.id AND facilities.facility_type IN ('hospital', 'clinic', 'pharmacy') GROUP BY state_codes.country, state_codes.state ORDER BY SUM(facilities.id) DESC; |
What is the maximum sustainable yield of Tilapia in the Mediterranean in 2022? | CREATE TABLE msy (species VARCHAR(255),msy_value FLOAT,year INT,region VARCHAR(255),PRIMARY KEY (species,year,region)); INSERT INTO msy (species,msy_value,year,region) VALUES ('Tilapia',25000,2022,'Mediterranean'),('Tuna',30000,2022,'Mediterranean'),('Salmon',15000,2022,'North Atlantic'); | SELECT msy_value FROM msy WHERE species = 'Tilapia' AND year = 2022 AND region = 'Mediterranean'; |
List all sustainable building practices in Washington state, with their respective descriptions | CREATE TABLE sustainable_practices_3 (practice_id INT,state VARCHAR(20),building_type VARCHAR(20),description TEXT); INSERT INTO sustainable_practices_3 (practice_id,state,building_type,description) VALUES (1,'WA','Residential','Use of recycled materials'),(2,'WA','Commercial','Solar panel installations'),(3,'WA','Industrial','Energy-efficient insulation'); | SELECT * FROM sustainable_practices_3 WHERE state = 'WA'; |
List the top 2 technology for social good projects by budget in the APAC region? | CREATE TABLE tech_social_good (project VARCHAR(255),budget FLOAT,region VARCHAR(255)); INSERT INTO tech_social_good (project,budget,region) VALUES ('Project X',800000,'APAC'),('Project Y',650000,'APAC'),('Project Z',700000,'EMEA'),('Project W',500000,'APAC'); | SELECT project, budget FROM (SELECT project, budget, RANK() OVER (PARTITION BY region ORDER BY budget DESC) AS rank FROM tech_social_good WHERE region = 'APAC') WHERE rank <= 2; |
What is the maximum speed recorded for vessels traveling from Port C to Port D? | CREATE TABLE Vessels (id INT,name TEXT,speed FLOAT,depart_port TEXT,arrive_port TEXT); INSERT INTO Vessels (id,name,speed,depart_port,arrive_port) VALUES (1,'Vessel1',22.5,'Port C','Port D'); INSERT INTO Vessels (id,name,speed,depart_port,arrive_port) VALUES (2,'Vessel2',27.0,'Port C','Port D'); | SELECT MAX(speed) FROM Vessels WHERE depart_port = 'Port C' AND arrive_port = 'Port D'; |
What is the minimum number of hours spent by students in lifelong learning activities in each district? | CREATE TABLE districts (district_id INT,district_name TEXT,num_students INT); CREATE TABLE activities (activity_id INT,activity_name TEXT,district_id INT,student_id INT,hours_spent INT); INSERT INTO districts (district_id,district_name,num_students) VALUES (1,'North District',500),(2,'South District',400),(3,'East District',600); INSERT INTO activities (activity_id,activity_name,district_id,student_id,hours_spent) VALUES (1,'Online Course',1,1,10),(2,'Book Club',1,2,5),(3,'Coding Club',2,1,15),(4,'Volunteer Work',2,2,12),(5,'Travel',3,1,20),(6,'Workshop',3,2,18); | SELECT district_name, MIN(hours_spent) as min_hours FROM districts JOIN activities ON districts.district_id = activities.district_id GROUP BY district_name; |
How many hotels in New York have achieved a sustainability rating? | CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,city TEXT,sustainability_rating INT); INSERT INTO hotels (hotel_id,hotel_name,city,sustainability_rating) VALUES (1,'Hotel A','New York',3),(2,'Hotel B','New York',NULL),(3,'Hotel C','New York',5); | SELECT COUNT(*) FROM hotels WHERE city = 'New York' AND sustainability_rating IS NOT NULL; |
What is the total number of hospitals in Mexico providing cancer treatment? | CREATE TABLE hospitals (id INT,name TEXT,country TEXT,cancer_treatment BOOLEAN); | SELECT COUNT(*) FROM hospitals WHERE country = 'Mexico' AND cancer_treatment = true; |
How many conservation efforts have been implemented for turtles? | CREATE TABLE conservation_efforts (id INT,species VARCHAR(50),year INT,protected_area VARCHAR(50),efforts VARCHAR(50)); INSERT INTO conservation_efforts (id,species,year,protected_area,efforts) VALUES (1,'Green Sea Turtle',2010,'Galapagos Marine Reserve','Habitat protection'); INSERT INTO conservation_efforts (id,species,year,protected_area,efforts) VALUES (2,'Leatherback Sea Turtle',2015,'Monterey Bay National Marine Sanctuary','Bycatch reduction programs'); | SELECT SUM(CASE WHEN species LIKE '%Turtle%' THEN 1 ELSE 0 END) FROM conservation_efforts; |
What is the average age of artists who have exhibited in galleries located in the Central Business District? | CREATE TABLE galleries (id INT,name TEXT,location TEXT,city TEXT,state TEXT,zip INT); INSERT INTO galleries (id,name,location,city,state,zip) VALUES (1,'Gallery A','Central Business District','Los Angeles','CA',90001); CREATE TABLE artists (id INT,name TEXT,age INT,gallery_id INT); INSERT INTO artists (id,name,age,gallery_id) VALUES (1,'Alice',35,1); | SELECT AVG(age) FROM artists JOIN galleries ON artists.gallery_id = galleries.id WHERE galleries.location = 'Central Business District'; |
How many calls were made before '2022-01-02' in the 'rural_fire' table? | CREATE TABLE rural_fire (id INT,call_type VARCHAR(20),call_date TIMESTAMP); INSERT INTO rural_fire VALUES (1,'fire','2022-01-01 15:00:00'),(2,'fire','2022-01-03 16:00:00'); | SELECT COUNT(*) FROM rural_fire WHERE call_date < '2022-01-02'; |
List all the columns in table 'hotel_reservations' | CREATE TABLE hotel_reservations (reservation_id INT,hotel_id INT,guest_name TEXT,arrival_date DATE,departure_date DATE,num_guests INT,payment_amount FLOAT,is_cancelled BOOLEAN); | SELECT * FROM hotel_reservations; |
Show the unique months in which Yttrium and Samarium had the highest production quantity | CREATE TABLE production (element VARCHAR(10),year INT,month INT,quantity INT); INSERT INTO production (element,year,month,quantity) VALUES ('Yttrium',2015,1,40),('Yttrium',2015,2,45),('Yttrium',2016,1,50),('Yttrium',2016,2,55),('Samarium',2015,1,60),('Samarium',2015,2,65),('Samarium',2016,1,70),('Samarium',2016,2,75); | SELECT element, month FROM (SELECT element, month, ROW_NUMBER() OVER (PARTITION BY element ORDER BY quantity DESC) AS rn FROM production WHERE element IN ('Yttrium', 'Samarium')) t WHERE rn = 1; |
What is the average age of clients who won their cases? | CREATE TABLE ClientDemographics (ClientID INT,Age INT,Won BOOLEAN); INSERT INTO ClientDemographics (ClientID,Age,Won) VALUES (1,35,TRUE),(2,45,FALSE); | SELECT AVG(ClientDemographics.Age) FROM ClientDemographics WHERE ClientDemographics.Won = TRUE; |
What is the average yield of potatoes in Idaho, broken down by variety? | CREATE TABLE potatoes (id INT,state VARCHAR(20),variety VARCHAR(20),yield INT); INSERT INTO potatoes (id,state,variety,yield) VALUES (1,'Idaho','Russet',2000),(2,'Idaho','Red',1800),(3,'Idaho','Yukon Gold',2200),(4,'Idaho','Russet',2100),(5,'Idaho','Red',1900); | SELECT variety, AVG(yield) FROM potatoes WHERE state = 'Idaho' GROUP BY variety; |
Delete the record with ID 3 from the marine_species table | CREATE TABLE marine_species (id INT PRIMARY KEY,name VARCHAR(255),conservation_status VARCHAR(255),habitat VARCHAR(255)); | WITH deleted_species AS (DELETE FROM marine_species WHERE id = 3 RETURNING *) SELECT * FROM deleted_species; |
What is the maximum number of passengers allowed on cruise ships registered in the Baltic Sea? | CREATE TABLE cruise_ships (id INT,name TEXT,passengers INT,registry TEXT); | SELECT MAX(passengers) FROM cruise_ships WHERE registry = 'Baltic Sea'; |
How many containers were shipped from the US to the Netherlands in Q1 of 2019? | CREATE TABLE ports (port_id INT,port_name TEXT,country TEXT);CREATE TABLE shipments (shipment_id INT,shipment_weight INT,ship_date DATE,port_id INT); INSERT INTO ports VALUES (1,'Port of Oakland','USA'),(2,'Port of Rotterdam','Netherlands'); INSERT INTO shipments VALUES (1,2000,'2019-01-01',1),(2,1500,'2019-02-15',2); | SELECT COUNT(*) FROM shipments JOIN ports ON shipments.port_id = ports.port_id WHERE ports.country = 'USA' AND ports.port_name = 'Port of Oakland' AND ship_date BETWEEN '2019-01-01' AND '2019-03-31'; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.