instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What was the average sales revenue for 'DrugJ' in 2021? | CREATE TABLE drug_j_sales (quarter INTEGER,year INTEGER,revenue INTEGER); INSERT INTO drug_j_sales (quarter,year,revenue) VALUES (1,2021,550000),(2,2021,650000),(3,2021,750000),(4,2021,850000); | SELECT AVG(revenue) FROM drug_j_sales WHERE year = 2021 AND drug_name = 'DrugJ'; |
Update the budget of the AI for Climate Change initiative to $22,000 in Q3 2023. | CREATE TABLE ai_for_climate_change (id INT,initiative_name VARCHAR(255),funding_quarter VARCHAR(10),budget DECIMAL(10,2)); INSERT INTO ai_for_climate_change (id,initiative_name,funding_quarter,budget) VALUES (1,'AI for Climate Change','Q3 2023',20000); | UPDATE ai_for_climate_change SET budget = 22000 WHERE initiative_name = 'AI for Climate Change' AND funding_quarter = 'Q3 2023'; |
Count the number of bridges in the Bridge_Inspections table | CREATE TABLE Bridge_Inspections (inspection_id INT,bridge_name VARCHAR(50),bridge_type VARCHAR(50),inspection_date DATE); | SELECT COUNT(*) FROM Bridge_Inspections WHERE bridge_type = 'Bridge'; |
What is the average credit score of customers who have taken out loans with a maturity of 3 years or less, in Indonesia? | CREATE TABLE customers (customer_id INT,customer_name TEXT,credit_score INT,country TEXT); INSERT INTO customers (customer_id,customer_name,credit_score,country) VALUES (1,'Budi',700,'Indonesia'),(2,'Dewi',750,'Indonesia'); CREATE TABLE loans (loan_id INT,customer_id INT,maturity INT); INSERT INTO loans (loan_id,custom... | SELECT AVG(credit_score) FROM customers JOIN loans ON customers.customer_id = loans.customer_id WHERE country = 'Indonesia' AND maturity <= 3; |
Add a new regulatory record 'New Regulation C' for country 'ES' in Q1 of 2023 | CREATE TABLE countries (id INT,name VARCHAR(10)); INSERT INTO countries (id,name) VALUES (1,'FR'),(2,'DE'); CREATE TABLE regulations (id INT,country VARCHAR(10),quarter DATE,description VARCHAR(50)); | INSERT INTO countries (id, name) VALUES (3, 'ES'); INSERT INTO regulations (id, country, quarter, description) VALUES (4, 'ES', '2023-01-01', 'New Regulation C'); |
List all types of vehicles and their respective counts in 'Tokyo' | CREATE TABLE public.vehicles (id INT,type VARCHAR(20),city VARCHAR(20)); INSERT INTO public.vehicles (id,type,city) VALUES (1,'electric_car','Tokyo'),(2,'conventional_car','Tokyo'),(3,'autonomous_bus','Tokyo'); | SELECT type, COUNT(*) FROM public.vehicles WHERE city = 'Tokyo' GROUP BY type; |
List all support programs and the number of participants for each program. | CREATE TABLE support_programs (id INT,program_name VARCHAR(50),description TEXT); INSERT INTO support_programs (id,program_name,description) VALUES (1,'Mentorship Program','A program that pairs students with mentors'),(2,'Tutoring Program','A program that provides tutoring for students with disabilities'); CREATE TABLE... | SELECT support_programs.program_name, COUNT(participants.id) AS number_of_participants FROM support_programs INNER JOIN participants ON support_programs.id = participants.program_id GROUP BY support_programs.id; |
What is the average number of employees in unionized workplaces in the United States? | CREATE TABLE workplaces (id INT,country VARCHAR(50),num_employees INT,is_unionized BOOLEAN); INSERT INTO workplaces (id,country,num_employees,is_unionized) VALUES (1,'United States',100,true),(2,'United States',200,false),(3,'United States',150,true); | SELECT AVG(num_employees) FROM workplaces WHERE country = 'United States' AND is_unionized = true; |
What is the maximum drought severity in each state over the past 5 years? | CREATE TABLE droughts (state VARCHAR(50),year INT,severity INT); INSERT INTO droughts (state,year,severity) VALUES ('California',2017,8),('California',2018,7),('California',2019,6),('California',2020,9),('California',2021,5),('Texas',2017,5),('Texas',2018,6),('Texas',2019,7),('Texas',2020,8),('Texas',2021,4),('Nevada',... | SELECT state, MAX(severity) as max_severity FROM droughts WHERE year BETWEEN 2017 AND 2021 GROUP BY state; |
List all OTA (Online Travel Agency) bookings made for 'Paris' hotels with a 'family' room type in the last month. | CREATE TABLE otabookings (id INT,hotel_id INT,room_type VARCHAR(255),customer_name VARCHAR(255),booking_date DATE); INSERT INTO otabookings (id,hotel_id,room_type,customer_name,booking_date) VALUES (1,3,'family','John Doe','2022-03-15'); INSERT INTO otabookings (id,hotel_id,room_type,customer_name,booking_date) VALUES ... | SELECT * FROM otabookings WHERE room_type = 'family' AND city = 'Paris' AND booking_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH); |
Identify the least profitable non-vegan menu items to potentially replace? | CREATE TABLE menu_items (item VARCHAR(50),type VARCHAR(15),sales INT,cost DECIMAL(10,2)); INSERT INTO menu_items (item,type,sales,cost) VALUES ('Steak','Non-Vegan',50,20.00),('Chicken Alfredo','Non-Vegan',75,18.00); CREATE VIEW profit AS SELECT item,sales - cost as profit FROM menu_items; | SELECT item FROM profit WHERE type = 'Non-Vegan' ORDER BY profit LIMIT 3; |
Determine the total amount of resources depleted by each mine | CREATE TABLE mine (id INT,name TEXT,location TEXT); CREATE TABLE depletion (mine_id INT,date DATE,resource TEXT,quantity INT); INSERT INTO mine VALUES (1,'Mine A','Country A'); INSERT INTO mine VALUES (2,'Mine B','Country B'); INSERT INTO depletion VALUES (1,'2021-01-01','Gold',100); INSERT INTO depletion VALUES (1,'20... | SELECT mine.name, SUM(depletion.quantity) AS total_depleted FROM mine INNER JOIN depletion ON mine.id = depletion.mine_id GROUP BY mine.name; |
What is the most common disease among male patients in rural Montana? | CREATE TABLE patients (id INT,name VARCHAR(50),gender VARCHAR(10),state VARCHAR(50)); CREATE TABLE diagnoses (id INT,patient_id INT,diagnosis VARCHAR(50)); INSERT INTO patients (id,name,gender,state) VALUES (1,'John Doe','Male','Montana'); INSERT INTO diagnoses (id,patient_id,diagnosis) VALUES (1,1,'Cancer'); INSERT IN... | SELECT diagnoses.diagnosis, COUNT(*) FROM diagnoses JOIN patients ON diagnoses.patient_id = patients.id WHERE patients.gender = 'Male' AND patients.state = 'Montana' GROUP BY diagnoses.diagnosis ORDER BY COUNT(*) DESC LIMIT 1; |
Which countries have the most solar power projects? | CREATE TABLE project_solar (project_name TEXT,country TEXT); INSERT INTO project_solar (project_name,country) VALUES ('Project A','Country A'),('Project B','Country A'),('Project C','Country B'),('Project D','Country C'),('Project E','Country D'),('Project F','Country D'),('Project G','Country A'); | SELECT country, COUNT(*) FROM project_solar GROUP BY country ORDER BY COUNT(*) DESC; |
What is the maximum data usage by a single subscriber? | CREATE TABLE subscribers (id INT,name TEXT,data_usage FLOAT); INSERT INTO subscribers (id,name,data_usage) VALUES (1,'John Doe',15.0); INSERT INTO subscribers (id,name,data_usage) VALUES (2,'Jane Smith',20.0); INSERT INTO subscribers (id,name,data_usage) VALUES (3,'Bob Johnson',25.0); | SELECT MAX(data_usage) FROM subscribers; |
Update the name of defense project 'Project Y' to 'Project Z' and its budget to 1,500,000,000. | CREATE TABLE DefenseProjects (project_name VARCHAR(255),start_date DATE,end_date DATE,budget FLOAT); INSERT INTO DefenseProjects (project_name,start_date,end_date,budget) VALUES ('Project Y','2021-01-01','2023-12-31',1000000000); | UPDATE DefenseProjects SET project_name = 'Project Z', budget = 1500000000 WHERE project_name = 'Project Y'; |
How many countries are represented in the 'museums' table? | CREATE TABLE continent (id INT,name VARCHAR(50)); INSERT INTO continent (id,name) VALUES (1,'Europe'),(2,'Americas'),(3,'Asia'),(4,'Africa'),(5,'Oceania'); CREATE TABLE country (id INT,name VARCHAR(50),continent_id INT); INSERT INTO country (id,name,continent_id) VALUES (1,'France',1),(2,'USA',2),(3,'China',3); CREATE ... | SELECT COUNT(DISTINCT c.country_id) FROM museums m JOIN country c ON m.country_id = c.id; |
What are the digital art marketplaces with their corresponding blockchain companies, ranked by marketplace ID in descending order, for the Ethereum platform? | CREATE TABLE digital_art_marketplaces (marketplace_id INT,marketplace_name VARCHAR(50),company_id INT); INSERT INTO digital_art_marketplaces (marketplace_id,marketplace_name,company_id) VALUES (1,'OpenSea',1); INSERT INTO digital_art_marketplaces (marketplace_id,marketplace_name,company_id) VALUES (2,'Rarible',2); INSE... | SELECT dam.marketplace_name, bc.company_name, dam.marketplace_id, ROW_NUMBER() OVER (PARTITION BY bc.platform ORDER BY dam.marketplace_id DESC) as rank FROM digital_art_marketplaces dam JOIN blockchain_companies bc ON dam.company_id = bc.company_id WHERE bc.platform = 'Ethereum'; |
How many electric vehicles were sold in Germany in 2019? | CREATE TABLE VehicleSales (vehicle_id INT,model VARCHAR(100),type VARCHAR(50),country VARCHAR(50),year INT); INSERT INTO VehicleSales (vehicle_id,model,type,country,year) VALUES (1,'Model 3','Electric','Germany',2019),(2,'Golf','Gasoline','Germany',2019); | SELECT COUNT(*) FROM VehicleSales WHERE type = 'Electric' AND country = 'Germany' AND year = 2019; |
What is the percentage of Neodymium exported from Brazil to other countries annually? | CREATE TABLE NeodymiumExport(year INT,country VARCHAR(50),percentage DECIMAL(5,2)); INSERT INTO NeodymiumExport(year,country,percentage) VALUES (2017,'Brazil',18.5),(2017,'USA',12.0),(2017,'China',45.0),(2018,'Brazil',20.0),(2018,'USA',13.0),(2018,'China',44.0); | SELECT (SUM(percentage) FILTER (WHERE country = 'Brazil'))/SUM(percentage) FROM NeodymiumExport; |
What is the contact information of the staff member responsible for mental health services? | CREATE TABLE staff (id INT PRIMARY KEY,name VARCHAR(255),role VARCHAR(255),email TEXT,phone TEXT); INSERT INTO staff (id,name,role,email,phone) VALUES (1,'Alex Duong','Mental Health Coordinator','alex.duong@disabilityservices.org','555-555-1234'); | SELECT * FROM staff WHERE role = 'Mental Health Coordinator'; |
List the top 3 makes with the highest average range for electric vehicles | CREATE TABLE electric_vehicles (id INT,make VARCHAR(50),range INT); INSERT INTO electric_vehicles (id,make,range) VALUES (1,'Tesla',350),(2,'Tesla',400),(3,'Nissan',250),(4,'Nissan',280),(5,'Ford',310),(6,'Ford',NULL),(7,'Chevy',240),(8,'Lucid',517),(9,'Rivian',314); | SELECT make, AVG(range) as avg_range FROM electric_vehicles WHERE range IS NOT NULL GROUP BY make ORDER BY avg_range DESC LIMIT 3; |
How many artifacts were found in the last 3 months, categorized by excavation site and artifact type? | CREATE TABLE Dates (DateID INT,ExcavationDate DATE); INSERT INTO Dates (DateID,ExcavationDate) VALUES (1,'2021-05-15'),(2,'2021-06-16'),(3,'2021-07-20'); CREATE TABLE ArtifactsDates (ArtifactID INT,DateID INT); INSERT INTO ArtifactsDates (ArtifactID,DateID) VALUES (1,1),(2,2),(3,1),(4,2),(5,3); | SELECT Dates.ExcavationDate, Sites.SiteName, Artifacts.ArtifactName, COUNT(ArtifactsDates.ArtifactID) AS Quantity FROM Dates INNER JOIN ArtifactsDates ON Dates.DateID = ArtifactsDates.DateID INNER JOIN Artifacts ON ArtifactsDates.ArtifactID = Artifacts.ArtifactID INNER JOIN Sites ON Artifacts.SiteID = Sites.SiteID WHER... |
Who are the top 3 salespeople by total revenue? | CREATE TABLE sales_data (salesperson_id INT,salesperson_name VARCHAR(255),revenue INT); INSERT INTO sales_data (salesperson_id,salesperson_name,revenue) VALUES (1,'John Doe',500000),(2,'Jane Smith',600000),(3,'Bob Johnson',400000),(4,'Alice Williams',700000),(5,'Charlie Brown',800000); | SELECT salesperson_name, SUM(revenue) AS total_revenue FROM sales_data GROUP BY salesperson_name ORDER BY total_revenue DESC LIMIT 3; |
How many broadband subscribers use 'WiMax' technology, grouped by subscription start date? | CREATE TABLE subscriber_tech (subscriber_id INT,subscription_start_date DATE,technology VARCHAR(50),subscription_fee DECIMAL(10,2)); INSERT INTO subscriber_tech (subscriber_id,subscription_start_date,technology,subscription_fee) VALUES (1,'2020-01-01','Fiber',50.00),(2,'2019-06-15','Cable',40.00),(4,'2021-02-20','WiMax... | SELECT subscription_start_date, COUNT(*) as total_subscribers FROM subscriber_tech WHERE technology = 'WiMax' GROUP BY subscription_start_date; |
What is the number of rural hospitals and clinics in each region, and the number of clinics within a 30-km radius of each hospital? | CREATE TABLE hospitals (id INT,name TEXT,location TEXT,num_beds INT,region TEXT); INSERT INTO hospitals (id,name,location,num_beds,region) VALUES (1,'Hospital A','Rural Andalusia',200,'Andalusia'),(2,'Hospital B','Rural Madrid',250,'Madrid'); CREATE TABLE clinics (id INT,name TEXT,location TEXT,num_beds INT,region TEXT... | SELECT h.region, COUNT(h.id) AS num_hospitals, COUNT(c.id) AS num_clinics_within_30_km FROM hospitals h INNER JOIN distance d ON h.id = d.hospital_id INNER JOIN clinics c ON d.clinic_id = c.id WHERE d.distance <= 30 GROUP BY h.region; |
How many 4-star hotels are there in Germany? | CREATE TABLE hotels (id INT,name TEXT,country TEXT,rating INT); INSERT INTO hotels (id,name,country,rating) VALUES (1,'Hotel Adlon Kempinski Berlin','Germany',4),(2,'Hotel Vier Jahreszeiten Kempinski Munich','Germany',4),(3,'The Ritz-Carlton,Berlin','Germany',5); | SELECT COUNT(*) FROM hotels WHERE country = 'Germany' AND rating = 4; |
Insert a new garment with id 3, name 'Jacket', category 'Men', rating 5 and quantity 25 into the database. | CREATE TABLE garments (id INT PRIMARY KEY,name VARCHAR(255),category VARCHAR(255),rating INT); CREATE TABLE inventories (id INT PRIMARY KEY,garment_id INT,quantity INT); | INSERT INTO garments (id, name, category, rating) VALUES (3, 'Jacket', 'Men', 5); INSERT INTO inventories (id, garment_id, quantity) VALUES (3, 3, 25); |
What is the total number of packages shipped to each country in the shipping database? | CREATE TABLE shipping (country VARCHAR(20),packages INT); INSERT INTO shipping (country,packages) VALUES ('Country1',100),('Country2',200),('Country3',150); | SELECT country, SUM(packages) FROM shipping GROUP BY country; |
Which lifelong learning courses had the lowest enrollment in the past two years? | CREATE TABLE courses (course_id INT,course_name TEXT,year INT); INSERT INTO courses (course_id,course_name,year) VALUES (1,'Course X',2021),(2,'Course Y',2021),(3,'Course Z',2022),(4,'Course W',2022); CREATE TABLE enrollments (enrollment_id INT,course_id INT,student_id INT); INSERT INTO enrollments (enrollment_id,cours... | SELECT c.course_name, MIN(c.year) as min_year, COUNT(e.student_id) as enrollment_count FROM courses c JOIN enrollments e ON c.course_id = e.course_id GROUP BY c.course_name HAVING MIN(c.year) >= 2021 ORDER BY enrollment_count ASC LIMIT 1; |
What is the average mental health support session duration for students of different age groups? | CREATE TABLE students (student_id INT,student_name TEXT,student_age INT); CREATE TABLE sessions (session_id INT,student_id INT,session_date DATE,support_type TEXT,hours_spent INT); INSERT INTO students VALUES (1,'Alex',15),(2,'Bella',17),(3,'Charlie',20),(4,'Daniel',22); INSERT INTO sessions VALUES (1,1,'2022-01-01','m... | SELECT FLOOR(s.student_age / 5) * 5 AS age_group, AVG(s.hours_spent) FROM students st INNER JOIN sessions s ON st.student_id = s.student_id WHERE s.support_type = 'mental health' GROUP BY age_group; |
What is the average cost of materials for bridges constructed in California? | CREATE TABLE Bridges (BridgeID INT,Location VARCHAR(20),Cost FLOAT); INSERT INTO Bridges (BridgeID,Location,Cost) VALUES (1,'California',5000000); | SELECT AVG(Cost) FROM Bridges WHERE Location = 'California' AND BridgeID IN (SELECT BridgeID FROM Bridges WHERE Location = 'California'); |
What is the total number of yellow cards given to players from Germany? | CREATE TABLE card_stats (id INT,player TEXT,yellow_cards INT,country TEXT); INSERT INTO card_stats (id,player,yellow_cards,country) VALUES (1,'Klose',5,'Germany'),(2,'Schweinsteiger',4,'Germany'),(3,'Lahm',3,'Germany'); | SELECT SUM(yellow_cards) FROM card_stats WHERE country = 'Germany'; |
What is the total number of vulnerabilities found for each threat actor? | CREATE TABLE vulnerabilities_by_actor (id INT,actor VARCHAR(50),vuln_count INT); INSERT INTO vulnerabilities_by_actor (id,actor,vuln_count) VALUES (1,'APT28',200),(2,'APT33',150),(3,'Lazarus',100); | SELECT actor, SUM(vuln_count) as total_vulnerabilities FROM vulnerabilities_by_actor GROUP BY actor; |
What is the average rating of cultural heritage sites in Madrid? | CREATE TABLE heritage_sites (site_id INT,site_name TEXT,city TEXT,rating INT); INSERT INTO heritage_sites (site_id,site_name,city,rating) VALUES (1,'Prado Museum','Madrid',5),(2,'Royal Palace','Madrid',4),(3,'Retiro Park','Madrid',4); | SELECT AVG(rating) FROM heritage_sites WHERE city = 'Madrid'; |
What is the average number of peacekeeping personnel contributed by each country in the 'asia' region? | CREATE TABLE peacekeeping_contributions (country VARCHAR(50),region VARCHAR(50),personnel INT); INSERT INTO peacekeeping_contributions (country,region,personnel) VALUES ('Afghanistan','Asia',300),('Bangladesh','Asia',1200),('China','Asia',500); | SELECT region, AVG(personnel) as avg_personnel FROM peacekeeping_contributions WHERE region = 'Asia' GROUP BY region; |
Update the 'Heart Disease' prevalence rate for 'Rural County A' in the "disease_prevalence" table to 12% | CREATE TABLE disease_prevalence (county VARCHAR(50),diagnosis VARCHAR(50),prevalence DECIMAL(5,2)); INSERT INTO disease_prevalence (county,diagnosis,prevalence) VALUES ('Rural County A','Heart Disease',10.00); | UPDATE disease_prevalence SET prevalence = 0.12 WHERE county = 'Rural County A' AND diagnosis = 'Heart Disease'; |
What was the total quantity of items shipped to a specific region (e.g. Asia)? | CREATE TABLE warehouse (warehouse_id VARCHAR(10),warehouse_location VARCHAR(20)); INSERT INTO warehouse (warehouse_id,warehouse_location) VALUES ('A','New York'),('B','Tokyo'),('C','London'); CREATE TABLE shipments (shipment_id INT,warehouse_id VARCHAR(10),quantity INT); INSERT INTO shipments (shipment_id,warehouse_id,... | SELECT SUM(quantity) FROM shipments JOIN warehouse ON shipments.warehouse_id = warehouse.warehouse_id WHERE warehouse.warehouse_location LIKE 'Asia%'; |
How many unique genres are there in the global_songs table? | CREATE TABLE global_songs (id INT,title TEXT,length FLOAT,genre TEXT); INSERT INTO global_songs (id,title,length,genre) VALUES (1,'Cancion1',3.2,'pop latino'),(2,'Cancion2',4.1,'reggaeton'),(3,'Cancion3',3.8,'salsa'),(4,'Cancion4',2.1,'flamenco'),(5,'Cancion5',5.3,'k-pop'),(6,'Cancion6',6.2,'bhangra'); | SELECT COUNT(DISTINCT genre) FROM global_songs; |
Which countries had the highest and lowest donation amounts? | CREATE TABLE Donors (DonorID INT,DonorCountry VARCHAR(50),Amount DECIMAL(10,2)); INSERT INTO Donors (DonorID,DonorCountry,Amount) VALUES (1,'USA',1000),(2,'Canada',800),(3,'Mexico',600); | SELECT DonorCountry, MAX(Amount) as HighestDonation, MIN(Amount) as LowestDonation FROM Donors GROUP BY DonorCountry HAVING COUNT(DonorID) > 1; |
What percentage of 'Theater for All' program attendees identify as BIPOC? | CREATE TABLE ProgramAttendance (program_name VARCHAR(50),attendee_race VARCHAR(20)); INSERT INTO ProgramAttendance (program_name,attendee_race) VALUES ('Theater for All','African American'); INSERT INTO ProgramAttendance (program_name,attendee_race) VALUES ('Theater for All','Hispanic'); INSERT INTO ProgramAttendance (... | SELECT (COUNT(*) FILTER (WHERE attendee_race IN ('African American', 'Hispanic', 'Asian', 'Native American')) * 100.0 / COUNT(*)) AS percentage FROM ProgramAttendance WHERE program_name = 'Theater for All'; |
What is the total number of voyages for vessels that have had zero accidents? | CREATE TABLE Voyages (Id INT,VesselId INT,Year INT); INSERT INTO Voyages (Id,VesselId,Year) VALUES (1,1,2021),(2,1,2022),(3,3,2021),(4,2,2020); | SELECT COUNT(*) FROM (SELECT VesselId FROM Voyages GROUP BY VesselId HAVING COUNT(*) = (SELECT COUNT(*) FROM Accidents WHERE Accidents.VesselId = Voyages.VesselId)) AS NoAccidentsVoyages; |
What is the total revenue for each salesperson in Q1 2022? | CREATE TABLE sales (sale_date DATE,salesperson VARCHAR(255),revenue FLOAT); | SELECT salesperson, SUM(revenue) AS total_revenue FROM sales WHERE sale_date BETWEEN '2022-01-01' AND '2022-03-31' GROUP BY salesperson; |
What's the number of volunteers who joined each month? | CREATE TABLE VolunteerDates (Id INT,VolunteerId INT,JoinDate DATE); INSERT INTO VolunteerDates VALUES (1,1,'2022-01-01'),(2,2,'2022-03-01'); | SELECT EXTRACT(MONTH FROM JoinDate) as Month, COUNT(DISTINCT VolunteerId) as VolunteersJoined FROM VolunteerDates GROUP BY Month; |
Determine the total number of unique cities where volunteers reside | CREATE TABLE volunteers (id INT,city VARCHAR,joined DATE); INSERT INTO volunteers VALUES (1,'San Francisco','2020-01-01') | SELECT COUNT(DISTINCT v.city) AS unique_cities FROM volunteers v; |
What is the minimum ticket price for an art exhibit in London? | CREATE TABLE Exhibits (exhibit_id INT,city VARCHAR(50),price DECIMAL(5,2)); INSERT INTO Exhibits (exhibit_id,city,price) VALUES (1,'London',35.99),(2,'Berlin',40.00); | SELECT MIN(price) FROM Exhibits WHERE city = 'London'; |
What is the average monthly water usage per worker at the 'South' region mines in 2022? | CREATE TABLE water_usage (site_id INT,site_name TEXT,region TEXT,month INT,year INT,worker_id INT,water_usage INT); INSERT INTO water_usage (site_id,site_name,region,month,year,worker_id,water_usage) VALUES (12,'DEF Mine','South',1,2022,12001,200),(13,'GHI Mine','South',2,2022,13001,220),(14,'JKL Mine','South',3,2022,1... | SELECT region, AVG(water_usage) as avg_water_usage_per_worker FROM water_usage WHERE region = 'South' AND year = 2022 GROUP BY region, year; |
Delete the wellness trend record for 'Pilates' | CREATE TABLE wellness_trend (trend_name VARCHAR(50),popularity_score INT); INSERT INTO wellness_trend (trend_name,popularity_score) VALUES ('Pilates',70); | WITH deleted_trend AS (DELETE FROM wellness_trend WHERE trend_name = 'Pilates' RETURNING *) SELECT * FROM deleted_trend; |
List the 'investor' and 'esg_score' for all 'CleanEnergy' investments. | CREATE TABLE InvestorsESG (id INT,investor VARCHAR(255),esg_score DECIMAL(3,2)); CREATE TABLE InvestmentsCE (id INT,investor VARCHAR(255),sector VARCHAR(255)); | SELECT InvestorsESG.investor, InvestorsESG.esg_score FROM InvestorsESG INNER JOIN InvestmentsCE ON InvestorsESG.id = InvestmentsCE.id WHERE InvestmentsCE.sector = 'CleanEnergy'; |
How many volunteers have donated more than $50 in Australia? | CREATE TABLE Donations (id INT,donor_name VARCHAR(50),donation_amount DECIMAL(10,2),donation_date DATE,country VARCHAR(50)); CREATE TABLE Volunteers (id INT,volunteer_name VARCHAR(50),country VARCHAR(50)); INSERT INTO Donations (id,donor_name,donation_amount,donation_date,country) VALUES (1,'John Doe',50.00,'2021-01-01... | SELECT COUNT(DISTINCT d.donor_name) as num_volunteers FROM Donations d INNER JOIN Volunteers v ON d.donor_name = v.volunteer_name WHERE d.country = 'Australia' AND d.donation_amount > 50; |
Identify the total number of refugee families and children by joining the refugee_families and refugee_children tables. | CREATE TABLE refugee_families (id INT,location_id INT,family_size INT); CREATE TABLE refugee_children (id INT,family_id INT,age INT); | SELECT COUNT(DISTINCT rf.id) as total_families, SUM(rc.age) as total_children_age FROM refugee_families rf INNER JOIN refugee_children rc ON rf.id = rc.family_id; |
Identify the textile supplier with the highest total quantity of sustainable fabric orders, for the past 12 months. | CREATE TABLE Suppliers (SupplierID INT,SupplierName VARCHAR(50),Sustainable BOOLEAN); INSERT INTO Suppliers (SupplierID,SupplierName,Sustainable) VALUES (1,'Green Textiles',true),(2,'Fashion Fabrics',false),(3,'Eco-Friendly Materials',true); CREATE TABLE PurchaseOrders (PurchaseOrderID INT,SupplierID INT,Quantity INT,O... | SELECT s.SupplierName, SUM(po.Quantity) as TotalQuantity FROM Suppliers s INNER JOIN PurchaseOrders po ON s.SupplierID = po.SupplierID WHERE s.Sustainable = true AND po.OrderDate >= DATEADD(YEAR, -1, GETDATE()) GROUP BY s.SupplierName ORDER BY TotalQuantity DESC; |
Present the number of fish that weigh more than 200kg in the 'LargeFish' table | CREATE TABLE LargeFish (id INT,species VARCHAR(255),weight FLOAT); INSERT INTO LargeFish (id,species,weight) VALUES (1,'Shark',350.5); INSERT INTO LargeFish (id,species,weight) VALUES (2,'Marlin',200.3); INSERT INTO LargeFish (id,species,weight) VALUES (3,'Swordfish',250.8); | SELECT COUNT(*) FROM LargeFish WHERE weight > 200; |
What is the average health equity metric score by state? | CREATE TABLE health_equity_metrics (state VARCHAR(255),score DECIMAL(5,2)); INSERT INTO health_equity_metrics (state,score) VALUES ('California',85.5),('New York',90.0),('Texas',76.0),('Florida',82.0); | SELECT state, AVG(score) FROM health_equity_metrics GROUP BY state; |
What is the total energy consumption in TWh for each sector (residential, commercial, industrial)? | CREATE TABLE EnergyConsumption (sector VARCHAR(50),consumption FLOAT); | SELECT sector, SUM(consumption) FROM EnergyConsumption GROUP BY sector; |
List all smart city technology adoptions and their corresponding costs from the 'smart_city_technology' table. | CREATE TABLE smart_city_technology (technology_name TEXT,cost REAL); | SELECT technology_name, cost FROM smart_city_technology; |
What is the average salary of workers in the 'Agriculture' industry who are not part of a union? | CREATE TABLE workers (id INT,industry VARCHAR(255),salary FLOAT,union_member BOOLEAN); INSERT INTO workers (id,industry,salary,union_member) VALUES (1,'Manufacturing',50000.0,true),(2,'Agriculture',60000.0,false),(3,'Retail',30000.0,false); | SELECT AVG(salary) FROM workers WHERE industry = 'Agriculture' AND union_member = false; |
Insert a new member from London with a membership fee of 60 starting on June 1st, 2022. | CREATE TABLE memberships (id INT,member_state VARCHAR(50),membership_start_date DATE,membership_fee FLOAT); | INSERT INTO memberships (id, member_state, membership_start_date, membership_fee) VALUES (1, 'London', '2022-06-01', 60.0); |
Insert sample data into 'risk_models' table | CREATE TABLE risk_models (model_id INT PRIMARY KEY,model_name VARCHAR(100),model_description TEXT,model_date DATE); | INSERT INTO risk_models (model_id, model_name, model_description, model_date) VALUES (1, 'Model A', 'Description for Model A', '2022-01-01'), (2, 'Model B', 'Description for Model B', '2022-02-15'), (3, 'Model C', 'Description for Model C', '2022-03-05'); |
What is the minimum donation amount made by new donors from the Asia-Pacific region in Q1 2022? | CREATE TABLE Donations (DonationID INT,DonorID INT,DonationDate DATE,DonationAmount DECIMAL); INSERT INTO Donations (DonationID,DonorID,DonationDate,DonationAmount) VALUES (1,3,'2022-03-15',50.00),(2,4,'2022-01-01',75.00); | SELECT MIN(DonationAmount) FROM Donations JOIN Donors ON Donations.DonorID = Donors.DonorID WHERE Donors.Region = 'Asia-Pacific' AND Donations.DonationDate BETWEEN '2022-01-01' AND '2022-03-31'; |
Display the names of artists who have updated their information more than once and the respective update dates. | CREATE TABLE Artist_Updates (update_id INT,artist_name VARCHAR(255),update_date DATE); INSERT INTO Artist_Updates (update_id,artist_name,update_date) VALUES (1,'Artist A','2019-01-01'),(2,'Artist B','2019-02-01'),(3,'Artist A','2019-03-01'),(4,'Artist C','2019-04-01'),(5,'Artist A','2019-05-01'); | SELECT artist_name, COUNT(update_id) AS num_updates, MIN(update_date) AS earliest_update_date FROM Artist_Updates GROUP BY artist_name HAVING COUNT(update_id) > 1 ORDER BY earliest_update_date; |
What percentage of employees are female and work in IT? | CREATE TABLE employees (id INT,gender VARCHAR(10),department VARCHAR(20)); INSERT INTO employees (id,gender,department) VALUES (1,'Female','IT'),(2,'Male','Marketing'),(3,'Female','IT'); | SELECT (COUNT(*) FILTER (WHERE gender = 'Female' AND department = 'IT')) * 100.0 / (SELECT COUNT(*) FROM employees) AS percentage; |
What is the total revenue for each artist, based on the 'digital_sales' table, joined with the 'artist' and 'song' tables? | CREATE TABLE artist (artist_id INT,artist_name VARCHAR(255)); CREATE TABLE song (song_id INT,song_name VARCHAR(255),artist_id INT); CREATE TABLE digital_sales (sale_id INT,song_id INT,sales_revenue DECIMAL(10,2)); | SELECT a.artist_name, SUM(ds.sales_revenue) AS total_revenue FROM artist a INNER JOIN song s ON a.artist_id = s.artist_id INNER JOIN digital_sales ds ON s.song_id = ds.song_id GROUP BY a.artist_name; |
Which vehicle safety tests were passed by Toyota? | CREATE TABLE VehicleTesting (Id INT,Make VARCHAR(255),Model VARCHAR(255),Test VARCHAR(255),Result VARCHAR(255)); INSERT INTO VehicleTesting (Id,Make,Model,Test,Result) VALUES (3,'Toyota','Corolla','AutoPilot','Pass'); | SELECT DISTINCT Test FROM VehicleTesting WHERE Make = 'Toyota' AND Result = 'Pass'; |
What is the average endangerment status of marine species in the Southern ocean? | CREATE TABLE marine_species_status (species_name VARCHAR(255),region VARCHAR(255),endangerment_status VARCHAR(255)); INSERT INTO marine_species_status (species_name,region,endangerment_status) VALUES ('Krill','Southern Ocean','Least Concern'),('Blue Whale','Southern Ocean','Endangered'); | SELECT AVG(CASE WHEN endangerment_status = 'Least Concern' THEN 1 WHEN endangerment_status = 'Near Threatened' THEN 2 WHEN endangerment_status = 'Vulnerable' THEN 3 WHEN endangerment_status = 'Endangered' THEN 4 ELSE 5 END) FROM marine_species_status WHERE region = 'Southern Ocean'; |
Which textile supplier has provided the most sustainable fabric to the fashion industry? | CREATE TABLE SupplierInfo (SupplierID INT,SupplierName VARCHAR(255),SustainableFabricQuantity INT); INSERT INTO SupplierInfo (SupplierID,SupplierName,SustainableFabricQuantity) VALUES (1,'SupplierA',30000),(2,'SupplierB',25000),(3,'SupplierC',35000); | SELECT SupplierName, MAX(SustainableFabricQuantity) FROM SupplierInfo; |
What is the total number of military innovation projects completed by 'usa' in the 'americas' region? | CREATE TABLE military_innovation (country VARCHAR(50),region VARCHAR(50),year INT,projects INT); INSERT INTO military_innovation (country,region,year,projects) VALUES ('USA','Americas',2020,150),('USA','Americas',2021,180); | SELECT country, region, SUM(projects) as total_projects FROM military_innovation WHERE country = 'USA' AND region = 'Americas' GROUP BY country, region; |
Update the "programs" table to reflect a change in the focus of a program in India | CREATE TABLE programs (id INT PRIMARY KEY,name VARCHAR(100),focus VARCHAR(100),country VARCHAR(50)); | UPDATE programs SET focus = 'Indian Classical Dance' WHERE country = 'India'; |
What is the total number of humanitarian assistance missions conducted by each military branch in 2020? | CREATE TABLE military_branch (id INT PRIMARY KEY,name VARCHAR(255)); INSERT INTO military_branch (id,name) VALUES (1,'Army'),(2,'Navy'),(3,'Air Force'),(4,'Marines'),(5,'Coast Guard'); CREATE TABLE missions (id INT PRIMARY KEY,military_branch_id INT,type VARCHAR(255),year INT,FOREIGN KEY (military_branch_id) REFERENCES... | SELECT m.name, COUNT(missions.id) as total_missions FROM missions JOIN military_branch m ON missions.military_branch_id = m.id WHERE missions.type = 'Humanitarian Assistance' AND missions.year = 2020 GROUP BY m.name; |
List the players and the number of games they have won in the "nba_games" table | CREATE TABLE nba_games (player VARCHAR(255),games_played INTEGER,games_won INTEGER); | SELECT player, SUM(games_won) as total_wins FROM nba_games GROUP BY player; |
What is the number of cases and win rate for attorneys in the Midwest? | CREATE TABLE Wins (CaseID INT,AttorneyID INT,Region VARCHAR(50),CaseOutcome VARCHAR(50)); INSERT INTO Wins (CaseID,AttorneyID,Region,CaseOutcome) VALUES (1,1,'Northeast','Won'),(2,1,'Northeast','Lost'),(3,2,'Northeast','Won'),(4,2,'Northeast','Won'),(5,3,'Midwest','Won'),(6,3,'Midwest','Lost'),(7,4,'Southwest','Won'),(... | SELECT a.AttorneyName, a.Region, COUNT(w.CaseID) AS TotalCases, COUNT(w.CaseID) * 100.0 / SUM(COUNT(w.CaseID)) OVER (PARTITION BY a.Region) AS WinRate FROM Attorneys a JOIN Wins w ON a.AttorneyID = w.AttorneyID WHERE a.Region = 'Midwest' GROUP BY a.AttorneyName, a.Region; |
Rank mental health facilities by the number of linguistically diverse staff members? | CREATE TABLE mental_health_facilities (id INT,name VARCHAR(50),linguistically_diverse_staff INT); INSERT INTO mental_health_facilities (id,name,linguistically_diverse_staff) VALUES (1,'Facility X',10),(2,'Facility Y',5),(3,'Facility Z',15); | SELECT name, RANK() OVER (ORDER BY linguistically_diverse_staff DESC) as ranking FROM mental_health_facilities; |
What is the average cultural competency score for each state? | CREATE TABLE state_cultural_competency (state VARCHAR(20),score INT); INSERT INTO state_cultural_competency (state,score) VALUES ('California',85),('Texas',90),('New York',88); CREATE TABLE state_population (state VARCHAR(20),population INT); INSERT INTO state_population (state,population) VALUES ('California',40000000... | SELECT scc.state, AVG(scc.score) FROM state_cultural_competency scc INNER JOIN state_population sp ON scc.state = sp.state GROUP BY scc.state; |
What is the total labor cost for construction projects in Texas in the past month? | CREATE TABLE LaborCosts (CostID int,ProjectID int,LaborCost money,Date date); CREATE TABLE Projects (ProjectID int,ProjectName varchar(255),State varchar(255),StartDate date,EndDate date,IsSustainable bit); | SELECT SUM(LaborCost) as TotalLaborCosts FROM LaborCosts JOIN Projects ON LaborCosts.ProjectID = Projects.ProjectID WHERE State = 'Texas' AND Date >= DATEADD(month, -1, GETDATE()); |
What is the average number of fans attending games in Asia? | CREATE TABLE games (id INT,team TEXT,location TEXT,attendees INT,year INT); INSERT INTO games (id,team,location,attendees,year) VALUES (1,'Dragons','Hong Kong',12000,2022); INSERT INTO games (id,team,location,attendees,year) VALUES (2,'Tigers','Tokyo',15000,2022); | SELECT location, AVG(attendees) FROM games WHERE location LIKE '%Asia%' GROUP BY location; |
What is the minimum labor cost for sustainable building projects in 2021? | CREATE TABLE labor_costs (project_id INT,sector VARCHAR(50),labor_cost FLOAT,year INT); INSERT INTO labor_costs (project_id,sector,labor_cost,year) VALUES (1,'Sustainable',30000,2021),(2,'Sustainable',28000,2021),(3,'Sustainable',35000,2021); | SELECT MIN(labor_cost) FROM labor_costs WHERE sector = 'Sustainable' AND year = 2021; |
Show the total number of educational programs in 'community_education' table | CREATE TABLE community_education (id INT,program VARCHAR(50),location VARCHAR(50),date DATE); | SELECT COUNT(*) FROM community_education; |
What is the average severity of cybersecurity incidents related to 'Ransomware' that occurred on '2022-05-01'? | CREATE TABLE CyberSecurity (id INT,incident VARCHAR(255),date DATE,severity INT); INSERT INTO CyberSecurity (id,incident,date,severity) VALUES (1,'Ransomware','2022-05-01',8); | SELECT AVG(severity) as avg_severity FROM CyberSecurity WHERE incident = 'Ransomware' AND date = '2022-05-01'; |
What is the total number of accommodations provided in South Africa by accommodation type? | CREATE TABLE accommodations (id INT,country VARCHAR(255),region VARCHAR(255),accommodation_type VARCHAR(255),count INT); INSERT INTO accommodations (id,country,region,accommodation_type,count) VALUES (1,'South Africa','Western Cape','Sign Language Interpreters',120); INSERT INTO accommodations (id,country,region,accomm... | SELECT accommodation_type, SUM(count) as total_count FROM accommodations WHERE country = 'South Africa' GROUP BY accommodation_type; |
Update a record with public health policy analysis data for a specific policy | CREATE TABLE public_health_policy_analysis_v3 (id INT,policy_name VARCHAR(30),impact_score INT); | UPDATE public_health_policy_analysis_v3 SET impact_score = 78 WHERE policy_name = 'Policy C'; |
How many financially capable individuals are there in the urban areas of the country? | CREATE TABLE financial_capability (location TEXT,capable BOOLEAN); INSERT INTO financial_capability (location,capable) VALUES ('City A',TRUE),('City B',FALSE),('City C',TRUE),('Town D',TRUE); | SELECT COUNT(*) FROM financial_capability WHERE location LIKE '%urban%' AND capable = TRUE; |
List the top 5 locations with the most incidents | CREATE TABLE incidents (incident_id INT,incident_type VARCHAR(50),location VARCHAR(50),date_time DATETIME); | SELECT location, COUNT(*) AS incidents_count FROM incidents GROUP BY location ORDER BY incidents_count DESC LIMIT 5; |
Insert a new record in the 'contractors' table with id 6, name 'EcoTech', country 'Canada', and registration_date '2021-06-22' | CREATE TABLE contractors (id INT,name VARCHAR(50),country VARCHAR(50),registration_date DATE); | INSERT INTO contractors (id, name, country, registration_date) VALUES (6, 'EcoTech', 'Canada', '2021-06-22'); |
What is the total number of cargo vessels in the 'fleet_inventory' table? | CREATE TABLE fleet_inventory (id INT,vessel_name TEXT,type TEXT,quantity INT); INSERT INTO fleet_inventory (id,vessel_name,type,quantity) VALUES (1,'Cargo Vessel 1','Cargo',20),(2,'Tanker Vessel 1','Tanker',30); | SELECT SUM(quantity) FROM fleet_inventory WHERE type = 'Cargo'; |
What was the total revenue for the "Basic" product line in Q2 2021? | CREATE TABLE sales (product_line VARCHAR(10),date DATE,revenue FLOAT); INSERT INTO sales (product_line,date,revenue) VALUES ('Premium','2021-04-01',5500),('Basic','2021-04-01',3500),('Premium','2021-04-02',6500),('Basic','2021-04-02',4500); | SELECT SUM(revenue) FROM sales WHERE product_line = 'Basic' AND date BETWEEN '2021-04-01' AND '2021-06-30'; |
Show the number of days in 2022 where there were no emergency calls | CREATE TABLE emergency_calls_2022 (id INT,call_date DATE); INSERT INTO emergency_calls_2022 (id,call_date) VALUES (1,'2022-01-01'),(2,'2022-01-02'),(3,'2022-01-03'),(4,'2022-02-01'),(5,'2022-02-02'),(6,'2022-03-01'),(7,'2022-03-02'),(8,'2022-03-03'); | SELECT call_date FROM emergency_calls_2022 GROUP BY call_date HAVING COUNT(*) = 0; |
How many solar power plants are there in the 'Southwest' region with a capacity greater than 100 MW? | CREATE TABLE SolarPlant (region VARCHAR(50),capacity FLOAT); | SELECT COUNT(*) FROM SolarPlant WHERE region = 'Southwest' AND capacity > 100; |
What is the maximum temperature recorded in the Sargasso Sea? | CREATE TABLE deep_sea_temperature_sargasso (location text,temperature numeric); INSERT INTO deep_sea_temperature_sargasso (location,temperature) VALUES ('Sargasso Sea',30),('Atlantic Ocean',25); | SELECT MAX(temperature) FROM deep_sea_temperature_sargasso WHERE location = 'Sargasso Sea'; |
What is the average age of players who play racing games? | CREATE TABLE Players (PlayerID INT,Age INT,GamePreference VARCHAR(20)); INSERT INTO Players (PlayerID,Age,GamePreference) VALUES (1,25,'Racing'); | SELECT AVG(Age) FROM Players WHERE GamePreference = 'Racing'; |
Update the CargoTable, setting the 'Weight' column to '0' for cargos with a CargoId of 10, 15, or 20 | CREATE TABLE CargoTable (CargoId INT PRIMARY KEY,VesselId INT,CargoName VARCHAR(50),Weight INT); | UPDATE CargoTable SET Weight = 0 WHERE CargoId IN (10, 15, 20); |
What is the total number of volunteers for each program? And which program has the highest total number of volunteers? | CREATE TABLE Programs (ProgramID INT,ProgramName VARCHAR(255)); INSERT INTO Programs (ProgramID,ProgramName) VALUES (1,'Education Support'),(2,'Environment Conservation'),(3,'Health Awareness'); | SELECT ProgramID, ProgramName, COUNT(VolunteerID) AS TotalVolunteers, RANK() OVER (ORDER BY COUNT(VolunteerID) DESC) AS ProgramRank FROM Volunteers JOIN Programs ON Volunteers.ProgramID = Programs.ProgramID GROUP BY ProgramID, ProgramName; |
How many public libraries are there in the city of "Chicago" with a rating greater than or equal to 8? | CREATE TABLE libraries (library_id INT,library_name TEXT,city TEXT,rating INT); INSERT INTO libraries (library_id,library_name,city,rating) VALUES (1,'Harold Washington Library','Chicago',9),(2,'Chicago Public Library','Chicago',8),(3,'Sulzer Regional Library','Chicago',7); | SELECT COUNT(*) FROM libraries WHERE city = 'Chicago' AND rating >= 8; |
Find the total climate finance provided by the World Bank for climate communication initiatives since 2015. | CREATE TABLE climate_finance (id INT,provider VARCHAR(100),initiative VARCHAR(100),amount FLOAT,year INT); INSERT INTO climate_finance (id,provider,initiative,amount,year) VALUES (1,'World Bank','Climate Communication',10000000,2015),(2,'UNDP','Climate Adaptation',15000000,2016); | SELECT SUM(amount) FROM climate_finance WHERE provider = 'World Bank' AND initiative = 'Climate Communication' AND year >= 2015; |
What are the names and completion dates of all utility projects in the infrastructure database? | CREATE TABLE Infrastructure_Projects (Project_ID INT,Project_Name VARCHAR(50),Project_Type VARCHAR(50),Completion_Date DATE); INSERT INTO Infrastructure_Projects (Project_ID,Project_Name,Project_Type,Completion_Date) VALUES (1,'Seawall','Resilience','2021-02-28'),(2,'Floodgate','Resilience','2020-12-31'),(3,'Bridge_Rep... | SELECT Project_Name, Completion_Date FROM Infrastructure_Projects WHERE Project_Type = 'Utility'; |
What is the number of climate adaptation projects in small island developing states (SIDS) that were initiated from 2010 to 2015, and how many of those projects received funding? | CREATE TABLE climate_projects (region VARCHAR(255),year INT,project_type VARCHAR(255),funded BOOLEAN); | SELECT project_type, COUNT(*) AS num_projects, SUM(funded) AS num_funded FROM climate_projects WHERE year BETWEEN 2010 AND 2015 AND region IN (SELECT region FROM sids_list) GROUP BY project_type; |
What is the distribution of funding sources for the "Literature Festival" and "Film Festival" programs? | CREATE TABLE LiteratureFestival(id INT,funding_source VARCHAR(20),amount DECIMAL(10,2)); CREATE TABLE FilmFestival(id INT,funding_source VARCHAR(20),amount DECIMAL(10,2)); | SELECT funding_source, SUM(amount) FROM LiteratureFestival GROUP BY funding_source UNION SELECT funding_source, SUM(amount) FROM FilmFestival GROUP BY funding_source; |
How many whale sharks are there in the Atlantic Ocean?" | CREATE TABLE whale_sharks (id INT,name TEXT,location TEXT,population INT); INSERT INTO whale_sharks (id,name,location,population) VALUES (1,'Whale Shark','Atlantic',450); | SELECT SUM(population) FROM whale_sharks WHERE location = 'Atlantic'; |
What are the average soil moisture levels for each crop type in the past month? | CREATE TABLE crop_data (id INT,crop_type VARCHAR(255),soil_moisture INT,timestamp TIMESTAMP); INSERT INTO crop_data (id,crop_type,soil_moisture,timestamp) VALUES (1,'Corn',75,'2022-01-01 10:00:00'),(2,'Soybeans',80,'2022-01-01 10:00:00'); | SELECT crop_type, AVG(soil_moisture) FROM crop_data WHERE timestamp >= DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 MONTH) GROUP BY crop_type; |
Who are the top 5 authors with the highest number of published articles in the "sports" section in 2020? | CREATE TABLE authors (id INT,name TEXT,bio TEXT); CREATE VIEW article_authors AS SELECT a.id,a.name,a.bio,w.id as article_id,w.title,w.section,w.publish_date FROM website_articles w JOIN authors a ON w.author_id = a.id; | SELECT name, COUNT(*) as article_count FROM article_authors WHERE section = 'sports' AND publish_date BETWEEN '2020-01-01' AND '2020-12-31' GROUP BY name ORDER BY article_count DESC LIMIT 5; |
What is the maximum water consumption in the month of July for each water treatment plant in the state of California in 2020? | CREATE TABLE water_treatment_plant (plant_id INT,state VARCHAR(50),year INT,month INT,water_consumption FLOAT); INSERT INTO water_treatment_plant (plant_id,state,year,month,water_consumption) VALUES (1,'California',2020,7,12345.6),(2,'California',2020,7,23456.7),(3,'California',2020,7,34567.8); | SELECT plant_id, MAX(water_consumption) as max_water_consumption FROM water_treatment_plant WHERE state = 'California' AND year = 2020 AND month = 7 GROUP BY plant_id; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.