instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
Update the name of DrugA to DrugAlpha in Q1 2017 sales figures. | CREATE TABLE sales_figures (quarter INT,drug_name VARCHAR(255),sales_amount FLOAT); INSERT INTO sales_figures (quarter,drug_name,sales_amount) VALUES (1,'DrugB',45000),(1,'DrugA',40000),(2,'DrugA',55000),(2,'DrugB',65000),(1,'DrugAlpha',35000); | UPDATE sales_figures SET drug_name = 'DrugAlpha' WHERE drug_name = 'DrugA' AND quarter = 1; |
What is the average area of fields located in the Gulf of Mexico? | CREATE TABLE fields (field_id INT,field_name VARCHAR(255),location VARCHAR(255),area FLOAT,discovery_date DATE); INSERT INTO fields (field_id,field_name,location,area,discovery_date) VALUES (3,'Field C','Gulf of Mexico',1200.0,'2010-01-01'); INSERT INTO fields (field_id,field_name,location,area,discovery_date) VALUES (... | SELECT location, AVG(area) FROM fields WHERE location = 'Gulf of Mexico' GROUP BY location; |
What is the maximum timber production area for each region? | CREATE TABLE timber (id INT,region_id INT,area FLOAT); INSERT INTO timber (id,region_id,area) VALUES (1,1,123.45); INSERT INTO timber (id,region_id,area) VALUES (2,2,234.56); CREATE TABLE region (id INT,name VARCHAR(255)); INSERT INTO region (id,name) VALUES (1,'Region1'); INSERT INTO region (id,name) VALUES (2,'Region... | SELECT r.name, MAX(t.area) as max_area FROM timber t JOIN region r ON t.region_id = r.id GROUP BY r.name; |
What is the total number of hospitals and clinics in the healthcare system? | CREATE TABLE hospitals (id INT,name TEXT,location TEXT,num_beds INT); INSERT INTO hospitals (id,name,location,num_beds) VALUES (1,'General Hospital','City A',500),(2,'Community Clinic','City B',50); CREATE TABLE clinics (id INT,name TEXT,location TEXT,num_doctors INT); INSERT INTO clinics (id,name,location,num_doctors)... | SELECT COUNT(*) FROM hospitals UNION SELECT COUNT(*) FROM clinics; |
What is the total number of volunteer hours served by volunteers from underrepresented communities in the month of March 2021? | CREATE TABLE VolunteerTransactions (VolunteerID INT,Hours DECIMAL(5,2),VolunteerCommunity TEXT,TransactionMonth INT); INSERT INTO VolunteerTransactions (VolunteerID,Hours,VolunteerCommunity,TransactionMonth) VALUES (1,25.50,'Minority',3),(2,30.00,'LGBTQ+',2),(3,40.00,'Women in Tech',3); | SELECT SUM(Hours) FROM VolunteerTransactions WHERE VolunteerCommunity IN ('Minority', 'LGBTQ+', 'Women in Tech') AND TransactionMonth = 3; |
Calculate the average water temperature in the Arctic Ocean for salmon farms in January. | CREATE TABLE Arctic_Ocean (temperature FLOAT,month DATE); INSERT INTO Arctic_Ocean (temperature,month) VALUES (0.0,'2022-01-01'); INSERT INTO Arctic_Ocean (temperature,month) VALUES (-1.5,'2022-01-15'); CREATE TABLE Salmon_Farms (id INT,ocean VARCHAR(10)); INSERT INTO Salmon_Farms (id,ocean) VALUES (1,'Arctic'); | SELECT AVG(temperature) FROM Arctic_Ocean INNER JOIN Salmon_Farms ON Arctic_Ocean.month = '2022-01-01' WHERE Salmon_Farms.ocean = 'Arctic'; |
List all the co-owners in the 'inclusive_co_ownership' table that have a 'shared_cost' greater than 50000. | CREATE TABLE inclusive_co_ownership (id INT,owner VARCHAR(20),shared_cost INT); INSERT INTO inclusive_co_ownership (id,owner,shared_cost) VALUES (1,'Ava',60000),(2,'Bella',40000),(3,'Charlie',70000); | SELECT * FROM inclusive_co_ownership WHERE shared_cost > 50000; |
What is the total funding received by startups founded before 2017? | CREATE TABLE startups (id INT,name VARCHAR(255),founding_year INT); INSERT INTO startups (id,name,founding_year) VALUES (1,'Acme Inc',2015),(2,'Bravo Corp',2017); CREATE TABLE funding (startup_id INT,amount INT); INSERT INTO funding (startup_id,amount) VALUES (1,500000),(1,1000000),(2,750000); | SELECT SUM(funding.amount) FROM funding INNER JOIN startups ON funding.startup_id = startups.id WHERE startups.founding_year < 2017; |
How many electric vehicles have been sold in California since 2019? | CREATE TABLE ev_sales (state VARCHAR(50),year INT,make VARCHAR(50),model VARCHAR(50),sales INT); INSERT INTO ev_sales (state,year,make,model,sales) VALUES ('California',2019,'Tesla','Model 3',30000),('California',2020,'Tesla','Model Y',45000),('California',2021,'Ford','Mustang Mach-E',25000),('California',2019,'Chevrol... | SELECT SUM(sales) FROM ev_sales WHERE state = 'California' AND year >= 2019; |
What is the total number of articles by each author in the 'articles' table, sorted by the total count in descending order? | CREATE TABLE articles (author VARCHAR(50),title VARCHAR(50),date DATE,topic VARCHAR(50)); INSERT INTO articles (author,title,date,topic) VALUES ('John Doe','Article 1','2021-01-01','Topic A'),('Jane Smith','Article 2','2021-01-02','Topic B'),('John Doe','Article 3','2021-01-03','Topic A'); | SELECT author, COUNT(*) as total_articles FROM articles GROUP BY author ORDER BY total_articles DESC; |
What is the average income in each city in the state of California? | CREATE TABLE incomes (id INT,city VARCHAR(50),state VARCHAR(50),income FLOAT); INSERT INTO incomes (id,city,state,income) VALUES (1,'City A','California',50000),(2,'City B','California',60000),(3,'City C','Texas',70000); | SELECT state, AVG(income) as avg_income FROM incomes WHERE state = 'California' GROUP BY state; |
What was the total cost of sustainable building materials for each project in Washington that lasted more than 3 months and started before 2021? | CREATE TABLE Projects_WA (project_id INT,start_date DATE,end_date DATE,material_cost FLOAT,project_state VARCHAR(20)); INSERT INTO Projects_WA (project_id,start_date,end_date,material_cost,project_state) VALUES (1,'2020-01-01','2020-03-31',7000,'Washington'),(2,'2020-01-01','2020-04-15',9000,'Washington'),(3,'2022-01-0... | SELECT project_id, SUM(material_cost) OVER (PARTITION BY project_id) AS total_cost FROM Projects_WA WHERE project_state = 'Washington' AND start_date < end_date AND start_date < '2021-01-01' AND end_date >= '2021-01-01'; |
Who are the top 5 artists with the highest total revenue generated from their streams in Germany? | CREATE TABLE streams (id INT,track_id INT,user_id INT,region VARCHAR(255),genre VARCHAR(255),revenue DECIMAL(10,2),timestamp TIMESTAMP); CREATE TABLE tracks (id INT,title VARCHAR(255),artist VARCHAR(255),genre VARCHAR(255)); | SELECT artist, SUM(revenue) AS total_revenue FROM streams s JOIN tracks t ON s.track_id = t.id WHERE s.region = 'Germany' GROUP BY artist ORDER BY total_revenue DESC LIMIT 5; |
What is the number of sustainable building projects per month in the last year? | CREATE TABLE sustainable_projects (project_id SERIAL PRIMARY KEY,start_date DATE,end_date DATE,is_sustainable BOOLEAN); INSERT INTO sustainable_projects (project_id,start_date,end_date,is_sustainable) VALUES (1,'2021-01-01','2021-06-01',true),(2,'2021-02-01','2021-08-15',false),(3,'2021-03-01','2021-10-01',true); | SELECT TO_CHAR(start_date, 'Month') AS month, COUNT(project_id) AS sustainable_projects_count FROM sustainable_projects WHERE is_sustainable = true AND start_date >= NOW() - INTERVAL '1 year' GROUP BY month ORDER BY TO_DATE(month, 'Month') ASC; |
Find the total number of sensors that have been active in the past week, and the average temperature and humidity recorded. | CREATE TABLE sensor_data (id INT,sensor_id VARCHAR(255),temperature INT,humidity INT,status VARCHAR(255),timestamp DATETIME); INSERT INTO sensor_data (id,sensor_id,temperature,humidity,status,timestamp) VALUES (1,'SENS001',22,65,'active','2022-01-01 10:00:00'); | SELECT status, COUNT(*) as sensor_count, AVG(temperature) as avg_temp, AVG(humidity) as avg_humidity FROM sensor_data WHERE status = 'active' AND timestamp >= DATE_SUB(CURRENT_TIMESTAMP(), INTERVAL 1 WEEK) GROUP BY status; |
Insert a new record into the 'gas_fields' table with the following data: 'South Pars', 'offshore', 1990 | CREATE TABLE gas_fields (field_name VARCHAR(50) PRIMARY KEY,field_type VARCHAR(20),discovery_year INT); | INSERT INTO gas_fields (field_name, field_type, discovery_year) VALUES ('South Pars', 'offshore', 1990); |
How many smart city projects are there in Tokyo, Japan? | CREATE TABLE smart_city_projects (id INT,project_name VARCHAR(50),city VARCHAR(50),country VARCHAR(50),project_type VARCHAR(50)); INSERT INTO smart_city_projects (id,project_name,city,country,project_type) VALUES (1,'Tokyo Smart Grid','Tokyo','Japan','Grid Modernization'); | SELECT COUNT(*) FROM smart_city_projects WHERE city = 'Tokyo' AND country = 'Japan'; |
What is the percentage of patients who identify as LGBTQ+ and have achieved health equity? | CREATE TABLE patients (id INT,name VARCHAR(100),lgbtq_identification BOOLEAN,health_equity BOOLEAN); INSERT INTO patients (id,name,lgbtq_identification,health_equity) VALUES (1,'Mark',true,true),(2,'Nancy',false,true),(3,'Oliver',true,false); | SELECT (COUNT(*) FILTER (WHERE lgbtq_identification = true AND health_equity = true)) * 100.0 / COUNT(*) FROM patients; |
What is the count of students in 'Spring 2023' by school district? | CREATE TABLE student_enrollment (student_id INT,school_district VARCHAR(255),date DATE); INSERT INTO student_enrollment (student_id,school_district,date) VALUES (1,'XYZ School District','2023-03-01'); CREATE VIEW spring_2023_enrollment AS SELECT * FROM student_enrollment WHERE date BETWEEN '2023-01-01' AND '2023-06-30'... | SELECT COUNT(*) as total_students, school_district FROM spring_2023_enrollment GROUP BY school_district; |
Which athletes from the wellbeing program have the lowest and highest average heart rate during training sessions in the last 6 months? | CREATE TABLE athletes (athlete_id INT,name VARCHAR(20),wellbeing_program BOOLEAN); INSERT INTO athletes (athlete_id,name,wellbeing_program) VALUES (1,'John',true),(2,'Jane',true); CREATE TABLE training_sessions (session_id INT,athlete_id INT,heart_rate INT,session_date DATE); INSERT INTO training_sessions (session_id,a... | SELECT athletes.name, AVG(training_sessions.heart_rate) FROM athletes INNER JOIN training_sessions ON athletes.athlete_id = training_sessions.athlete_id WHERE training_sessions.session_date >= DATEADD(month, -6, GETDATE()) AND athletes.wellbeing_program = true GROUP BY athletes.name ORDER BY AVG(training_sessions.heart... |
Who are the investors who used a specific investment strategy? | CREATE TABLE Investments (InvestmentID INT,InvestorID INT,StrategyID INT); INSERT INTO Investments (InvestmentID,InvestorID,StrategyID) VALUES (1,1,1),(2,1,1),(3,2,2),(4,2,2),(5,3,3),(6,3,3),(7,4,4),(8,4,4),(9,1,1),(10,2,2); CREATE TABLE Investors (InvestorID INT,Name VARCHAR(20)); INSERT INTO Investors (InvestorID,Nam... | SELECT Investors.Name FROM Investors JOIN Investments ON Investors.InvestorID = Investments.InvestorID JOIN InvestmentStrategies ON Investments.StrategyID = InvestmentStrategies.StrategyID WHERE InvestmentStrategies.StrategyName = 'Impact Investing'; |
What are the top 5 most vulnerable systems in the organization, based on their Common Vulnerability Scoring System (CVSS) scores, in the last month? | CREATE TABLE systems (system_id INT,system_name TEXT,cvss_score FLOAT,last_updated DATETIME);INSERT INTO systems (system_id,system_name,cvss_score,last_updated) VALUES (1,'Web Server 1',7.5,'2022-01-01 10:00:00'),(2,'Database Server 1',8.2,'2022-01-02 11:00:00'),(3,'Email Server 1',6.8,'2022-01-03 12:00:00'),(4,'File S... | SELECT system_name, cvss_score FROM systems WHERE last_updated >= DATEADD(month, -1, GETDATE()) ORDER BY cvss_score DESC LIMIT 5; |
Which co-ownership properties have a maintenance cost over $100? | CREATE TABLE CoOwnershipProperties (PropertyID INT,MaintenanceCost DECIMAL(5,2)); INSERT INTO CoOwnershipProperties (PropertyID,MaintenanceCost) VALUES (1,50.50),(2,120.00),(3,75.25); | SELECT PropertyID FROM CoOwnershipProperties WHERE MaintenanceCost > 100; |
Update the address of 'Rural Hospital B' in the "hospitals" table from '789 Oak St' to '987 Pine St' where the hospital ID is '456' | CREATE TABLE hospitals (id INT PRIMARY KEY,name VARCHAR(50),address VARCHAR(100)); INSERT INTO hospitals (id,name,address) VALUES ('123','Rural Hospital A','123 Main St'),('456','Rural Hospital B','789 Oak St'); | UPDATE hospitals SET address = '987 Pine St' WHERE id = '456'; |
How many public libraries are there in total in the state of New York and the state of California combined? | CREATE TABLE public_libraries (name TEXT,state TEXT); INSERT INTO public_libraries (name,state) VALUES ('Library A','New York'),('Library B','New York'),('Library C','California'); | SELECT COUNT(*) FROM public_libraries WHERE state IN ('New York', 'California'); |
How many cases of Influenza were reported in Chicago in 2018? | CREATE TABLE disease_reports (id INT,disease VARCHAR(50),location VARCHAR(50),year INT,reported INT); INSERT INTO disease_reports (id,disease,location,year,reported) VALUES (1,'Influenza','Chicago',2018,43875),(2,'Influenza','Chicago',2017,44345); | SELECT reported FROM disease_reports WHERE disease = 'Influenza' AND location = 'Chicago' AND year = 2018; |
What is the total value of defense contracts awarded to company 'Smith & Wesson' in the year 2020? | CREATE SCHEMA if not exists defense_industry AUTHORIZATION def_admin; CREATE TABLE if not exists defense_industry.contracts(contract_id INT PRIMARY KEY,contractor VARCHAR(255),contract_value DECIMAL(10,2),contract_date DATE); INSERT INTO defense_industry.contracts(contract_id,contractor,contract_value,contract_date) VA... | SELECT SUM(contract_value) FROM defense_industry.contracts WHERE contractor = 'Smith & Wesson' AND contract_date >= '2020-01-01' AND contract_date < '2021-01-01'; |
Delete the volunteer with ID 4. | CREATE TABLE Volunteers (VolunteerID INT,Name TEXT,Country TEXT,JoinDate DATE); INSERT INTO Volunteers (VolunteerID,Name,Country,JoinDate) VALUES (3,'Aarav Patel','India','2021-09-01'); INSERT INTO Volunteers (VolunteerID,Name,Country,JoinDate) VALUES (4,'Priya Gupta','USA','2022-01-10'); | DELETE FROM Volunteers WHERE VolunteerID = 4; |
What is the total installed capacity for geothermal projects in Asia? | CREATE TABLE geothermal_projects (id INT,name VARCHAR(255),location VARCHAR(255),capacity INT); | SELECT SUM(capacity) FROM geothermal_projects WHERE location LIKE '%Asia%'; |
What is the average water consumption in the industrial sector in Egypt for the year 2019? | 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 ('Egypt','Industrial',2019,8000000); | SELECT AVG(value) FROM water_consumption_kl WHERE sector = 'Industrial' AND region = 'Egypt' AND year = 2019; |
What's the total investment amount and number of investments by each investor? | CREATE TABLE if not exists investors (id INT PRIMARY KEY,name TEXT,location TEXT,investment_goal TEXT); INSERT INTO investors (id,name,location,investment_goal) VALUES (1,'John Doe','New York','Climate Change'); CREATE TABLE if not exists investments (id INT PRIMARY KEY,investor_id INT,nonprofit_id INT,amount DECIMAL(1... | SELECT i.name, SUM(investment.amount) AS total_investment_amount, COUNT(investment.id) AS number_of_investments FROM investors i JOIN investments investment ON i.id = investment.investor_id GROUP BY i.id; |
How many volunteers have contributed more than 50 hours in Germany? | CREATE TABLE Volunteers (VolunteerID INT,VolunteerName TEXT,Hours INT,Country TEXT); INSERT INTO Volunteers (VolunteerID,VolunteerName,Hours,Country) VALUES (1,'Max Mustermann',75,'Germany'),(2,'Erika Musterfrau',30,'Germany'); | SELECT COUNT(*) FROM Volunteers WHERE Country = 'Germany' AND Hours > 50; |
Show policyholders from 'California' | CREATE TABLE Policyholders (PolicyholderID INT,Age INT,Gender VARCHAR(10),State VARCHAR(20)); INSERT INTO Policyholders (PolicyholderID,Age,Gender,State) VALUES (1,34,'Female','California'),(2,45,'Male','New York'),(3,52,'Male','California'); | SELECT * FROM Policyholders WHERE State = 'California'; |
What is the total CO2 emissions reduction in Mega tonnes, for each country, in the renewable energy sector in the last 5 years? | CREATE TABLE co2_emissions (id INT,country VARCHAR(50),sector VARCHAR(50),year INT,emissions FLOAT); INSERT INTO co2_emissions (id,country,sector,year,emissions) VALUES (1,'Germany','Renewable Energy',2017,123.4),(2,'China','Renewable Energy',2018,456.7),(3,'United States','Renewable Energy',2019,789.0); | SELECT country, SUM(emissions) FROM co2_emissions WHERE sector = 'Renewable Energy' AND year >= 2016 GROUP BY country; |
What is the average salary by department for employees who have been trained? | CREATE TABLE Employees (EmployeeID INT,Department VARCHAR(20),Salary FLOAT,Trained BOOLEAN); INSERT INTO Employees (EmployeeID,Department,Salary,Trained) VALUES (1,'IT',75000.0,1),(2,'HR',65000.0,0),(3,'IT',80000.0,1); | SELECT Department, AVG(Salary) FROM Employees WHERE Trained = 1 GROUP BY Department; |
Add a new mental health campaign in 'campaigns_2022' with id=5, name='Hope Rises', budget=10000, and region='Northeast'. | CREATE TABLE campaigns_2022 (campaign_id INT,name VARCHAR(50),budget INT,region VARCHAR(50)); | INSERT INTO campaigns_2022 (campaign_id, name, budget, region) VALUES (5, 'Hope Rises', 10000, 'Northeast'); |
What is the number of crimes committed by juveniles and adults in Chicago, broken down by type of crime and race, for the years 2018 and 2019? | CREATE TABLE crime (crime_id INT,year INT,age_group TEXT,race TEXT,crime_type TEXT); INSERT INTO crime (crime_id,year,age_group,race,crime_type) VALUES (1,2018,'Juvenile','White','Theft'); INSERT INTO crime (crime_id,year,age_group,race,crime_type) VALUES (2,2018,'Adult','Black','Assault'); INSERT INTO crime (crime_id,... | SELECT c.year, c.age_group, c.race, c.crime_type, COUNT(c.crime_id) AS crime_count FROM crime c WHERE c.year IN (2018, 2019) GROUP BY c.year, c.age_group, c.race, c.crime_type; |
What is the recycling rate for plastic and glass in the city of New York in 2019?' | CREATE TABLE recycling_rates (city VARCHAR(20),year INT,material_type VARCHAR(20),recycling_rate DECIMAL(5,2)); INSERT INTO recycling_rates VALUES ('New York',2019,'Plastic',0.3),('New York',2019,'Glass',0.5),('New York',2019,'Paper',0.7),('New York',2019,'Metal',0.6),('New York',2019,'Organic',0.4); | SELECT material_type, AVG(recycling_rate) AS avg_recycling_rate FROM recycling_rates WHERE city = 'New York' AND year = 2019 AND material_type IN ('Plastic', 'Glass') GROUP BY material_type; |
Identify the top 3 emergency response times for 'Fire' incidents, in the 'EmergencyResponse' table, for regions 'North', 'South', and 'East'. | CREATE TABLE EmergencyResponse (id INT,incidentType VARCHAR(20),region VARCHAR(10),responseTime INT); | SELECT incidentType, region, MIN(responseTime) FROM EmergencyResponse WHERE incidentType = 'Fire' AND region IN ('North', 'South', 'East') GROUP BY incidentType, region ORDER BY responseTime LIMIT 3; |
What is the average ESG score for companies in the 'Renewable Energy' industry? | CREATE TABLE company (id INT PRIMARY KEY,name TEXT,industry TEXT,location TEXT,esg_score INT); INSERT INTO company (id,name,industry,location,esg_score) VALUES (1,'EcoPower','Renewable Energy','USA',82); INSERT INTO company (id,name,industry,location,esg_score) VALUES (2,'GreenTech','Renewable Energy','Germany',87); IN... | SELECT AVG(esg_score) AS avg_esg_score FROM company WHERE industry = 'Renewable Energy'; |
Update the name of user with id 1 to 'Jane Doe' | CREATE TABLE users (id INT,name VARCHAR(100)); INSERT INTO users (id,name) VALUES (1,'John Doe'),(2,'Jane Smith'); | UPDATE users SET name = 'Jane Doe' WHERE id = 1; |
What is the average response time for emergency medical services (EMS) in each precinct over the last year? | CREATE TABLE Precincts (PrecinctID INT,PrecinctName VARCHAR(255)); CREATE TABLE EMSResponses (ResponseID INT,ResponseType VARCHAR(255),PrecinctID INT,ResponseTime INT,ResponseDate DATE); | SELECT p.PrecinctName, AVG(ResponseTime) as AvgResponseTime FROM EMSResponses r JOIN Precincts p ON r.PrecinctID = p.PrecinctID WHERE r.ResponseType = 'EMS' AND r.ResponseDate >= DATEADD(year, -1, GETDATE()) GROUP BY p.PrecinctName; |
Find the top 2 countries with the highest average loan amount for socially responsible lending in Q2 2022, partitioned by month. | CREATE TABLE loans (id INT,country VARCHAR(50),amount DECIMAL(10,2),date DATE); INSERT INTO loans (id,country,amount,date) VALUES (1,'USA',1000.00,'2022-04-01'),(2,'Canada',1500.00,'2022-04-05'),(3,'Mexico',800.00,'2022-04-10'),(4,'USA',1200.00,'2022-05-01'),(5,'Canada',900.00,'2022-05-05'),(6,'Mexico',1000.00,'2022-05... | SELECT country, AVG(amount) as avg_amount, EXTRACT(MONTH FROM date) as month FROM loans WHERE date >= '2022-04-01' AND date < '2022-07-01' GROUP BY country, month ORDER BY avg_amount DESC, month LIMIT 2; |
Which marine conservation initiatives in the Arctic Ocean have been ongoing for more than 5 years? | CREATE TABLE marine_conservation_initiatives (name VARCHAR(255),location VARCHAR(255),start_date DATE,end_date DATE); | SELECT * FROM marine_conservation_initiatives WHERE location LIKE '%Arctic%' AND DATEDIFF(end_date, start_date) > 1825; |
Find the number of cases that were open for more than 6 months for clients who identify as 'Hispanic' or 'Latino'? | CREATE TABLE clients (client_id INT,ethnicity VARCHAR(50)); CREATE TABLE cases (case_id INT,client_id INT,open_date DATE); INSERT INTO clients (client_id,ethnicity) VALUES (1,'Hispanic'),(2,'Latino'); INSERT INTO cases (case_id,client_id,open_date) VALUES (1,1,'2021-01-01'); | SELECT COUNT(*) FROM cases JOIN clients ON cases.client_id = clients.client_id WHERE clients.ethnicity IN ('Hispanic', 'Latino') AND cases.open_date <= DATE_SUB(CURDATE(), INTERVAL 6 MONTH); |
What is the maximum number of transactions that have been executed by a single smart contract in a single day? | CREATE TABLE smart_contracts (contract_id INT,name VARCHAR(255),date DATE); CREATE TABLE transactions (transaction_id INT,contract_id INT); INSERT INTO smart_contracts (contract_id,name,date) VALUES (1,'Contract1','2021-01-01'),(2,'Contract2','2021-01-02'),(3,'Contract3','2021-01-03'),(4,'Contract4','2021-01-04'),(5,'C... | SELECT contract_id, MAX(transaction_count) AS max_transactions FROM (SELECT contract_id, COUNT(*) AS transaction_count FROM transactions JOIN smart_contracts ON transactions.contract_id = smart_contracts.contract_id GROUP BY contract_id, date) AS transactions_per_day GROUP BY contract_id; |
List all 'tourism_destinations' with their respective visitor counts and carbon footprint. | CREATE TABLE tourism_destinations (destination_name VARCHAR(50),visitor_count INT,carbon_footprint INT); INSERT INTO tourism_destinations (destination_name,visitor_count,carbon_footprint) VALUES ('Paris',1000000,500),('Rome',800000,400),('Barcelona',900000,450); | SELECT destination_name, visitor_count, carbon_footprint FROM tourism_destinations; |
Find the top 2 rural infrastructure projects with the highest budgets in Asia and their completion years. | CREATE TABLE infrastructure (id INT,region VARCHAR(50),project VARCHAR(50),year INT,budget INT); INSERT INTO infrastructure (id,region,project,year,budget) VALUES (1,'Asia','Railway Expansion',2018,600000),(2,'Africa','Highway Construction',2020,400000); | SELECT project, year, budget FROM infrastructure WHERE region = 'Asia' ORDER BY budget DESC LIMIT 2; |
How many properties were sold in each month of 2021? | CREATE TABLE properties (property_id INT,sale_date DATE); | SELECT EXTRACT(MONTH FROM sale_date) as month, COUNT(property_id) as sales_in_month FROM properties WHERE sale_date BETWEEN '2021-01-01' AND '2021-12-31' GROUP BY month ORDER BY month; |
Total revenue of Abstract paintings sold in Paris since 2015? | CREATE TABLE ArtSales (id INT,painting_name VARCHAR(50),price FLOAT,sale_date DATE,painting_style VARCHAR(20),sale_location VARCHAR(30)); INSERT INTO ArtSales (id,painting_name,price,sale_date,painting_style,sale_location) VALUES (1,'Painting1',7000,'2016-01-01','Abstract','Paris'); | SELECT SUM(price) FROM ArtSales WHERE painting_style = 'Abstract' AND sale_location = 'Paris' AND sale_date >= '2015-01-01'; |
What is the number of marine protected areas in each ocean? | CREATE TABLE marine_protected_areas (id INT,name VARCHAR(255),location VARCHAR(255),depth FLOAT); INSERT INTO marine_protected_areas (id,name,location,depth) VALUES (1,'MPA 1','Pacific Ocean',123.4),(2,'MPA 2','Atlantic Ocean',150.0),(3,'MPA 3','Indian Ocean',75.0),(4,'MPA 4','Pacific Ocean',300.0); CREATE TABLE oceans... | SELECT location, COUNT(*) FROM marine_protected_areas GROUP BY location; |
Find the number of players who have played 'SportsGame' more than 200 hours in 'UK' region. | CREATE TABLE SportsGame (playerID INT,region VARCHAR(5),playtime INT); INSERT INTO SportsGame (playerID,region,playtime) VALUES (1,'UK',300),(2,'UK',100),(3,'UK',250),(4,'EU',80); | SELECT COUNT(*) FROM SportsGame WHERE region = 'UK' AND playtime > 200; |
What is the total quantity of jellyfish and sea cucumbers in each oceanographic region, and which regions have the highest combined quantities? | CREATE TABLE MarineLife (Region VARCHAR(20),Species VARCHAR(20),Quantity INT); INSERT INTO MarineLife (Region,Species,Quantity) VALUES ('Atlantic','Jellyfish',1200),('Atlantic','SeaCucumber',800),('Pacific','Jellyfish',1800),('Pacific','SeaCucumber',1500),('Indian','Jellyfish',900),('Indian','SeaCucumber',1100); | SELECT Region, SUM(Quantity) FROM MarineLife WHERE Species IN ('Jellyfish', 'SeaCucumber') GROUP BY Region ORDER BY SUM(Quantity) DESC; |
What was the minimum sea surface temperature in the Indian Ocean in 2019? | CREATE TABLE ocean_temperatures (year INT,region VARCHAR(20),temperature DECIMAL(5,2)); INSERT INTO ocean_temperatures (year,region,temperature) VALUES (2019,'Indian Ocean',27.3); INSERT INTO ocean_temperatures (year,region,temperature) VALUES (2019,'Indian Ocean',28.1); INSERT INTO ocean_temperatures (year,region,temp... | SELECT MIN(temperature) FROM ocean_temperatures WHERE year = 2019 AND region = 'Indian Ocean'; |
What are the top three countries with the most marine biodiversity in the Indian Ocean?" | CREATE TABLE marine_biodiversity (id INT,country TEXT,species_count INT,ocean TEXT); INSERT INTO marine_biodiversity (id,country,species_count,ocean) VALUES (1,'Indonesia',3700,'Indian'); | SELECT country, species_count FROM marine_biodiversity WHERE ocean = 'Indian' ORDER BY species_count DESC LIMIT 3; |
Determine the total number of hours spent playing games by female players | CREATE TABLE Players (PlayerID INT,Gender VARCHAR(10),HoursPlayed INT); INSERT INTO Players (PlayerID,Gender,HoursPlayed) VALUES (1,'Female',50); INSERT INTO Players (PlayerID,Gender,HoursPlayed) VALUES (2,'Male',100); | SELECT SUM(HoursPlayed) FROM Players WHERE Gender = 'Female'; |
What is the total quantity of recycled polyester used by brands in the 'ethical_brands' table? | CREATE TABLE ethical_brands (brand_id INT,brand_name TEXT,total_recycled_polyester_kg FLOAT); | SELECT SUM(total_recycled_polyester_kg) FROM ethical_brands; |
How many fans attended each team's games by age group? | CREATE TABLE FansByAge (FanID INT,Age INT,TeamID INT); INSERT INTO FansByAge (FanID,Age,TeamID) VALUES (1,22,1),(2,30,1),(3,38,2),(4,25,2); CREATE TABLE GameAttendanceByAge (GameID INT,FanID INT); INSERT INTO GameAttendanceByAge (GameID,FanID) VALUES (1,1),(1,2),(2,3),(2,4); | SELECT t.TeamName, f.AgeGroup, COUNT(*) as Total_Attendance FROM (SELECT FanID, CASE WHEN Age < 18 THEN 'Under 18' WHEN Age < 30 THEN '18-30' WHEN Age < 50 THEN '31-50' ELSE '50+' END as AgeGroup FROM FansByAge) f JOIN GameAttendanceByAge ga ON f.FanID = ga.FanID JOIN Teams t ON f.TeamID = t.TeamID GROUP BY t.TeamName,... |
What is the highest number of whale sightings in a single month in the Southern Hemisphere? | CREATE TABLE whale_sightings (month INTEGER,hemisphere TEXT,sightings INTEGER); INSERT INTO whale_sightings (month,hemisphere,sightings) VALUES (1,'Southern',500),(2,'Northern',400),(3,'Southern',700); | SELECT MAX(sightings) FROM whale_sightings WHERE hemisphere = 'Southern'; |
What is the total funding amount for startups founded by people with disabilities? | CREATE TABLE startups (id INT,name TEXT,location TEXT,founder_disability BOOLEAN,funding_amount INT); INSERT INTO startups (id,name,location,founder_disability,funding_amount) VALUES (1,'Startup A','USA',true,3000000); INSERT INTO startups (id,name,location,founder_disability,funding_amount) VALUES (2,'Startup B','Cana... | SELECT SUM(funding_amount) FROM startups WHERE founder_disability = true; |
Count the number of light rail vehicles operational on the last day of each month in 2022 | CREATE TABLE light_rail (id INT PRIMARY KEY,vehicle_id INT,operational BOOLEAN,operational_time TIMESTAMP); | SELECT DATE_FORMAT(operational_time, '%Y-%m-01') AS start_of_month, COUNT(*) AS num_vehicles FROM light_rail WHERE operational = TRUE AND operational_time >= '2022-01-01 00:00:00' AND operational_time < '2023-01-01 00:00:00' GROUP BY start_of_month; |
How many patients have been treated with teletherapy in each country? | CREATE TABLE teletherapy_sessions (id INT PRIMARY KEY,patient_id INT,session_date DATE,country VARCHAR(255)); INSERT INTO teletherapy_sessions (id,patient_id,session_date,country) VALUES (1,1,'2022-01-01','United States'); | SELECT country, COUNT(DISTINCT patient_id) as patient_count FROM teletherapy_sessions GROUP BY country; |
What is the percentage of on-time arrivals for vessels in the South China Sea in 2019? | CREATE TABLE vessels(id INT,name VARCHAR(100),region VARCHAR(50));CREATE TABLE arrivals(id INT,vessel_id INT,arrival_date DATE,on_time BOOLEAN); | SELECT 100.0 * COUNT(*) / (SELECT COUNT(*) FROM arrivals a WHERE a.vessel_id = v.id) AS percentage FROM arrivals a JOIN vessels v ON a.vessel_id = v.id WHERE v.region = 'South China Sea' AND on_time = TRUE; |
What is the number of customers in each region? | CREATE TABLE customers (customer_id INT,name VARCHAR(50),region VARCHAR(50)); INSERT INTO customers (customer_id,name,region) VALUES (1,'John Doe','Midwest'),(2,'Jane Smith','Northeast'),(3,'Bob Johnson','Midwest'); | SELECT region, COUNT(*) FROM customers GROUP BY region; |
What is the average age of artifacts from the 'Mesoamerican_Artifacts' table? | CREATE TABLE Mesoamerican_Artifacts (id INT,artifact_name VARCHAR(50),age INT); INSERT INTO Mesoamerican_Artifacts (id,artifact_name,age) VALUES (1,'Jade Mask',2500),(2,'Obsidian Knife',1800),(3,'Ceramic Pot',3000); | SELECT AVG(age) FROM Mesoamerican_Artifacts; |
What is the maximum population of a facility in the 'health_facilities' table? | CREATE TABLE health_facilities (facility_id INT,name VARCHAR(50),type VARCHAR(50),population INT,city VARCHAR(50),state VARCHAR(50)); | SELECT MAX(population) FROM health_facilities; |
List the rural infrastructure projects in Ghana that started in 2019. | CREATE TABLE RuralInfrastructure (id INT,country VARCHAR(50),project VARCHAR(50),start_date DATE); INSERT INTO RuralInfrastructure (id,country,project,start_date) VALUES (1,'Ghana','Road Construction','2019-03-01'),(2,'Ghana','Bridge Building','2018-08-15'),(3,'Nigeria','Electricity Grid Expansion','2020-06-05'); | SELECT project FROM RuralInfrastructure WHERE country = 'Ghana' AND start_date >= '2019-01-01' AND start_date < '2020-01-01'; |
Identify dispensaries with more than 500 sales in the last week, and update their status to 'High Volume'. | CREATE TABLE Dispensaries (DispensaryID INT,DispensaryName VARCHAR(50),Status VARCHAR(50)); | UPDATE D SET Status = 'High Volume' FROM Dispensaries D JOIN (SELECT DispensaryID FROM Sales WHERE SaleDate >= DATEADD(day, -7, GETDATE()) GROUP BY DispensaryID HAVING COUNT(*) > 500) S ON D.DispensaryID = S.DispensaryID; |
How many co-ownership properties have more than 3 bedrooms in the city of Toronto? | CREATE TABLE properties (id INT,city VARCHAR,num_bedrooms INT,co_ownership BOOLEAN); | SELECT COUNT(*) FROM properties WHERE city = 'Toronto' AND num_bedrooms > 3 AND co_ownership = TRUE; |
What is the minimum installed capacity of a wind energy project in the country of Canada? | CREATE TABLE wind_projects (id INT,country VARCHAR(20),installed_capacity FLOAT); INSERT INTO wind_projects (id,country,installed_capacity) VALUES (1,'Canada',35.0),(2,'Canada',45.2),(3,'Canada',55.3),(4,'Canada',65.0); | SELECT MIN(installed_capacity) FROM wind_projects WHERE country = 'Canada'; |
Determine the number of smart cities in each continent, represented in the smart_cities table. | CREATE TABLE smart_cities (city_id INT,city_name VARCHAR(255),location VARCHAR(255)); | SELECT SUBSTRING(location, 1, INSTR(location, '-') - 1) AS continent, COUNT(*) AS num_cities FROM smart_cities GROUP BY continent; |
List the states with their respective industrial water usage in descending order | CREATE TABLE water_usage_states (state VARCHAR(20),sector VARCHAR(20),usage FLOAT); INSERT INTO water_usage_states (state,sector,usage) VALUES ('California','Industrial',1200),('Texas','Industrial',1100),('Florida','Industrial',900),('New York','Industrial',800),('Illinois','Industrial',700),('Pennsylvania','Industrial... | SELECT state, usage FROM water_usage_states WHERE sector = 'Industrial' ORDER BY usage DESC; |
How many art exhibitions were held in Berlin in 2020? | CREATE TABLE Art_Exhibitions (id INT,city VARCHAR(50),year INT,attendance INT); CREATE VIEW Berlin_Events AS SELECT * FROM Art_Exhibitions WHERE city = 'Berlin'; | SELECT COUNT(*) FROM Berlin_Events WHERE year = 2020 AND city = 'Berlin'; |
Who are the top 3 suppliers with the highest total revenue? | CREATE TABLE suppliers (supplier_id INT,supplier_name VARCHAR(255)); CREATE TABLE purchases (purchase_id INT,supplier_id INT,purchase_amount DECIMAL(10,2)); | SELECT suppliers.supplier_name, SUM(purchases.purchase_amount) as total_revenue FROM purchases JOIN suppliers ON purchases.supplier_id = suppliers.supplier_id GROUP BY suppliers.supplier_name ORDER BY total_revenue DESC LIMIT 3; |
Update the affordability score for the given property ID | CREATE TABLE property (id INT PRIMARY KEY,affordability_score INT); | UPDATE property SET affordability_score = 85 WHERE id = 123; |
Which network infrastructure investments were made in the American region? | CREATE TABLE network_investments (investment_id INT,amount FLOAT,region VARCHAR(20)); INSERT INTO network_investments (investment_id,amount,region) VALUES (1,500000,'Europe'),(2,600000,'America'); | SELECT investment_id, amount FROM network_investments WHERE region = 'America'; |
What was the average time taken for restorative justice cases in each quarter of 2021? | CREATE TABLE restorative_justice_2 (case_id INT,quarter INT,year INT,time_taken INT); INSERT INTO restorative_justice_2 (case_id,quarter,year,time_taken) VALUES (1,1,2021,30),(2,1,2021,45),(3,2,2021,50),(4,2,2021,60),(5,3,2021,40),(6,3,2021,55),(7,4,2021,50),(8,4,2021,60); | SELECT quarter, AVG(time_taken) as avg_time FROM restorative_justice_2 WHERE year = 2021 GROUP BY quarter; |
Display the total biomass of fish in each species | CREATE TABLE fish_stock (fish_id INT PRIMARY KEY,species VARCHAR(50),location VARCHAR(50),biomass FLOAT); INSERT INTO fish_stock (fish_id,species,location,biomass) VALUES (1,'tuna','tropical',250.5),(2,'salmon','arctic',180.3),(3,'cod','temperate',120.0); | SELECT species, SUM(biomass) FROM fish_stock GROUP BY species; |
What is the minimum duration (in days) of any space mission that has used a Russian spacecraft? | CREATE TABLE space_missions (id INT,mission_name VARCHAR(50),launch_date DATE,duration INT,spacecraft_nationality VARCHAR(50)); INSERT INTO space_missions (id,mission_name,launch_date,duration,spacecraft_nationality) VALUES (1,'Artemis I','2022-08-29',26,'USA'); INSERT INTO space_missions (id,mission_name,launch_date,d... | SELECT MIN(duration) FROM space_missions WHERE spacecraft_nationality = 'Russia'; |
How many destinations did tourists from Australia visit in 2019? | CREATE TABLE tourism_stats (id INT PRIMARY KEY,year INT,country VARCHAR(255),destination VARCHAR(255)); INSERT INTO tourism_stats (id,year,country,destination) VALUES (1,2019,'Australia','Japan'),(2,2019,'Australia','USA'),(3,2019,'Australia','Thailand'); | SELECT COUNT(DISTINCT destination) FROM tourism_stats WHERE country = 'Australia' AND year = 2019; |
Insert new marine life records for the Gulf of California in 2022. | CREATE TABLE marine_life (location TEXT,year INTEGER,species TEXT,population REAL); | INSERT INTO marine_life (location, year, species, population) VALUES ('Gulf of California', 2022, 'Blue Whale', 500), ('Gulf of California', 2022, 'Leatherback Turtle', 300); |
Which teachers have led the most professional development courses? | CREATE TABLE teachers (id INT,name VARCHAR(255)); CREATE TABLE courses (id INT,teacher_id INT,name VARCHAR(255)); INSERT INTO teachers (id,name) VALUES (1,'Teacher A'),(2,'Teacher B'),(3,'Teacher C'),(4,'Teacher D'); INSERT INTO courses (id,teacher_id,name) VALUES (1,1,'Open Pedagogy 101'),(2,1,'Math'),(3,2,'Science'),... | SELECT t.name AS teacher_name, COUNT(c.id) AS num_courses FROM teachers t JOIN courses c ON t.id = c.teacher_id GROUP BY t.name ORDER BY num_courses DESC; |
Find the species with the highest total habitat area in 'habitat_preservation' table. | CREATE TABLE habitat_preservation (id INT,species VARCHAR(255),area INT); | SELECT species, SUM(area) AS total_area FROM habitat_preservation GROUP BY species ORDER BY total_area DESC LIMIT 1; |
Update the explainability score for ModelB to 0.85. | CREATE TABLE explainability_scores (id INT,model_id INT,score FLOAT); INSERT INTO explainability_scores (id,model_id,score) VALUES (1,1,0.75),(2,2,0.91); CREATE TABLE models (id INT,name TEXT); INSERT INTO models (id,name) VALUES (1,'ModelA'),(2,'ModelB'); | UPDATE explainability_scores SET score = 0.85 WHERE model_id = (SELECT id FROM models WHERE name = 'ModelB'); |
Find the number of unique donors for each program. | CREATE TABLE Donations (DonationID INT,DonorID INT,ProgramID INT); INSERT INTO Donations (DonationID,DonorID,ProgramID) VALUES (1,1,1),(2,2,1),(3,3,2),(4,1,3); | SELECT Programs.Name, COUNT(DISTINCT Donors.DonorID) as NumDonors FROM Programs INNER JOIN Donations ON Programs.ProgramID = Donations.ProgramID GROUP BY Programs.Name; |
What is the average number of points scored by players from the Eastern Conference in NBA games, excluding players with less than 10 games played? | CREATE TABLE NBA_Teams (Team VARCHAR(50),Conference VARCHAR(50),Points INT); INSERT INTO NBA_Teams (Team,Conference,Points) VALUES ('Atlanta Hawks','Eastern',8370),('Boston Celtics','Eastern',8218),('Brooklyn Nets','Eastern',7552); | SELECT AVG(Points) FROM NBA_Teams WHERE Conference = 'Eastern' AND Points > (SELECT AVG(Points) FROM NBA_Teams WHERE Conference = 'Eastern') GROUP BY Conference HAVING COUNT(*) >= 10; |
How many security incidents were reported in the APAC region in the last quarter? | CREATE TABLE incidents (incident_id INT PRIMARY KEY,incident_date TIMESTAMP,region VARCHAR(50)); | SELECT COUNT(*) FROM incidents WHERE incident_date >= NOW() - INTERVAL 3 MONTH AND region = 'APAC'; |
What is the maximum battery range of electric vehicles in the New_Vehicles table? | CREATE TABLE New_Vehicles (Vehicle_Type VARCHAR(20),Model VARCHAR(20),Battery_Range INT); | SELECT MAX(Battery_Range) FROM New_Vehicles WHERE Vehicle_Type = 'Electric'; |
What is the total waste generation by material type in New York? | CREATE TABLE waste_generation (location VARCHAR(50),material_type VARCHAR(50),quantity INT); INSERT INTO waste_generation (location,material_type,quantity) VALUES ('New York','Plastic',1500),('New York','Paper',2000),('New York','Glass',1000); | SELECT material_type, SUM(quantity) FROM waste_generation WHERE location = 'New York' GROUP BY material_type; |
List all universities in 'universities' table offering AI courses and ethics courses. | CREATE TABLE universities (university_name VARCHAR(50),location VARCHAR(50),ai_courses INTEGER,ethics_courses INTEGER); | SELECT university_name FROM universities WHERE ai_courses > 0 AND ethics_courses > 0; |
What are the total expenses for organizations focused on Art and Culture, sorted alphabetically by organization name? | CREATE TABLE organizations (id INT,name VARCHAR(100),mission_area VARCHAR(50),state VARCHAR(50)); CREATE TABLE expenses (id INT,organization_id INT,amount DECIMAL(10,2)); INSERT INTO organizations VALUES (1,'Organization C','Art and Culture','New York'); INSERT INTO expenses VALUES (1,1,3000); INSERT INTO expenses VALU... | SELECT o.name, SUM(e.amount) as total_expenses FROM organizations o INNER JOIN expenses e ON o.id = e.organization_id WHERE o.mission_area = 'Art and Culture' GROUP BY o.name ORDER BY o.name; |
Delete all records from the regulatory_compliance table where the compliance_date is older than 2 years | CREATE TABLE regulatory_compliance (compliance_id INT,regulation_name VARCHAR(50),compliance_date DATE); | DELETE FROM regulatory_compliance WHERE compliance_date < (CURRENT_DATE - INTERVAL '2' YEAR); |
What is the total number of marine protected areas in Southeast Asia and Oceania, and how many of them are in the Coral Triangle? | CREATE TABLE MARINE_PROTECTED_AREAS (NAME TEXT,LOCATION TEXT,REGION TEXT); INSERT INTO MARINE_PROTECTED_AREAS (NAME,LOCATION,REGION) VALUES ('Tubbataha Reefs Natural Park','Sulu Sea,Philippines','Southeast Asia'),('Komodo National Park','Indonesia','Southeast Asia'),('Great Barrier Reef Marine Park','Coral Sea,Australi... | SELECT (SELECT COUNT(*) FROM MARINE_PROTECTED_AREAS WHERE REGION IN ('Southeast Asia', 'Oceania')) AS TOTAL, (SELECT COUNT(*) FROM MARINE_PROTECTED_AREAS WHERE LOCATION LIKE '%Coral Triangle%') AS CORAL_TRIANGLE; |
What is the average age of offenders who have completed a restorative justice program in the state of California? | CREATE TABLE offenders (offender_id INT,age INT,state VARCHAR(20)); INSERT INTO offenders (offender_id,age,state) VALUES (1,34,'California'); INSERT INTO offenders (offender_id,age,state) VALUES (2,28,'California'); CREATE TABLE restorative_justice_programs (program_id INT,offender_id INT); INSERT INTO restorative_just... | SELECT AVG(offenders.age) FROM offenders JOIN restorative_justice_programs ON offenders.offender_id = restorative_justice_programs.offender_id WHERE offenders.state = 'California'; |
Delete records of clients who have taken part in Shariah-compliant finance in Malaysia, if their financial wellbeing score is below 6. | CREATE TABLE shariah_compliant_finance_my (client_id INT,financial_wellbeing_score INT,country VARCHAR(50)); INSERT INTO shariah_compliant_finance_my (client_id,financial_wellbeing_score,country) VALUES (1,7,'Malaysia'),(2,3,'Malaysia'),(3,6,'Malaysia'); | DELETE FROM shariah_compliant_finance_my WHERE country = 'Malaysia' AND financial_wellbeing_score < 6; |
How many hotels in Canada have adopted cloud-based PMS technology? | CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,country TEXT,pms_adoption BOOLEAN); | SELECT COUNT(*) FROM hotels WHERE country = 'Canada' AND pms_adoption = TRUE; |
What is the total revenue for each region in Q1 2022? | CREATE TABLE sales (sale_date DATE,region VARCHAR(255),revenue FLOAT); | SELECT region, SUM(revenue) AS total_revenue FROM sales WHERE sale_date BETWEEN '2022-01-01' AND '2022-03-31' GROUP BY region; |
Calculate the total cost of ingredients for all dishes in the appetizer category. | CREATE TABLE dishes (id INT,name TEXT,type TEXT,ingredients TEXT,cost FLOAT); | SELECT SUM(cost) FROM dishes WHERE type = 'appetizer'; |
What is the average capacity of shelters in 'east_asia' region? | CREATE TABLE region (region_id INT,name VARCHAR(255)); INSERT INTO region (region_id,name) VALUES (1,'east_asia'); CREATE TABLE shelter (shelter_id INT,name VARCHAR(255),region_id INT,capacity INT); INSERT INTO shelter (shelter_id,name,region_id,capacity) VALUES (1,'Shelter1',1,50),(2,'Shelter2',1,75); | SELECT AVG(capacity) FROM shelter WHERE region_id = (SELECT region_id FROM region WHERE name = 'east_asia'); |
What is the total billing amount per case outcome, grouped by attorney? | CREATE TABLE Attorneys (AttorneyID int,Name varchar(50),Region varchar(10)); INSERT INTO Attorneys VALUES (1,'Juanita Guerrero','Northeast'),(2,'Tatsuo Nakamura','Southwest'); CREATE TABLE Cases (CaseID int,AttorneyID int,Outcome varchar(10),BillingID int); INSERT INTO Cases VALUES (1,1,'Won',1),(2,1,'Lost',2),(3,2,'Wo... | SELECT A.Name, C.Outcome, SUM(B.Amount) as TotalBilling FROM Attorneys A JOIN Cases C ON A.AttorneyID = C.AttorneyID JOIN Billing B ON C.BillingID = B.BillingID GROUP BY A.Name, C.Outcome; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.