instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
What is the average water consumption in the agricultural sector in Australia for the year 2020? | CREATE TABLE water_consumption_kl (region VARCHAR(20),sector VARCHAR(20),year INT,value FLOAT); INSERT INTO water_consumption_kl (region,sector,year,value) VALUES ('Australia','Agricultural',2020,12000000); | SELECT AVG(value) FROM water_consumption_kl WHERE sector = 'Agricultural' AND region = 'Australia' AND year = 2020; |
What is the maximum water consumption by a single customer in the city of Miami? | CREATE TABLE miami_customers (customer_id INT,city VARCHAR(20),water_usage FLOAT); INSERT INTO miami_customers (customer_id,city,water_usage) VALUES (1,'Miami',5000),(2,'Miami',7000),(3,'Miami',8000),(4,'Miami',9000); | SELECT MAX(water_usage) FROM miami_customers; |
Find the percentage of AI researchers who are from underrepresented countries, rounded to two decimal places. | CREATE TABLE ai_researchers (id INT,name VARCHAR(100),gender VARCHAR(10),country VARCHAR(50),published_papers INT); INSERT INTO ai_researchers (id,name,gender,country,published_papers) VALUES (1,'Alice','Female','USA',3),(2,'Bob','Male','Canada',0),(3,'Charlotte','Female','UK',2),(4,'David','Male','USA',1),(5,'Eva','Female','Germany',0),(6,'Francisco','Male','Mexico',2); | SELECT ROUND(100.0 * SUM(CASE WHEN country IN ('Mexico', 'India', 'Brazil', 'South Africa', 'Indonesia') THEN 1 ELSE 0 END) / COUNT(*), 2) AS percentage_underrepresented_countries FROM ai_researchers; |
What is the maximum bias score for each creative AI application? | CREATE TABLE CreativeAIs (id INT,name VARCHAR(255),bias_score DECIMAL(5,2)); INSERT INTO CreativeAIs (id,name,bias_score) VALUES (1,'AI Painter',0.15),(2,'AI Music Composer',0.08),(3,'AI Poet',0.12); | SELECT name, MAX(bias_score) as max_bias_score FROM CreativeAIs GROUP BY name; |
Which explainable AI techniques are most frequently used in financial services? | CREATE TABLE Financial_Services (ID INT,Company VARCHAR(50),Explainable_AI VARCHAR(50)); INSERT INTO Financial_Services (ID,Company,Explainable_AI) VALUES (1,'CompanyA','LIME'),(2,'CompanyB','SHAP'),(3,'CompanyC','LIME'),(4,'CompanyD','SHAP'),(5,'CompanyE','TreeExplainer'); | SELECT Explainable_AI, COUNT(*) OVER (PARTITION BY Explainable_AI) as Count FROM Financial_Services WHERE Explainable_AI IN ('LIME', 'SHAP', 'TreeExplainer') ORDER BY Count DESC; |
Delete records with a start_date after 2023 in the economic_diversification table | CREATE TABLE economic_diversification (id INT PRIMARY KEY,name VARCHAR(255),description TEXT,start_date DATE,end_date DATE); | WITH cte AS (DELETE FROM economic_diversification WHERE start_date > '2023-01-01') SELECT * FROM cte; |
Update records in the agricultural_innovations table with rural_innovation_id 2 to have a year of 2024 | CREATE TABLE agricultural_innovations (id INT PRIMARY KEY,rural_innovation_id INT,name VARCHAR(255),description TEXT,year INT); | WITH cte AS (UPDATE agricultural_innovations SET year = 2024 WHERE rural_innovation_id = 2) SELECT * FROM cte; |
Find the types of fish farmed in Canada and their respective quantities. | CREATE TABLE FarmB (species VARCHAR(20),country VARCHAR(20),quantity INT); INSERT INTO FarmB (species,country,quantity) VALUES ('Salmon','Canada',120000); INSERT INTO FarmB (species,country,quantity) VALUES ('Trout','Canada',45000); INSERT INTO FarmB (species,country,quantity) VALUES ('Cod','Canada',28000); | SELECT species, quantity FROM FarmB WHERE country = 'Canada'; |
What is the average stocking density of fish in freshwater farms, grouped by farm type, where the density is greater than 1000 fish per cubic meter? | CREATE TABLE freshwater_farms (farm_id INT,farm_type VARCHAR(255),stocking_density INT); INSERT INTO freshwater_farms (farm_id,farm_type,stocking_density) VALUES (1,'Pond',1200),(2,'Cage',1500),(3,'Recirculating',2000),(4,'Pond',800),(5,'Cage',1200); | SELECT farm_type, AVG(stocking_density) FROM freshwater_farms WHERE stocking_density > 1000 GROUP BY farm_type; |
What is the average amount donated by each gender? | CREATE TABLE Donors (id INT,gender VARCHAR(10),donation_id INT); INSERT INTO Donors (id,gender,donation_id) VALUES (1,'Male',1001),(2,'Female',1002),(3,'Male',1003); CREATE TABLE Donations (id INT,donor_id INT,amount DECIMAL(10,2)); INSERT INTO Donations (id,donor_id,amount) VALUES (1001,1,50.00),(1002,2,75.00),(1003,3,100.00); | SELECT g.gender, AVG(d.amount) as avg_donation FROM Donors g JOIN Donations d ON g.id = d.donor_id GROUP BY g.gender; |
What is the total number of tickets sold by each event category? | CREATE TABLE events (event_id INT,event_name VARCHAR(50),event_category VARCHAR(50)); INSERT INTO events (event_id,event_name,event_category) VALUES (1,'Dance Performance','Dance'),(2,'Theatre Play','Theatre'),(3,'Art Exhibit','Visual Arts'); | SELECT event_category, SUM(tickets_sold) FROM events e JOIN tickets t ON e.event_id = t.event_id GROUP BY event_category; |
How many viewers in Canada watched TV shows with a rating above 8.5 in 2022? | CREATE TABLE TV_Shows (region VARCHAR(20),year INT,rating DECIMAL(2,1),viewers INT); INSERT INTO TV_Shows (region,year,rating,viewers) VALUES ('Canada',2022,8.2,1000000),('Canada',2022,8.7,800000),('Canada',2022,9.1,1200000); | SELECT COUNT(*) FROM (SELECT * FROM TV_Shows WHERE region = 'Canada' AND year = 2022 AND rating > 8.5) AS high_rated_shows; |
What was the average project cost for sustainable buildings in Arizona in Q3 2022? | CREATE TABLE Sustainable_Buildings_AZ (id INT,project_cost FLOAT,state VARCHAR(255),quarter VARCHAR(255)); INSERT INTO Sustainable_Buildings_AZ (id,project_cost,state,quarter) VALUES (1,600000,'Arizona','Q3 2022'); INSERT INTO Sustainable_Buildings_AZ (id,project_cost,state,quarter) VALUES (2,700000,'Arizona','Q3 2022'); INSERT INTO Sustainable_Buildings_AZ (id,project_cost,state,quarter) VALUES (3,800000,'Arizona','Q3 2022'); | SELECT AVG(project_cost) FROM Sustainable_Buildings_AZ WHERE state = 'Arizona' AND quarter = 'Q3 2022'; |
What was the total revenue from cannabis-infused edibles sold by each dispensary in the city of San Francisco in the month of December 2021? | CREATE TABLE Dispensaries (id INT,name VARCHAR(255),city VARCHAR(255),state VARCHAR(255));CREATE TABLE Inventory (id INT,dispensary_id INT,revenue DECIMAL(10,2),product_type VARCHAR(255),month INT,year INT);INSERT INTO Dispensaries (id,name,city,state) VALUES (1,'Golden Gate Greens','San Francisco','CA');INSERT INTO Inventory (id,dispensary_id,revenue,product_type,month,year) VALUES (1,1,2000,'edibles',12,2021); | SELECT d.name, SUM(i.revenue) as total_revenue FROM Dispensaries d JOIN Inventory i ON d.id = i.dispensary_id WHERE d.city = 'San Francisco' AND i.product_type = 'edibles' AND i.month = 12 AND i.year = 2021 GROUP BY d.name; |
What was the average CO2 emission reduction target for each country in 2020? | CREATE TABLE co2_reduction_targets (country TEXT,year INT,target FLOAT); INSERT INTO co2_reduction_targets (country,year,target) VALUES ('USA',2015,10.0),('China',2015,12.0),('Germany',2015,15.0),('France',2015,20.0),('Brazil',2015,25.0),('USA',2020,12.0),('China',2020,14.0),('Germany',2020,17.0),('France',2020,22.0),('Brazil',2020,27.0); | SELECT country, AVG(target) as avg_target FROM co2_reduction_targets WHERE year IN (2020) GROUP BY country; |
What is the average number of days from drug approval to the completion of Phase 3 clinical trials for drugs that were approved after 2015? | CREATE TABLE clinical_trials (id INT PRIMARY KEY,drug_id INT,phase VARCHAR(50),completion_date DATE); CREATE TABLE drugs (id INT PRIMARY KEY,name VARCHAR(255),manufacturer VARCHAR(255),approval_date DATE); | SELECT AVG(ct.completion_date - d.approval_date) as avg_days_to_phase FROM clinical_trials ct JOIN drugs d ON ct.drug_id = d.id WHERE ct.phase = 'Phase 3' AND d.approval_date > '2015-01-01'; |
Find the number of unique healthcare centers in the USA where at least 5 infectious disease cases were reported in the last month. | CREATE TABLE healthcare_centers (id INT,name TEXT,country TEXT,created_at TIMESTAMP); INSERT INTO healthcare_centers (id,name,country,created_at) VALUES (1,'St. John Hospital','USA','2021-01-01 10:00:00'),(2,'Montreal General Hospital','Canada','2021-01-02 12:00:00'); CREATE TABLE infectious_disease_reports (id INT,patient_id INT,healthcare_center_id INT,report_date TIMESTAMP); INSERT INTO infectious_disease_reports (id,patient_id,healthcare_center_id,report_date) VALUES (1,1,1,'2021-07-10 14:30:00'),(2,2,1,'2021-06-15 09:00:00'),(3,3,2,'2021-07-16 11:00:00'); | SELECT COUNT(DISTINCT healthcare_centers.id) FROM healthcare_centers JOIN infectious_disease_reports ON healthcare_centers.id = infectious_disease_reports.healthcare_center_id WHERE infectious_disease_reports.report_date >= DATEADD(month, -1, CURRENT_TIMESTAMP) GROUP BY healthcare_centers.id HAVING COUNT(infectious_disease_reports.id) >= 5 AND healthcare_centers.country = 'USA'; |
What is the average rating of hospitals with over 10000 patients served, grouped by state? | CREATE TABLE public.healthcare_access (id SERIAL PRIMARY KEY,state TEXT,city TEXT,facility_type TEXT,patients_served INT,rating INT); INSERT INTO public.healthcare_access (state,city,facility_type,patients_served,rating) VALUES ('Texas','Dallas','Clinic',3000,7),('Florida','Miami','Hospital',8000,9),('Texas','Houston','Hospital',12000,8); | SELECT state, facility_type, AVG(rating) AS avg_rating FROM public.healthcare_access WHERE patients_served > 10000 GROUP BY state, facility_type; |
What was the life expectancy in Japan in 2019? | CREATE TABLE life_expectancy (id INT,country VARCHAR(50),year INT,expectancy DECIMAL(5,2)); INSERT INTO life_expectancy (id,country,year,expectancy) VALUES (1,'Japan',2019,84.43),(2,'Japan',2018,83.98); | SELECT expectancy FROM life_expectancy WHERE country = 'Japan' AND year = 2019; |
What is the average yield of crops for each indigenous community? | CREATE TABLE indigenous_communities (id INT,name VARCHAR(255)); INSERT INTO indigenous_communities VALUES (1,'Mayans'),(2,'Navajos'); CREATE TABLE crop_yields (community_id INT,yield INT); | SELECT ic.name, AVG(cy.yield) as avg_yield FROM indigenous_communities ic JOIN crop_yields cy ON ic.id = cy.community_id GROUP BY ic.id, ic.name; |
What are the cosmetic brands that use cruelty-free ingredients? | CREATE TABLE if not exists brand (id INT PRIMARY KEY,name TEXT,category TEXT,country TEXT,cruelty_free BOOLEAN); INSERT INTO brand (id,name,category,country,cruelty_free) VALUES (2,'The Body Shop','Cosmetics','United Kingdom',true); | SELECT name FROM brand WHERE cruelty_free = true; |
What was the minimum response time for police calls in January 2022? | CREATE TABLE police_calls (id INT,call_date DATE,response_time INT); INSERT INTO police_calls (id,call_date,response_time) VALUES (1,'2022-01-01',10),(2,'2022-01-02',15),(3,'2022-01-03',12); | SELECT MIN(response_time) FROM police_calls WHERE call_date BETWEEN '2022-01-01' AND '2022-01-31'; |
What is the total number of artworks by each artist? | CREATE TABLE Artists (ArtistID INT,ArtistName TEXT); INSERT INTO Artists (ArtistID,ArtistName) VALUES (1,'Picasso'),(2,'Van Gogh'); CREATE TABLE Artworks (ArtworkID INT,ArtistID INT,Title TEXT); INSERT INTO Artworks (ArtworkID,ArtistID,Title) VALUES (1,1,'Guernica'),(2,1,'Three Musicians'),(3,2,'Starry Night'),(4,2,'Sunflowers'); | SELECT ArtistID, COUNT(*) as TotalArtworks FROM Artworks GROUP BY ArtistID; |
Add new diplomacy meeting records for 'Iraq', 'Colombia', and 'Indonesia' with meeting outcomes 'Successful', 'Pending', and 'Failed' respectively | CREATE TABLE diplomacy_meetings (meeting_id INT,country_name VARCHAR(50),meeting_date DATE,meeting_outcome VARCHAR(20)); | INSERT INTO diplomacy_meetings (country_name, meeting_outcome) VALUES ('Iraq', 'Successful'), ('Colombia', 'Pending'), ('Indonesia', 'Failed'); |
List all defense diplomacy events in Asia in 2018. | CREATE TABLE defense_diplomacy (event_id INT,event_name VARCHAR(255),region VARCHAR(255),date DATE); INSERT INTO defense_diplomacy (event_id,event_name,region,date) VALUES (1,'Event A','Asia','2018-01-01'),(2,'Event B','Asia','2018-12-31'),(3,'Event C','Europe','2018-07-04'); CREATE TABLE regions (region VARCHAR(255)); | SELECT event_name FROM defense_diplomacy INNER JOIN regions ON defense_diplomacy.region = regions.region WHERE region = 'Asia' AND date >= '2018-01-01' AND date <= '2018-12-31'; |
What is the maximum salary in the Research and Development department? | CREATE TABLE Employees (id INT,name VARCHAR(50),department VARCHAR(50),salary DECIMAL(10,2)); | SELECT MAX(salary) FROM Employees WHERE department = 'Research and Development'; |
What is the median age of artifacts in the 'Prehistoric_Artifacts' table? | CREATE TABLE Prehistoric_Artifacts (id INT,artifact_name VARCHAR(50),age INT); INSERT INTO Prehistoric_Artifacts (id,artifact_name,age) VALUES (1,'Hand Axe',25000),(2,'Stone Spear',20000),(3,'Flint Knife',30000); | SELECT AVG(age) FROM (SELECT artifact_name, age FROM Prehistoric_Artifacts ORDER BY age) AS subquery GROUP BY artifact_name; |
What is the total number of streams per month, by platform, for the last 12 months? | CREATE TABLE monthly_streams (stream_id INT,platform VARCHAR(255),streams INT,stream_month DATE); CREATE VIEW total_streams_per_month AS SELECT platform,DATE_TRUNC('month',stream_month) as month,SUM(streams) as total_streams FROM monthly_streams WHERE stream_month >= DATEADD(month,-12,CURRENT_DATE) GROUP BY platform,month; | SELECT * FROM total_streams_per_month; |
How many unique one-time donors made donations in 'q4' of '2022'? | CREATE TABLE Donations (id INT,donor_type VARCHAR(10),donation_amount DECIMAL(10,2),donation_date DATE); INSERT INTO Donations (id,donor_type,donation_amount,donation_date) VALUES (1,'one-time',50.00,'2022-01-01'); INSERT INTO Donations (id,donor_type,donation_amount,donation_date) VALUES (2,'recurring',25.00,'2022-01-15'); INSERT INTO Donations (id,donor_type,donation_amount,donation_date) VALUES (3,'one-time',75.00,'2022-12-31'); | SELECT COUNT(DISTINCT donor_id) FROM Donations WHERE donor_type = 'one-time' AND QUARTER(donation_date) = 4 AND YEAR(donation_date) = 2022; |
What is the installed capacity of renewable energy sources in countries that have a carbon tax? | CREATE TABLE carbon_tax (country VARCHAR(255),tax BOOLEAN); INSERT INTO carbon_tax (country,tax) VALUES ('Canada',TRUE),('Chile',TRUE),('Colombia',TRUE),('US',FALSE),('Mexico',TRUE); CREATE TABLE renewable_energy (country VARCHAR(255),capacity FLOAT); INSERT INTO renewable_energy (country,capacity) VALUES ('Canada',90000),('Chile',50000),('Colombia',30000),('US',200000),('Mexico',70000); | SELECT capacity FROM renewable_energy WHERE country IN (SELECT country FROM carbon_tax WHERE tax = TRUE); |
What is the total carbon pricing revenue for Canada in 2021? | CREATE TABLE carbon_pricing (country VARCHAR(255),year INT,revenue FLOAT); INSERT INTO carbon_pricing (country,year,revenue) VALUES ('Canada',2021,34.5),('Canada',2022,37.2); | SELECT revenue FROM carbon_pricing WHERE country = 'Canada' AND year = 2021; |
What is the production of well 'W010' in the 'OilWells' table for the year 2014? | CREATE TABLE OilWells (WellID VARCHAR(10),Production FLOAT,DrillYear INT); | SELECT Production FROM OilWells WHERE WellID = 'W010' AND DrillYear = 2014; |
What is the average home run distance for each player in the 2021 MLB season? | CREATE TABLE players (player_id INT,name TEXT,team TEXT,avg_home_run_distance FLOAT); INSERT INTO players (player_id,name,team,avg_home_run_distance) VALUES (1,'John Doe','Yankees',415.3),(2,'Jane Smith','Dodgers',401.7); | SELECT team, AVG(avg_home_run_distance) as avg_distance FROM players GROUP BY team; |
What is the highest-scoring cricket match in history and which teams were involved? | CREATE TABLE cricket_scores (match_id INT,team_1 VARCHAR(50),team_2 VARCHAR(50),team_1_score INT,team_2_score INT); INSERT INTO cricket_scores (match_id,team_1,team_2,team_1_score,team_2_score) VALUES (1,'India','Australia',417,376),(2,'England','South Africa',408,399),(3,'Pakistan','New Zealand',438,322); | SELECT team_1, team_2, team_1_score, team_2_score FROM cricket_scores WHERE team_1_score + team_2_score = (SELECT MAX(team_1_score + team_2_score) FROM cricket_scores); |
What is the maximum number of games played by each team in the 'soccer_teams' table? | CREATE TABLE soccer_teams (team_id INT,team_name VARCHAR(100),num_games INT); | SELECT team_id, MAX(num_games) FROM soccer_teams GROUP BY team_id; |
What is the total revenue generated in 'January'? | CREATE TABLE january_revenue (revenue int); INSERT INTO january_revenue (revenue) VALUES (30000),(35000),(40000); | SELECT SUM(revenue) FROM january_revenue; |
What is the average CO2 emission of transportation per order for each delivery method? | CREATE TABLE delivery_methods (id INT,delivery_method VARCHAR(255),co2_emission_kg INT,orders INT); INSERT INTO delivery_methods VALUES (1,'Standard Shipping',0.5,1000),(2,'Express Shipping',1.2,500),(3,'Standard Shipping',0.6,800),(4,'Bicycle Delivery',0.1,200); | SELECT delivery_method, AVG(co2_emission_kg/orders) FROM delivery_methods GROUP BY delivery_method; |
What's the maximum number of tweets by users from Germany in the technology category? | CREATE TABLE users (id INT,country VARCHAR(255),category VARCHAR(255),tweets INT); INSERT INTO users (id,country,category,tweets) VALUES (1,'Germany','technology',2000); | SELECT MAX(users.tweets) FROM users WHERE users.country = 'Germany' AND users.category = 'technology'; |
What is the average price of each material in the 'textiles' table? | CREATE TABLE textiles (id INT,material VARCHAR(20),price DECIMAL(5,2)); INSERT INTO textiles (id,material,price) VALUES (1,'cotton',5.50),(2,'silk',15.00),(3,'wool',12.00); | SELECT material, AVG(price) FROM textiles GROUP BY material; |
List all the Shariah-compliant investments made by ResponsibleCapital in 2020. | CREATE TABLE ResponsibleCapital (id INT,investment_type VARCHAR(20),investment_amount INT,investment_date DATE); INSERT INTO ResponsibleCapital (id,investment_type,investment_amount,investment_date) VALUES (1,'Shariah Compliant',9000,'2020-12-31'); | SELECT investment_type, investment_amount FROM ResponsibleCapital WHERE investment_type = 'Shariah Compliant' AND YEAR(investment_date) = 2020; |
Identify the suppliers offering organic products from Canada | CREATE TABLE suppliers (id INT,name VARCHAR(255),country VARCHAR(255)); CREATE TABLE products (id INT,supplier_id INT,is_organic BOOLEAN,product_country VARCHAR(255)); INSERT INTO suppliers (id,name,country) VALUES (1,'Supplier X','Canada'),(2,'Supplier Y','USA'),(3,'Supplier Z','Mexico'); INSERT INTO products (id,supplier_id,is_organic,product_country) VALUES (1,1,true,'Canada'),(2,1,false,'USA'),(3,2,true,'Mexico'),(4,2,true,'Canada'),(5,3,false,'USA'); | SELECT s.name FROM suppliers s JOIN products p ON s.id = p.supplier_id AND p.is_organic = true AND s.country = p.product_country WHERE s.country = 'Canada'; |
List all suppliers providing "vegan" products that are also in the "sustainable_practices" view | CREATE TABLE products (product_id INT,product_name VARCHAR(50),supplier_id INT,is_vegan BOOLEAN); INSERT INTO products (product_id,product_name,supplier_id,is_vegan) VALUES (1,'Almond Milk',1,true); INSERT INTO products (product_id,product_name,supplier_id,is_vegan) VALUES (2,'Tofu',2,true); CREATE TABLE suppliers (supplier_id INT,supplier_name VARCHAR(50),sustainable_practices BOOLEAN); INSERT INTO suppliers (supplier_id,supplier_name,sustainable_practices) VALUES (1,'Eden Foods',true); INSERT INTO suppliers (supplier_id,supplier_name,sustainable_practices) VALUES (2,'Tofurky',true); CREATE VIEW sustainable_practices AS SELECT supplier_id FROM suppliers WHERE sustainable_practices = true; | SELECT DISTINCT p.supplier_id, p.product_name FROM products p JOIN suppliers s ON p.supplier_id = s.supplier_id WHERE p.is_vegan = true AND s.supplier_id IN (SELECT supplier_id FROM sustainable_practices); |
What is the maximum distance for routes to 'City X'? | CREATE TABLE Routes (id INT,origin_city VARCHAR(255),destination_city VARCHAR(255),distance INT,eta INT); INSERT INTO Routes (id,origin_city,destination_city,distance,eta) VALUES (1,'City A','City X',200,2); INSERT INTO Routes (id,origin_city,destination_city,distance,eta) VALUES (2,'City B','City Y',250,3); INSERT INTO Routes (id,origin_city,destination_city,distance,eta) VALUES (3,'City C','City X',300,4); | SELECT destination_city, MAX(distance) FROM Routes WHERE destination_city = 'City X' GROUP BY destination_city; |
What is the total number of hospitals in India, and what are their names? | CREATE TABLE india_hospitals (name TEXT,type TEXT); INSERT INTO india_hospitals (name,type) VALUES ('All India Institute of Medical Sciences','Hospital'),('Postgraduate Institute of Medical Education and Research','Hospital'); | SELECT COUNT(*), name FROM india_hospitals WHERE type = 'Hospital' GROUP BY name; |
Insert a new research grant into the research_grants table | CREATE TABLE research_grants (id INT,name TEXT,amount INT); INSERT INTO research_grants (id,name,amount) VALUES (1,'Grant A',50000),(2,'Grant B',75000); | INSERT INTO research_grants (id, name, amount) VALUES (3, 'Grant C', 100000); |
Delete the entry for the green building with id 7 in the 'green_buildings' table | CREATE TABLE green_buildings (building_id INT,city VARCHAR(50),size INT); | DELETE FROM green_buildings WHERE building_id = 7; |
What is the capacity of the largest geothermal energy project in California? | CREATE TABLE geothermal_projects (project_id INT,project_name VARCHAR(255),city VARCHAR(255),state VARCHAR(255),capacity FLOAT); INSERT INTO geothermal_projects (project_id,project_name,city,state,capacity) VALUES (1,'California Geothermal One','Los Angeles','CA',80.0); INSERT INTO geothermal_projects (project_id,project_name,city,state,capacity) VALUES (2,'Geothermal Valley','San Francisco','CA',110.5); | SELECT MAX(capacity) FROM geothermal_projects WHERE state = 'CA'; |
List the names of mental health parity officers and the number of trainings they have conducted in the mental_health schema. | CREATE TABLE mental_health_parity_officers (officer_id INT,name VARCHAR(50)); CREATE TABLE trainings_conducted (officer_id INT,training_id INT); INSERT INTO mental_health_parity_officers (officer_id,name) VALUES (1,'Alice Johnson'); INSERT INTO mental_health_parity_officers (officer_id,name) VALUES (2,'Bob Brown'); INSERT INTO trainings_conducted (officer_id,training_id) VALUES (1,1); INSERT INTO trainings_conducted (officer_id,training_id) VALUES (1,2); | SELECT mental_health_parity_officers.name, COUNT(trainings_conducted.training_id) FROM mental_health_parity_officers INNER JOIN trainings_conducted ON mental_health_parity_officers.officer_id = trainings_conducted.officer_id GROUP BY mental_health_parity_officers.name; |
What is the average mental health score for patients from historically marginalized communities? | CREATE TABLE patients (id INT,name VARCHAR(100),community VARCHAR(50),mental_health_score INT); INSERT INTO patients (id,name,community,mental_health_score) VALUES (1,'Alice','African American',70),(2,'Brian','Latinx',65),(3,'Carla','Asian American',80); | SELECT AVG(mental_health_score) FROM patients WHERE community IN ('African American', 'Latinx'); |
Delete all records in the "hotel_reviews" table that do not have a rating of at least 4? | CREATE TABLE hotel_reviews (review_id INT,hotel_id INT,rating INT,review TEXT); INSERT INTO hotel_reviews (review_id,hotel_id,rating,review) VALUES (1,101,5,'Excellent stay'),(2,102,3,'Average stay'),(3,103,4,'Good stay'),(4,104,1,'Terrible stay'); | DELETE FROM hotel_reviews WHERE rating < 4; |
What is the total number of OTA (Online Travel Agency) bookings for each hotel in the USA, sorted by the hotel name? | CREATE TABLE hotel_bookings (booking_id INT,hotel_name TEXT,country TEXT,ota_name TEXT,revenue FLOAT); INSERT INTO hotel_bookings (booking_id,hotel_name,country,ota_name,revenue) VALUES (1,'Hotel X','USA','OTA 1',500),(2,'Hotel Y','USA','OTA 2',700),(3,'Hotel X','USA','OTA 3',300),(4,'Hotel Y','USA','OTA 1',600),(5,'Hotel X','USA','OTA 2',400); | SELECT hotel_name, SUM(revenue) as total_bookings FROM hotel_bookings WHERE country = 'USA' GROUP BY hotel_name ORDER BY hotel_name; |
Calculate the average price of artworks exhibited in 'New York' with the 'modern' style in the 'Exhibitions' table. | CREATE TABLE Exhibitions (id INT,artwork_id INT,exhibition_location VARCHAR(20),exhibition_style VARCHAR(20),artwork_price DECIMAL(10,2)); | SELECT AVG(artwork_price) FROM Exhibitions WHERE exhibition_location = 'New York' AND exhibition_style = 'modern'; |
What is the correlation between climate change and biodiversity in the Arctic? | CREATE TABLE Climate_Change (id INT PRIMARY KEY,year INT,temperature FLOAT,region VARCHAR(50)); CREATE TABLE Biodiversity (id INT,year INT,species_count INT,region VARCHAR(50),climate_id INT,FOREIGN KEY (climate_id) REFERENCES Climate_Change(id)); INSERT INTO Climate_Change (id,year,temperature,region) VALUES (1,2000,-10.0,'Arctic'),(2,2010,-9.5,'Arctic'); INSERT INTO Biodiversity (id,year,species_count,region,climate_id) VALUES (1,2000,100,'Arctic',1),(2,2010,105,'Arctic',2); | SELECT Climate_Change.year, Climate_Change.temperature, Biodiversity.species_count FROM Climate_Change INNER JOIN Biodiversity ON Climate_Change.id = Biodiversity.climate_id WHERE Climate_Change.region = 'Arctic'; |
What is the total number of species observed in each location, ordered by the number of species in descending order? | CREATE TABLE Animals (Id INT,Species VARCHAR(20),Count INT,Location VARCHAR(20),Last_Observed DATE); INSERT INTO Animals (Id,Species,Count,Location,Last_Observed) VALUES (1,'Walrus',15,'Arctic','2021-02-01'),(2,'Polar_Bear',10,'Arctic','2021-02-01'),(3,'Fox',20,'Arctic','2021-02-01'); | SELECT Location, COUNT(DISTINCT Species) as Total_Species FROM Animals GROUP BY Location ORDER BY Total_Species DESC; |
What is the total number of language learners for each indigenous language this year? | CREATE TABLE Languages (LanguageID INT,LanguageName VARCHAR(50),LanguageFamily VARCHAR(50),Indigenous BOOLEAN); CREATE TABLE LanguageLearners (LearnerID INT,LanguageID INT,Year INT,LearnerCount INT); INSERT INTO Languages VALUES (1,'Inuktitut','Eskimo-Aleut',TRUE),(2,'Mapudungun','Araucanian',TRUE),(3,'English','Germanic',FALSE); INSERT INTO LanguageLearners VALUES (1,1,2023,5000),(2,1,2022,4000),(3,2,2023,3000),(4,3,2023,10000); | SELECT Languages.LanguageName, SUM(LanguageLearners.LearnerCount) AS TotalLearners FROM Languages INNER JOIN LanguageLearners ON Languages.LanguageID = LanguageLearners.LanguageID WHERE Languages.Indigenous = TRUE AND Year = 2023 GROUP BY Languages.LanguageName; |
What is the average age of clinical psychologists who have treated mental health patients in Asia, ordered by the number of patients treated? | CREATE TABLE psychologists (id INT,name TEXT,age INT,country TEXT,patients INT); INSERT INTO psychologists (id,name,age,country,patients) VALUES (1,'John Lee',45,'China',75),(2,'Mei Chen',50,'Japan',60),(3,'Kim Park',40,'South Korea',80),(4,'Anand Patel',55,'India',90); | SELECT AVG(age) as avg_age FROM (SELECT age, ROW_NUMBER() OVER (PARTITION BY country ORDER BY patients DESC) as rn FROM psychologists WHERE country IN ('China', 'Japan', 'South Korea', 'India')) t WHERE rn = 1; |
What is the average cost of projects per engineer in the 'WestCoast' region, ordered by the highest average cost? | CREATE TABLE Engineers (ID INT,Name VARCHAR(255),Region VARCHAR(255),Projects INT,Cost DECIMAL(10,2)); INSERT INTO Engineers VALUES (1,'John Doe','WestCoast',5,15000.00),(2,'Jane Smith','EastCoast',3,12000.00),(3,'Mike Johnson','WestCoast',7,20000.00); | SELECT Region, AVG(Cost) AS AvgCost FROM Engineers WHERE Region = 'WestCoast' GROUP BY Region ORDER BY AvgCost DESC; |
Find the percentage change in tourism to Thailand between 2019 and 2021. | CREATE TABLE thailand_tourism (year INT,total_visitors INT); INSERT INTO thailand_tourism (year,total_visitors) VALUES (2019,40000),(2021,30000); | SELECT (30000 - 40000) * 100.0 / 40000 AS change_percentage FROM thailand_tourism WHERE year = 2021; |
What is the average number of restorative justice sessions attended, by participant's age group, for cases closed in the past year? | CREATE TABLE restorative_justice (id INT,participant_age_group VARCHAR(50),sessions_attended INT,case_closed_date DATE); | SELECT participant_age_group, AVG(sessions_attended) FROM restorative_justice WHERE case_closed_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY participant_age_group; |
List all maritime law compliance projects in the Atlantic and Southern Oceans. | CREATE TABLE atlantic_ocean (id INT,project TEXT,region TEXT); CREATE TABLE southern_ocean (id INT,project TEXT,region TEXT); INSERT INTO atlantic_ocean (id,project,region) VALUES (1,'Compliance Project A','Atlantic Ocean'),(2,'Compliance Project B','Indian Ocean'); INSERT INTO southern_ocean (id,project,region) VALUES (1,'Compliance Project C','Southern Ocean'),(2,'Compliance Project D','Southern Ocean'); | SELECT project FROM atlantic_ocean WHERE region = 'Atlantic Ocean' UNION SELECT project FROM southern_ocean WHERE region = 'Southern Ocean'; |
What is the average pollution level in the 'Arctic' region in the last year?' | CREATE TABLE pollution_data (location VARCHAR(50),region VARCHAR(20),pollution_level FLOAT,inspection_date DATE); INSERT INTO pollution_data (location,region,pollution_level,inspection_date) VALUES ('Location A','Arctic',50.2,'2022-01-01'),('Location B','Arctic',70.1,'2022-02-15'),('Location C','Antarctic',30.9,'2022-03-01'); | SELECT AVG(pollution_level) FROM pollution_data WHERE region = 'Arctic' AND inspection_date > DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR); |
What is the maximum depth of the Indian Ocean? | CREATE TABLE IndianOcean (trench_name TEXT,avg_depth FLOAT); INSERT INTO IndianOcean (trench_name,avg_depth) VALUES ('Java Trench',8075.0),('Sunda Trench',7450.0); | SELECT MAX(avg_depth) FROM IndianOcean WHERE trench_name IS NOT NULL; |
Calculate the average sales per day for a specific item | CREATE TABLE time (time_id INT,sales_time DATE); INSERT INTO time VALUES (1,'2023-02-01'),(2,'2023-02-02'),(3,'2023-02-03'),(4,'2023-02-04'),(5,'2023-02-05'); CREATE TABLE sales_by_time (time_id INT,item_id INT,sales_amount DECIMAL(5,2)); INSERT INTO sales_by_time VALUES (1,1,50.00),(2,1,75.00),(3,1,100.00),(4,1,125.00),(5,1,150.00); | SELECT AVG(sales_by_time.sales_amount) FROM sales_by_time JOIN time ON sales_by_time.time_id = time.time_id WHERE sales_by_time.item_id = 1; |
List all environmental impact assessments for mining operations in Canada. | CREATE TABLE mining_operation (id INT,name VARCHAR(255),location VARCHAR(255));CREATE TABLE environmental_assessment (id INT,mining_operation_id INT,date DATE,impact VARCHAR(255)); INSERT INTO mining_operation (id,name,location) VALUES (1,'Canadian Gold','Canada'); INSERT INTO mining_operation (id,name,location) VALUES (2,'Canadian Diamond','Canada'); INSERT INTO environmental_assessment (id,mining_operation_id,date,impact) VALUES (1,1,'2020-01-01','Air pollution'); | SELECT mining_operation.name, environmental_assessment.date, environmental_assessment.impact FROM mining_operation JOIN environmental_assessment ON mining_operation.id = environmental_assessment.mining_operation_id WHERE mining_operation.location = 'Canada'; |
What types of equipment were rented in total in the 'equipment_rental' department? | CREATE TABLE equipment_rental(id INT,equipment VARCHAR(50),quantity INT); INSERT INTO equipment_rental (id,equipment,quantity) VALUES (1,'Bulldozer',10),(2,'Excavator',15),(3,'Dump Truck',8),(4,'Grader',12); | SELECT equipment, SUM(quantity) AS total_quantity FROM equipment_rental GROUP BY equipment; |
Identify the number of mobile and broadband subscribers per region, and their respective percentage contributions to total subscribers in each service category. | CREATE TABLE MobileSubscribers (SubscriberID int,Region varchar(10),Service varchar(10)); CREATE TABLE BroadbandSubscribers (SubscriberID int,Region varchar(10),Service varchar(10)); INSERT INTO MobileSubscribers (SubscriberID,Region,Service) VALUES (1,'North','mobile'),(2,'North','mobile'),(3,'South','mobile'),(4,'East','mobile'),(5,'West','broadband'); INSERT INTO BroadbandSubscribers (SubscriberID,Region,Service) VALUES (1,'North','broadband'),(2,'South','broadband'),(3,'East','broadband'),(4,'West','broadband'),(5,'North','broadband'); | SELECT R.Region, S.Service, COUNT(M.SubscriberID) AS MobileCount, COUNT(B.SubscriberID) AS BroadbandCount, (COUNT(M.SubscriberID)::float / (COUNT(M.SubscriberID) + COUNT(B.SubscriberID))) * 100 AS MobilePercent, (COUNT(B.SubscriberID)::float / (COUNT(M.SubscriberID) + COUNT(B.SubscriberID))) * 100 AS BroadbandPercent FROM MobileSubscribers M FULL OUTER JOIN BroadbandSubscribers B ON M.Region = B.Region AND M.Service = B.Service JOIN Regions R ON M.Region = R.Region JOIN Services S ON M.Service = S.Service GROUP BY R.Region, S.Service; |
Update the mobile_subscribers table to add a new subscriber with name "Jose Garcia" from Mexico City, mobile_number +521234567890 and subscription_date 2023-03-01 | CREATE TABLE mobile_subscribers (subscriber_id INT,subscriber_name VARCHAR(50),mobile_number VARCHAR(15),subscription_date DATE); | UPDATE mobile_subscribers SET subscriber_name = 'Jose Garcia', mobile_number = '+521234567890', subscription_date = '2023-03-01' WHERE subscriber_id = (SELECT MAX(subscriber_id) FROM mobile_subscribers) + 1; |
Get the number of unique genres represented by artists from the United Kingdom. | CREATE TABLE artists (id INT,name TEXT,genre TEXT,country TEXT); INSERT INTO artists (id,name,genre,country) VALUES (1,'Adele','Pop','United Kingdom'); | SELECT COUNT(DISTINCT genre) FROM artists WHERE country = 'United Kingdom'; |
How many news articles were published in the last week, categorized as 'Politics'? | CREATE TABLE news (id INT,title VARCHAR(100),category VARCHAR(20),publish_date DATE); INSERT INTO news (id,title,category,publish_date) VALUES (1,'Government announces new policy','Politics','2022-02-14'); | SELECT COUNT(*) FROM news WHERE category = 'Politics' AND publish_date >= CURDATE() - INTERVAL 1 WEEK |
What is the average donation amount for each mission_area in the 'Organizations' and 'Donations' tables? | CREATE TABLE Organizations (org_id INT,name VARCHAR(50),mission_area VARCHAR(20)); CREATE TABLE Donations (donation_id INT,org_id INT,donation_amount DECIMAL(10,2)); | SELECT O.mission_area, AVG(D.donation_amount) FROM Donations D INNER JOIN Organizations O ON D.org_id = O.org_id GROUP BY O.mission_area; |
List the names of players who have played "Cosmic Cricket" for more than 3 hours in total. | CREATE TABLE PlayerTimes (PlayerID INT,Game TEXT,TotalTime INT); INSERT INTO PlayerTimes (PlayerID,Game,TotalTime) VALUES (1,'Cosmic Cricket',210),(2,'Cosmic Cricket',180),(3,'Cosmic Cricket',240); | SELECT PlayerName FROM Players INNER JOIN PlayerTimes ON Players.PlayerID = PlayerTimes.PlayerID WHERE Game = 'Cosmic Cricket' GROUP BY PlayerID HAVING SUM(TotalTime) > 3 * 60; |
Find the number of users who played game 'A' in the last week, grouped by their regions. | CREATE TABLE games (id INT,game_name VARCHAR(255),release_date DATE); INSERT INTO games VALUES (1,'A','2020-01-01'); INSERT INTO games VALUES (2,'B','2019-06-15'); | SELECT region, COUNT(user_id) FROM user_actions WHERE game_id = (SELECT id FROM games WHERE game_name = 'A') AND action_date >= DATE_SUB(CURDATE(), INTERVAL 1 WEEK) GROUP BY region; |
What is the average annual dysprosium production for each refiner from 2017 to 2019? | CREATE TABLE DysprosiumProduction (Refiner VARCHAR(50),Year INT,Production FLOAT); INSERT INTO DysprosiumProduction(Refiner,Year,Production) VALUES ('RefinerX',2017,251.3),('RefinerX',2018,260.7),('RefinerX',2019,272.1),('RefinerY',2017,233.9),('RefinerY',2018,241.5),('RefinerY',2019,253.8),('RefinerZ',2017,304.4),('RefinerZ',2018,312.2),('RefinerZ',2019,329.6); | SELECT Refiner, AVG(Production) as Avg_Production FROM DysprosiumProduction WHERE Year IN (2017, 2018, 2019) GROUP BY Refiner; |
Which country had the highest production of Lanthanum in 2019? | CREATE TABLE production (country VARCHAR(255),element VARCHAR(255),quantity INT,year INT); INSERT INTO production (country,element,quantity,year) VALUES ('China','Lanthanum',180000,2019),('Malaysia','Lanthanum',20000,2019),('India','Lanthanum',15000,2019); | SELECT country, MAX(quantity) as max_production FROM production WHERE element = 'Lanthanum' AND year = 2019; |
Update the name of Restaurant P to 'Green Garden' in the 'restaurants' table. | CREATE TABLE restaurants (restaurant_id INT,name VARCHAR(255)); | UPDATE restaurants SET name = 'Green Garden' WHERE restaurant_id = (SELECT restaurant_id FROM restaurants WHERE name = 'Restaurant P'); |
What is the highest altitude of all satellites in Low Earth Orbit (LEO)? | CREATE TABLE leo_satellites (id INT,name VARCHAR(50),type VARCHAR(50),altitude INT); INSERT INTO leo_satellites (id,name,type,altitude) VALUES (1,'Sat1','Communication',500),(2,'Sat2','Navigation',600),(3,'Sat3','Observation',550); | SELECT MAX(altitude) FROM leo_satellites; |
What is the total number of launches by each country in the space domain? | CREATE TABLE launches (id INT,country VARCHAR(255),launch_year INT,PRIMARY KEY(id)); INSERT INTO launches (id,country,launch_year) VALUES (1,'Country1',2000),(2,'Country2',2010),(3,'Country1',2020),(4,'Country3',2015); | SELECT launches.country, COUNT(launches.id) FROM launches GROUP BY launches.country; |
Which space agency has launched the most satellites in descending order? | CREATE TABLE Space_Satellites (Satellite_ID INT,Satellite_Name VARCHAR(100),Launch_Date DATE,Country_Name VARCHAR(50),Agency_Name VARCHAR(50)); INSERT INTO Space_Satellites (Satellite_ID,Satellite_Name,Launch_Date,Country_Name,Agency_Name) VALUES (1,'Sat1','2000-01-01','USA','NASA'),(2,'Sat2','2001-01-01','Russia','Roscosmos'),(3,'Sat3','2002-01-01','China','CNSA'),(4,'Sat4','2003-01-01','USA','NASA'),(5,'Sat5','2004-01-01','India','ISRO'); | SELECT Agency_Name, COUNT(*) as Total_Satellites FROM Space_Satellites GROUP BY Agency_Name ORDER BY Total_Satellites DESC; |
Insert a new athlete wellbeing program for a team into the AthleteWellbeingPrograms table. | CREATE TABLE Teams (TeamID INT,TeamName VARCHAR(100)); CREATE TABLE AthleteWellbeingPrograms (ProgramID INT,TeamID INT,ProgramName VARCHAR(100),StartDate DATE,EndDate DATE); | INSERT INTO AthleteWellbeingPrograms (ProgramID, TeamID, ProgramName, StartDate, EndDate) VALUES (1, 1, 'Mental Health Workshops', '2023-01-01', '2023-12-31'); |
Insert a new record for the 'Golden State Warriors' with 500 tickets sold. | CREATE TABLE teams (id INT,name TEXT,city TEXT); INSERT INTO teams (id,name,city) VALUES (1,'Boston Celtics','Boston'),(2,'NY Knicks','NY'),(3,'LA Lakers','LA'),(4,'Atlanta Hawks','Atlanta'),(5,'Chicago Bulls','Chicago'),(6,'Golden State Warriors','San Francisco'); CREATE TABLE tickets (id INT,team TEXT,home_team TEXT,quantity INT); | INSERT INTO tickets (id, team, quantity) VALUES (7, 'Golden State Warriors', 500); |
How many autonomous buses are in the "fleet" table? | CREATE TABLE fleet (id INT,vehicle_type VARCHAR(255),is_autonomous BOOLEAN); INSERT INTO fleet (id,vehicle_type,is_autonomous) VALUES (1,'Bus',true); | SELECT COUNT(*) FROM fleet WHERE vehicle_type = 'Bus' AND is_autonomous = true; |
What is the total claim amount for policies sold in the first quarter of each year? | CREATE TABLE Claims (PolicyID int,ClaimAmount int,SaleDate date); INSERT INTO Claims (PolicyID,ClaimAmount,SaleDate) VALUES (1,500,'2022-01-05'),(2,2000,'2022-04-10'),(3,800,'2022-03-15'),(4,1500,'2022-02-20'); CREATE TABLE Policies (PolicyID int,SaleDate date); INSERT INTO Policies (PolicyID,SaleDate) VALUES (1,'2022-01-05'),(2,'2022-04-10'),(3,'2022-03-15'),(4,'2022-02-20'); | SELECT SUM(ClaimAmount) OVER (PARTITION BY DATEPART(quarter, SaleDate)) as TotalClaimAmount FROM Claims JOIN Policies ON Claims.PolicyID = Policies.PolicyID WHERE DATEPART(quarter, SaleDate) = 1; |
What is the maximum number of union organizing meetings held in the "union_database" for each month in 2021? | CREATE TABLE meetings (id INT,month INT,num_meetings INT); INSERT INTO meetings (id,month,num_meetings) VALUES (1,1,20),(2,2,25),(3,3,30),(4,4,35),(5,5,40),(6,6,45),(7,7,50),(8,8,55),(9,9,60),(10,10,65),(11,11,70),(12,12,75); | SELECT month, MAX(num_meetings) FROM meetings WHERE year = 2021 GROUP BY month; |
Insert a new row into the 'autonomous_driving_tests' table with the following values: 'Cruise', 'San Francisco', 'Level 5', '2022-07-15' | CREATE TABLE autonomous_driving_tests (company VARCHAR(255),city VARCHAR(255),autonomous_level VARCHAR(255),test_date DATE); | INSERT INTO autonomous_driving_tests (company, city, autonomous_level, test_date) VALUES ('Cruise', 'San Francisco', 'Level 5', '2022-07-15'); |
What is the name and type of the vessel with the highest average speed? | CREATE TABLE Vessels (ID VARCHAR(20),Name VARCHAR(20),Type VARCHAR(20),AverageSpeed FLOAT); INSERT INTO Vessels VALUES ('V012','Vessel L','Passenger',35.0),('V013','Vessel M','Cargo',19.5),('V014','Vessel N','Passenger',32.0); | SELECT Name, Type FROM Vessels WHERE AverageSpeed = (SELECT MAX(AverageSpeed) FROM Vessels); |
What is the total cargo capacity of vessels that are not Tankers? | CREATE TABLE Vessels (vessel_id VARCHAR(10),name VARCHAR(20),type VARCHAR(20),max_speed FLOAT,cargo_capacity INT); INSERT INTO Vessels (vessel_id,name,type,max_speed,cargo_capacity) VALUES ('1','Vessel A','Cargo',20.5,5000),('2','Vessel B','Tanker',15.2,0),('3','Vessel C','Tanker',18.1,0),('4','Vessel D','Cargo',12.6,6000),('5','Vessel E','Cargo',16.2,4500),('6','Vessel F','Passenger',30.5,2500),('7','Vessel G','Passenger',27.5,1000); | SELECT SUM(cargo_capacity) FROM Vessels WHERE type != 'Tanker'; |
Find the number of visitors from the United States | CREATE TABLE Visitor (id INT,name TEXT,country TEXT); INSERT INTO Visitor (id,name,country) VALUES (1,'Alice','USA'),(2,'Bob','Canada'); | SELECT COUNT(*) FROM Visitor WHERE country = 'USA'; |
List the names of all exhibitions that had more than 3,000 visitors on a weekend. | CREATE TABLE attendance (visitor_id INT,exhibition_name VARCHAR(255),visit_date DATE); INSERT INTO attendance (visitor_id,exhibition_name,visit_date) VALUES (123,'Art of the Renaissance','2022-01-01'),(456,'Art of the Renaissance','2022-01-02'),(789,'Modern Art','2022-01-03'),(111,'Impressionism','2022-01-04'),(222,'Cubism','2022-01-05'),(333,'Surrealism','2022-01-06'),(444,'Surrealism','2022-01-07'),(555,'Surrealism','2022-01-08'),(666,'Surrealism','2022-01-09'),(777,'Surrealism','2022-01-10'); | SELECT exhibition_name FROM attendance WHERE EXTRACT(DAY FROM visit_date) BETWEEN 6 AND 7 GROUP BY exhibition_name HAVING COUNT(*) > 3000; |
Which city had the highest average visitor spending in 2021? | CREATE TABLE CitySpending (id INT,city VARCHAR(20),year INT,spending INT); INSERT INTO CitySpending (id,city,year,spending) VALUES (1,'Paris',2021,3200),(2,'London',2021,2600),(3,'Berlin',2021,2100),(4,'New York',2021,3600),(5,'Tokyo',2021,3000); | SELECT city, AVG(spending) AS avg_spending FROM CitySpending WHERE year = 2021 GROUP BY city ORDER BY avg_spending DESC LIMIT 1; |
Insert new records into the 'circular_economy_initiatives' table for 'Tokyo', 'Japan' | CREATE TABLE circular_economy_initiatives (id INT,city VARCHAR(255),state VARCHAR(255),country VARCHAR(255),initiative VARCHAR(255)); | INSERT INTO circular_economy_initiatives (city, state, country, initiative) VALUES ('Tokyo', NULL, 'Japan', 'Extended Producer Responsibility for Electronic Waste'); |
How many algorithmic fairness papers were published before 2018? | CREATE TABLE if not exists fairness_papers (paper_id INT PRIMARY KEY,title TEXT,year INT); INSERT INTO fairness_papers (paper_id,title,year) VALUES (101,'Paper A',2017),(102,'Paper B',2018),(103,'Paper C',2019),(104,'Paper D',2020); | SELECT COUNT(*) FROM fairness_papers WHERE year < 2018; |
What is the average flight hours for each aircraft model? | CREATE TABLE flight_hours (id INT PRIMARY KEY,aircraft_model VARCHAR(50),flight_hours INT); INSERT INTO flight_hours (id,aircraft_model,flight_hours) VALUES (1,'Boeing 747',100000),(2,'Airbus A380',150000),(3,'Boeing 777',200000),(4,'Airbus A330',250000); | SELECT aircraft_model, AVG(flight_hours) FROM flight_hours GROUP BY aircraft_model; |
What is the maximum flight distance for each aircraft model? | CREATE TABLE flights (id INT,model VARCHAR(50),flight_distance DECIMAL(10,2),flight_hours DECIMAL(5,2)); INSERT INTO flights (id,model,flight_distance,flight_hours) VALUES (1,'Boeing 737',1500,4.5),(2,'Airbus A320',1200,3.8),(3,'Boeing 787',2000,5.5); | SELECT model, MAX(flight_distance) as max_flight_distance FROM flights GROUP BY model; |
Create a view that selects all records from the 'animals' table where the species is 'Mammal' | CREATE TABLE animals (id INT PRIMARY KEY,name VARCHAR(100),species VARCHAR(50),population INT); INSERT INTO animals (id,name,species,population) VALUES (1,'Giraffe','Mammal',30000),(2,'Elephant','Mammal',5000); | CREATE VIEW mammals_view AS SELECT * FROM animals WHERE species = 'Mammal'; |
What is the total number of animals in the 'animal_population' table, grouped by their species and sorted by the total count in descending order? | CREATE TABLE animal_population (id INT,species VARCHAR(255),population INT); INSERT INTO animal_population (id,species,population) VALUES (1,'Tiger',500),(2,'Elephant',2000),(3,'Lion',800); | SELECT species, SUM(population) as total FROM animal_population GROUP BY species ORDER BY total DESC; |
How many visitors attended the 'Music Festival' event in the 'Events' table? | CREATE TABLE Events (id INT,name VARCHAR(50),location VARCHAR(50),date DATE,attendance INT); INSERT INTO Events (id,name,location,date,attendance) VALUES (1,'Music Festival','New York','2022-01-01',2000); | SELECT SUM(attendance) FROM Events WHERE name = 'Music Festival'; |
Find the number of workers and projects for sustainable building permits | CREATE TABLE project (id INT PRIMARY KEY,name VARCHAR(50),location VARCHAR(50),start_date DATE); INSERT INTO project (id,name,location,start_date) VALUES (1,'GreenTowers','NYC','2020-01-01'); CREATE TABLE building_permit (id INT PRIMARY KEY,project_id INT,permit_type VARCHAR(50),permit_number INT); | SELECT COUNT(DISTINCT p.id) AS projects_count, SUM(l.workers_count) AS total_workers_count FROM project p INNER JOIN labor_statistics l ON p.id = l.project_id INNER JOIN building_permit bp ON p.id = bp.project_id WHERE bp.permit_type = 'Sustainable'; |
What is the total number of construction permits issued in each state? | CREATE TABLE PermitsByState (State VARCHAR(50),PermitCount INT); INSERT INTO PermitsByState (State,PermitCount) VALUES ('Texas',100); | SELECT State, SUM(PermitCount) AS TotalPermits FROM PermitsByState GROUP BY State; |
find the number of records in the CommunityHealthStatistics table where the State is 'TX' and the County is 'Harris' | CREATE TABLE CommunityHealthStatistics (ID INT,State TEXT,County TEXT,Population INT,AverageIncome FLOAT); INSERT INTO CommunityHealthStatistics (ID,State,County,Population,AverageIncome) VALUES (1,'TX','Harris',4500000,60000),(2,'CA','LA',2500000,70000); | SELECT * FROM CommunityHealthStatistics WHERE State = 'TX' AND County = 'Harris'; |
Identify the number of farmers involved in urban agriculture initiatives in California and New York in 2019. | CREATE TABLE Urban_Agriculture (Farmer_ID INT,State VARCHAR(20),Initiative VARCHAR(20),Year INT); INSERT INTO Urban_Agriculture (Farmer_ID,State,Initiative,Year) VALUES (101,'California','Community_Garden',2019),(102,'California','Rooftop_Farming',2019),(103,'New_York','Community_Garden',2019); | SELECT COUNT(DISTINCT Farmer_ID) FROM Urban_Agriculture WHERE State IN ('California', 'New York') AND Year = 2019 AND Initiative IN ('Community_Garden', 'Rooftop_Farming'); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.