instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the total claim amount for auto insurance in California last year? | CREATE TABLE claims (id INT,state VARCHAR(2),policy_type VARCHAR(20),claim_amount DECIMAL(10,2),claim_date DATE); INSERT INTO claims (id,state,policy_type,claim_amount,claim_date) VALUES (1,'CA','Auto',2500,'2021-02-12'),(2,'CA','Auto',3500,'2021-06-23'),(3,'CA','Health',1000,'2021-09-14'); | SELECT SUM(claim_amount) FROM claims WHERE state = 'CA' AND policy_type = 'Auto' AND YEAR(claim_date) = 2021; |
Show the number of satellites in the satellite_database table, grouped by their orbit_type and order by the count in descending order, only showing the top 3 orbit types | CREATE TABLE satellite_database (id INT,name VARCHAR(50),type VARCHAR(50),orbit_type VARCHAR(50),country VARCHAR(50),launch_date DATE); | SELECT orbit_type, COUNT(*) as satellite_count FROM satellite_database GROUP BY orbit_type ORDER BY satellite_count DESC LIMIT 3; |
What is the policy count by age group? | CREATE TABLE policyholders (id INT,name TEXT,age INT,gender TEXT); INSERT INTO policyholders (id,name,age,gender) VALUES (1,'John Doe',35,'Male'); INSERT INTO policyholders (id,name,age,gender) VALUES (2,'Jane Smith',42,'Female'); INSERT INTO policyholders (id,name,age,gender) VALUES (3,'Bob Johnson',27,'Male'); INSERT... | SELECT FLOOR(policyholders.age / 10) * 10 AS age_group, COUNT(DISTINCT policyholders.id) AS policy_count FROM policyholders GROUP BY age_group; |
What is the total number of space missions per space agency for the last 10 years? | CREATE TABLE SpaceAgencies (Id INT,Name VARCHAR(50)); INSERT INTO SpaceAgencies (Id,Name) VALUES (1,'NASA'),(2,'ESA'),(3,'ROSCOSMOS'),(4,'CNSA'); CREATE TABLE SpaceMissions (Id INT,SpaceAgencyId INT,Year INT,Success BOOLEAN); INSERT INTO SpaceMissions (Id,SpaceAgencyId,Year,Success) VALUES (1,1,2012,TRUE),(2,1,2013,FAL... | SELECT sa.Name, SUM(CASE WHEN sm.Success THEN 1 ELSE 0 END) as Successes, SUM(CASE WHEN NOT sm.Success THEN 1 ELSE 0 END) as Failures FROM SpaceAgencies sa LEFT JOIN SpaceMissions sm ON sa.Id = sm.SpaceAgencyId AND sm.Year BETWEEN 2012 AND 2021 GROUP BY sa.Name; |
What is the number of AI safety incidents recorded for each region in the 'safety_incidents' table, grouped by incident type? | CREATE TABLE safety_incidents (region VARCHAR(20),incident_type VARCHAR(20),incident_count INT); INSERT INTO safety_incidents (region,incident_type,incident_count) VALUES ('North America','autonomous_vehicle',3),('North America','AI_assistant',1),('Europe','autonomous_vehicle',2); | SELECT region, incident_type, SUM(incident_count) as total_incidents FROM safety_incidents GROUP BY region, incident_type; |
How many public parks were there in rural areas in 2018 and 2019? | CREATE TABLE Park(Year INT,Location VARCHAR(10),Number INT); INSERT INTO Park VALUES (2017,'Urban',12),(2017,'Rural',8),(2018,'Urban',13),(2018,'Rural',9),(2019,'Urban',14),(2019,'Rural',10); | SELECT SUM(Number) FROM Park WHERE Year IN (2018, 2019) AND Location = 'Rural'; |
Which space agencies have discovered exoplanets? | CREATE TABLE exoplanet_discoveries (agency_id INT,exoplanet_name VARCHAR(50)); CREATE TABLE space_agencies (id INT,name VARCHAR(50)); | SELECT s.name FROM space_agencies s JOIN exoplanet_discoveries ed ON s.id = ed.agency_id; |
Calculate the total number of animals in the 'rehabilitation' and 'release' stages | CREATE TABLE animal_status (animal_id INT,status VARCHAR(10)); INSERT INTO animal_status (animal_id,status) VALUES (1,'rehabilitation'),(2,'release'),(3,'rehabilitation'); | SELECT SUM(status = 'rehabilitation' OR status = 'release') FROM animal_status; |
Show the total number of hospitals in 'CityG' and 'CityH' | CREATE TABLE Cities (CityName VARCHAR(20),NumHospitals INT); INSERT INTO Cities (CityName,NumHospitals) VALUES ('CityG',2),('CityH',3); | SELECT SUM(NumHospitals) FROM Cities WHERE CityName IN ('CityG', 'CityH'); |
Find the total investment for each rural infrastructure project in 'RuralDev' database. | CREATE TABLE rural_infrastructure (id INT,name VARCHAR(255),investment FLOAT); INSERT INTO rural_infrastructure (id,name,investment) VALUES (1,'Water Supply System',500000.00),(2,'Solar Farm',1000000.00),(3,'School',200000.00); | SELECT name, SUM(investment) FROM rural_infrastructure GROUP BY name; |
What is the total amount of in-game currency spent by all players in the game "Mystic Quest" in the past year? | CREATE TABLE spending (id INT,player_id INT,game VARCHAR(50),currency_spent FLOAT,spend_date DATETIME); INSERT INTO spending VALUES (1,1,'Mystic Quest',500.50,'2022-04-01 16:00:00'); INSERT INTO spending VALUES (2,2,'Mystic Quest',700.25,'2022-04-05 20:45:00'); | SELECT SUM(currency_spent) FROM spending WHERE game = 'Mystic Quest' AND spend_date >= DATE_SUB(NOW(), INTERVAL 1 YEAR); |
What are the unique IP addresses that have been associated with unsuccessful login attempts in the last 3 months? | CREATE TABLE login_attempts_time (id INT,ip_address VARCHAR(15),login_status VARCHAR(10),login_date DATE); INSERT INTO login_attempts_time (id,ip_address,login_status,login_date) VALUES (1,'192.168.1.100','successful','2022-01-01'),(2,'192.168.1.101','suspicious','2022-03-15'),(3,'192.168.1.102','successful','2022-02-2... | SELECT ip_address FROM login_attempts_time WHERE login_status = 'unsuccessful' AND login_date >= DATEADD(month, -3, GETDATE()) GROUP BY ip_address; |
What is the number of climate mitigation projects in South America funded by the Green Climate Fund? | CREATE TABLE green_climate_fund_2 (fund_id INT,project_name VARCHAR(100),country VARCHAR(50),sector VARCHAR(50),mitigation_flag BOOLEAN); INSERT INTO green_climate_fund_2 (fund_id,project_name,country,sector,mitigation_flag) VALUES (1,'Forest Conservation','Brazil','Land Use',TRUE); | SELECT COUNT(*) FROM green_climate_fund_2 WHERE country LIKE '%%south%am%' AND mitigation_flag = TRUE; |
Which models were used for generating text data in the 'text_data' table? | CREATE TABLE text_data (id INT,text VARCHAR(255),model VARCHAR(50)); | SELECT model FROM text_data WHERE text IS NOT NULL; |
What is the total revenue for each type of beauty product? | CREATE TABLE beauty_sales (product_type VARCHAR(255),revenue DECIMAL(10,2)); INSERT INTO beauty_sales (product_type,revenue) VALUES ('Skincare',7500.00),('Makeup',5000.00),('Haircare',3000.00),('Bodycare',4000.00); | SELECT product_type, SUM(revenue) as total_revenue FROM beauty_sales GROUP BY product_type; |
Get the names of all climate mitigation projects in 'Oceania' that started between 2000 and 2005. | CREATE TABLE climate_mitigation (project_id INT,project_name VARCHAR(255),location VARCHAR(255),start_date DATE); | SELECT project_name FROM climate_mitigation WHERE location = 'Oceania' AND start_date BETWEEN '2000-01-01' AND '2005-12-31'; |
What is the sum of local economic impact in New York and Berlin? | CREATE TABLE local_impact (id INT,city VARCHAR(50),value INT); INSERT INTO local_impact (id,city,value) VALUES (1,'New York',1000),(2,'Berlin',1500),(3,'Tokyo',800); | SELECT SUM(value) FROM local_impact WHERE city IN ('New York', 'Berlin'); |
What is the total number of volunteers in 'volunteers' table from the city of Los Angeles? | CREATE TABLE volunteers (id INT,name TEXT,city TEXT,volunteer_hours INT); | SELECT SUM(volunteer_hours) FROM volunteers WHERE city = 'Los Angeles'; |
List the teams and the number of games they have won in the "nba_games" table | CREATE TABLE nba_games (team VARCHAR(255),won INTEGER); | SELECT team, SUM(won) as total_wins FROM nba_games GROUP BY team; |
What is the number of tourists visiting Paris from the United States? | CREATE TABLE paris_visitors (id INT,name VARCHAR(50),age INT,nationality VARCHAR(50)); INSERT INTO paris_visitors (id,name,age,nationality) VALUES (1,'James Brown',45,'American'),(2,'Pierre Dupont',30,'French'); | SELECT COUNT(*) FROM paris_visitors WHERE nationality = 'American'; |
Retrieve the names and IDs of all animals that do not have a community education program associated | CREATE TABLE education_programs (id INT,name VARCHAR(255),animal_id INT); INSERT INTO education_programs (id,name,animal_id) VALUES (1,'Wildlife Wonders',2),(2,'Animal Buddies',3),(3,'Conservation Champions',4); CREATE TABLE animals (id INT,name VARCHAR(20),species VARCHAR(20)); INSERT INTO animals (id,name,species) VA... | SELECT a.id, a.name FROM animals a LEFT JOIN education_programs ep ON a.id = ep.animal_id WHERE ep.animal_id IS NULL; |
What is the average water consumption per day for the month of June for water treatment plants in Utah in 2021? | CREATE TABLE water_treatment_plant (plant_id INT,state VARCHAR(50),year INT,month INT,day INT,water_consumption FLOAT); INSERT INTO water_treatment_plant (plant_id,state,year,month,day,water_consumption) VALUES (5,'Utah',2021,6,1,12345.6),(6,'Utah',2021,6,2,23456.7),(7,'Utah',2021,6,3,34567.8); | SELECT plant_id, AVG(water_consumption) as avg_water_consumption FROM water_treatment_plant WHERE state = 'Utah' AND year = 2021 AND month = 6 GROUP BY plant_id; |
Update the depth of the 'Tonga Trench' in the ocean_floor_mapping table to 10900. | CREATE TABLE ocean_floor_mapping (location TEXT,depth INTEGER); INSERT INTO ocean_floor_mapping (location,depth) VALUES ('Challenger Deep',10994),('Mariana Trench',10972),('Tonga Trench',10823); | UPDATE ocean_floor_mapping SET depth = 10900 WHERE location = 'Tonga Trench'; |
What is the total revenue generated by OTAs in 'North America' in the year 2022? | CREATE TABLE ota_revenue_north_america (ota TEXT,country TEXT,revenue FLOAT,year INT); INSERT INTO ota_revenue_north_america (ota,country,revenue,year) VALUES ('Expedia','USA',1200000,2022),('Booking.com','Canada',1000000,2022),('Agoda','Mexico',800000,2022),('MakeMyTrip','USA',900000,2022),('Despegar','Canada',1100000... | SELECT SUM(revenue) FROM ota_revenue_north_america WHERE country IN ('USA', 'Canada', 'Mexico') AND year = 2022; |
Identify the top 3 'Education' causes with the highest average donation amount in Q1 2023, excluding anonymous donors. | CREATE TABLE donations (donation_id INT,donor_id INT,cause VARCHAR(255),donation_amount DECIMAL,is_anonymous BOOLEAN); | SELECT c.name, AVG(d.donation_amount) as avg_donation FROM donations d JOIN causes c ON d.cause = c.name WHERE d.donation_date BETWEEN '2023-01-01' AND '2023-03-31' AND c.category = 'Education' AND d.is_anonymous = FALSE GROUP BY c.name ORDER BY avg_donation DESC LIMIT 3; |
Show the average credit limit of all credit cards owned by customers from historically underrepresented communities. | CREATE TABLE Customers (CustomerID int,Name varchar(50),Community varchar(50)); INSERT INTO Customers (CustomerID,Name,Community) VALUES (1,'Jamal Johnson','Historically Underrepresented Community'); CREATE TABLE CreditCards (CardID int,CustomerID int,CreditLimit decimal(10,2)); INSERT INTO CreditCards (CardID,Customer... | SELECT AVG(CC.CreditLimit) FROM CreditCards CC INNER JOIN Customers C ON CC.CustomerID = C.CustomerID WHERE C.Community = 'Historically Underrepresented Community'; |
Delete all records in the "Fish" table where the "Species" is "Anglerfish" | CREATE TABLE Fish (Id INT,Species VARCHAR(20),Population INT); | DELETE FROM Fish WHERE Species = 'Anglerfish'; |
What is the total fare collected by each vehicle type in the last month? | CREATE TABLE Fares (FareID INT,FareAmount DECIMAL(5,2),VehicleTypeID INT,CollectionDate DATE); INSERT INTO Fares (FareID,FareAmount,VehicleTypeID,CollectionDate) VALUES (1,2.50,1,'2020-01-01'),(2,3.00,1,'2020-01-01'),(3,2.75,2,'2019-12-31'),(4,3.25,3,'2019-12-31'); CREATE TABLE VehicleTypes (VehicleTypeID INT,VehicleTy... | SELECT VehicleType, SUM(FareAmount) FROM Fares INNER JOIN VehicleTypes ON Fares.VehicleTypeID = VehicleTypes.VehicleTypeID WHERE CollectionDate >= DATEADD(month, -1, GETDATE()) GROUP BY VehicleType; |
Calculate the average environmental impact score for each location, excluding records with missing environmental impact scores. | CREATE TABLE mining_sites (site_id INT,site_name TEXT,location TEXT); INSERT INTO mining_sites (site_id,site_name,location) VALUES (1,'Site A','Country X'),(2,'Site B','Country Y'),(5,'Site E','Country Z'); CREATE TABLE environmental_impact (site_id INT,site_name TEXT,ei_score FLOAT); INSERT INTO environmental_impact (... | SELECT mining_sites.location, AVG(environmental_impact.ei_score) AS avg_ei_score FROM mining_sites INNER JOIN environmental_impact ON mining_sites.site_id = environmental_impact.site_id GROUP BY mining_sites.location; |
What is the total number of green building certifications awarded in Sydney, Australia, for each certification type? | CREATE TABLE certifications_sydney (id INT,city VARCHAR(20),certification_name VARCHAR(20),year INT); INSERT INTO certifications_sydney (id,city,certification_name,year) VALUES (1,'Sydney','LEED',2018),(2,'Sydney','BREEAM',2019),(3,'Sydney','WELL',2020),(4,'Sydney','Green Star',2021); | SELECT certification_name, COUNT(*) FROM certifications_sydney WHERE city = 'Sydney' GROUP BY certification_name; |
What is the total funding received by startups founded in Asia in each quarter of 2021? | CREATE TABLE startups(id INT,name TEXT,country TEXT,funding FLOAT,founding_date DATE); INSERT INTO startups(id,name,country,funding,founding_date) VALUES (1,'StartupA','China',500000,'2021-01-01'),(2,'StartupB','Japan',750000,'2021-02-15'),(3,'StartupC','China',250000,'2021-03-30'),(4,'StartupD','India',300000,'2021-04... | SELECT EXTRACT(QUARTER FROM founding_date) as quarter, country, SUM(funding) FROM startups WHERE country IN ('China', 'Japan', 'India', 'South Korea') GROUP BY quarter, country; |
How many incidents were recorded for vessels with the 'FV' prefix in the first quarter of 2021? | CREATE TABLE VesselIncidents (vessel_id VARCHAR(5),incident_date DATE); INSERT INTO VesselIncidents (vessel_id,incident_date) VALUES ('FV1','2021-01-05'),('FV2','2021-03-12'),('SV3','2021-02-20'); | SELECT COUNT(*) FROM VesselIncidents WHERE vessel_id LIKE 'FV%' AND incident_date BETWEEN '2021-01-01' AND '2021-03-31'; |
Find the circular economy initiatives by organization and year? | CREATE TABLE circular_economy_initiatives(organization VARCHAR(255),initiative_year INT,initiative_type VARCHAR(255)); INSERT INTO circular_economy_initiatives VALUES ('OrgA',2020,'Composting'); | SELECT organization, initiative_year, initiative_type FROM circular_economy_initiatives ORDER BY initiative_year, organization |
What is the total value of defense contracts with the United States government, for the last 12 months? | CREATE TABLE Contract_Data (contract_id INT,contract_value FLOAT,contract_date DATE,contract_region VARCHAR(50)); | SELECT contract_region, SUM(contract_value) as total_contract_value FROM Contract_Data WHERE contract_region = 'United States government' AND contract_date >= DATEADD(year, -1, GETDATE()) GROUP BY contract_region; |
What is the total number of community education programs for each type of animal? | CREATE TABLE animal_population (id INT,type VARCHAR(50),species VARCHAR(50),animals INT); INSERT INTO animal_population (id,type,species,animals) VALUES (1,'Forest','Deer',200),(2,'Forest','Bear',100),(3,'Savannah','Lion',300),(4,'Savannah','Gazelle',150),(5,'Wetlands','Alligator',150),(6,'Wetlands','Turtle',100),(7,'W... | SELECT a.species, SUM(b.programs) FROM animal_population a JOIN education b ON a.species = b.species GROUP BY a.species; |
Insert records for 4 arctic plants into the "plants" table | CREATE TABLE plants (id INT PRIMARY KEY,name VARCHAR(100),family VARCHAR(100),region VARCHAR(100),population INT); | WITH plants_data AS (VALUES (1, 'Arctic Willow', 'Salicaceae', 'Tundra', 5000), (2, 'Arctic Poppy', 'Papaveraceae', 'Arctic Tundra', 7000), (3, 'Diamond-leaf Willow', 'Salicaceae', 'Alpine Tundra', 4000), (4, 'Arctic Cotton', 'Malvaceae', 'Tundra', 6000)) INSERT INTO plants SELECT * FROM plants_data; |
What is the total revenue generated by restaurants in each city? | CREATE TABLE restaurants (id INT,name TEXT,city TEXT,revenue FLOAT); INSERT INTO restaurants (id,name,city,revenue) VALUES (1,'Restaurant A','New York',50000.00),(2,'Restaurant B','Los Angeles',45000.00),(3,'Restaurant C','Chicago',60000.00),(4,'Restaurant D','New York',75000.00),(5,'Restaurant E','Los Angeles',80000.0... | SELECT city, SUM(revenue) FROM restaurants GROUP BY city; |
What is the maximum environmental impact score in the last 3 years? | CREATE TABLE environment (id INT,date DATE,score INT); INSERT INTO environment (id,date,score) VALUES (1,'2020-01-01',80),(2,'2020-02-01',85),(3,'2021-01-01',90),(4,'2021-02-01',95),(5,'2022-01-01',100); | SELECT MAX(e.score) AS max_impact_score FROM environment e WHERE e.date >= DATE_SUB(CURDATE(), INTERVAL 3 YEAR); |
What is the difference in productivity between workers in the 'mining' and 'oil' industries, ordered by the productivity difference in descending order? | CREATE TABLE Productivity (Id INT,Worker VARCHAR(50),Industry VARCHAR(50),Productivity FLOAT); INSERT INTO Productivity (Id,Worker,Industry,Productivity) VALUES (1,'John Doe','mining',10.5); INSERT INTO Productivity (Id,Worker,Industry,Productivity) VALUES (2,'Jane Smith','mining',9.8); INSERT INTO Productivity (Id,Wor... | SELECT a.Industry as Industry_1, b.Industry as Industry_2, ABS(a.Productivity - b.Productivity) as Productivity_Difference FROM Productivity a, Productivity b WHERE a.Industry = 'mining' AND b.Industry = 'oil' ORDER BY Productivity_Difference DESC; |
What was the average number of citizens participating in public meetings in the state of New York in 2019? | CREATE TABLE new_york_citizens (id INT PRIMARY KEY,year INT,num_citizens INT); INSERT INTO new_york_citizens (id,year,num_citizens) VALUES (1,2019,19000000); INSERT INTO meetings (id,state,year,num_participants) VALUES (1,'New York',2019,5000); INSERT INTO meetings (id,state,year,num_participants) VALUES (2,'New York',... | SELECT AVG(meetings.num_participants) FROM meetings INNER JOIN new_york_citizens ON meetings.year = new_york_citizens.year WHERE meetings.state = 'New York' AND meetings.year = 2019; |
How many unique countries and languages are represented in the media_data table? | CREATE TABLE media_data (id INT,content TEXT,country TEXT,language TEXT); INSERT INTO media_data (id,content,country,language) VALUES (1,'Sample content 1','United States','English'); INSERT INTO media_data (id,content,country,language) VALUES (2,'Sample content 2','Canada','French'); INSERT INTO media_data (id,content... | SELECT COUNT(DISTINCT country) + COUNT(DISTINCT language) FROM media_data; |
What is the total production quantity of dysprosium in 2018 for mines located in China or the United States? | CREATE TABLE mines (id INT,name TEXT,location TEXT,production_quantity INT,year INT,element TEXT); INSERT INTO mines (id,name,location,production_quantity,year,element) VALUES (1,'Baotou Steel Rare-Earth','China',2500,2018,'dysprosium'),(2,'Mountain Pass Rare Earth Mine','United States',1500,2018,'dysprosium'); | SELECT SUM(production_quantity) FROM mines WHERE (location = 'China' OR location = 'United States') AND year = 2018 AND element = 'dysprosium'; |
Calculate the total funding for neurological disorder related projects. | CREATE SCHEMA if not exists genetic_research;CREATE TABLE if not exists genetic_research.projects(id INT,name TEXT,lead_researcher TEXT,disease_category TEXT,funding FLOAT);INSERT INTO genetic_research.projects (id,name,lead_researcher,disease_category,funding) VALUES (1,'ProjectX','Dr. Jane Smith','Cancer',2000000),(2... | SELECT SUM(funding) FROM genetic_research.projects WHERE disease_category = 'Neurological Disorders'; |
Show the number of players who have participated in esports events for 'Valorant' or 'Rainbow Six Siege' | CREATE TABLE EsportsEvents (PlayerID INT,Game VARCHAR(20),Event VARCHAR(20)); INSERT INTO EsportsEvents (PlayerID,Game,Event) VALUES (1,'Valorant','First Strike'),(2,'Rainbow Six Siege','Six Invitational'),(3,'Fortnite','World Cup'),(4,'Valorant','Masters Reykjavik'),(5,'Rainbow Six Siege','Invitational'),(6,'Valorant'... | SELECT COUNT(DISTINCT PlayerID) FROM EsportsEvents WHERE Game IN ('Valorant', 'Rainbow Six Siege') |
Find the policy types with more than 10% of claims denied in the state of California. | CREATE TABLE Claim_Decisions (Policy_Type VARCHAR(20),State VARCHAR(20),Decision ENUM('Approved','Denied')); INSERT INTO Claim_Decisions (Policy_Type,State,Decision) VALUES ('Life','California','Approved'),('Health','California','Denied'),('Auto','California','Approved'),('Life','California','Denied'),('Health','Califo... | SELECT Policy_Type FROM Claim_Decisions WHERE State = 'California' AND Decision = 'Denied' GROUP BY Policy_Type HAVING COUNT(*) / (SELECT COUNT(*) FROM Claim_Decisions WHERE State = 'California') > 0.10; |
List military equipment maintenance requests with a priority level higher than 3, grouped by equipment type, in descending order of total maintenance hours requested. | CREATE TABLE equipment_maintenance (request_id INT,priority INT,equipment_type VARCHAR(50),maintenance_hours FLOAT); INSERT INTO equipment_maintenance (request_id,priority,equipment_type,maintenance_hours) VALUES (1,4,'M1 Abrams',10),(2,5,'UH-60 Black Hawk',15),(3,3,'AH-64 Apache',8); | SELECT equipment_type, SUM(maintenance_hours) as total_maintenance_hours FROM equipment_maintenance WHERE priority > 3 GROUP BY equipment_type ORDER BY total_maintenance_hours DESC; |
What is the average age of patients in the 'rural_hospital_5' table? | CREATE TABLE rural_hospital_5 (patient_id INT,age INT,gender VARCHAR(10)); INSERT INTO rural_hospital_5 (patient_id,age,gender) VALUES (1,70,'Male'),(2,45,'Female'),(3,55,'Male'),(4,60,'Female'),(5,35,'Male'),(6,50,'Female'),(7,65,'Male'); | SELECT AVG(age) FROM rural_hospital_5; |
What is the total number of cybersecurity incidents reported by Latinx-owned businesses in the past year, broken down by incident type? | CREATE TABLE cybersecurity_incidents (id INT,incident_type VARCHAR(255),incident_date DATE,business_id INT,business_owner_ethnicity VARCHAR(255)); INSERT INTO cybersecurity_incidents (id,incident_type,incident_date,business_id,business_owner_ethnicity) VALUES (1,'Data Breach','2022-01-01',1,'Latinx'); INSERT INTO cyber... | SELECT incident_type, COUNT(*) as num_incidents FROM cybersecurity_incidents WHERE business_owner_ethnicity = 'Latinx' AND incident_date >= DATEADD(year, -1, GETDATE()) GROUP BY incident_type; |
How many patients have been treated for anxiety in Hawaii? | CREATE TABLE condition_records (patient_id INT,condition VARCHAR(50)); INSERT INTO condition_records (patient_id,condition) VALUES (1,'Depression'),(2,'Anxiety'),(3,'PTSD'),(4,'Anxiety'),(5,'Anxiety'),(6,'Bipolar Disorder'),(7,'Depression'),(8,'Anxiety'); CREATE TABLE patient_location (patient_id INT,location VARCHAR(5... | SELECT COUNT(DISTINCT patient_id) FROM condition_records JOIN patient_location ON condition_records.patient_id = patient_location.patient_id WHERE condition = 'Anxiety' AND location = 'Hawaii'; |
What is the safety score distribution for each AI model type, ordered by average safety score in descending order? | CREATE TABLE safety_scores (model_id INT,model_type VARCHAR(20),safety_score INT); INSERT INTO safety_scores (model_id,model_type,safety_score) VALUES (1,'Generative',80),(2,'Transformer',85),(3,'Reinforcement',70),(4,'Generative2',82); | SELECT model_type, AVG(safety_score) as avg_safety_score, STDDEV(safety_score) as stddev_safety_score FROM safety_scores GROUP BY model_type ORDER BY avg_safety_score DESC; |
Which exhibition had the highest average visitor rating? | CREATE TABLE ratings (id INT,exhibition_id INT,rating INT); INSERT INTO ratings (id,exhibition_id,rating) VALUES (1,1,8),(2,1,9),(3,1,7),(4,2,5),(5,2,6),(6,2,6),(7,3,8),(8,3,9),(9,3,10); CREATE TABLE exhibitions (id INT,name VARCHAR(255),type VARCHAR(255)); INSERT INTO exhibitions (id,name,type) VALUES (1,'Impressionis... | SELECT e.name, AVG(r.rating) AS avg_rating FROM ratings r JOIN exhibitions e ON r.exhibition_id = e.id GROUP BY r.exhibition_id ORDER BY avg_rating DESC LIMIT 1; |
How many mental health awareness campaigns have been launched in Africa? | CREATE TABLE campaigns (id INT,region VARCHAR(255)); INSERT INTO campaigns (id,region) VALUES (1,'Africa'),(2,'North America'),(3,'Europe'); | SELECT COUNT(*) FROM campaigns WHERE region = 'Africa'; |
What is the average monthly price difference between Basic and Premium memberships? | CREATE TABLE gym_memberships (id INT,member_name VARCHAR(50),start_date DATE,end_date DATE,membership_type VARCHAR(50),price DECIMAL(5,2)); | SELECT AVG(price_diff) AS avg_monthly_price_difference FROM (SELECT DATEDIFF(end_date, start_date) / 12 AS months_between, AVG(CASE WHEN membership_type = 'Premium' THEN price ELSE 0 END) - AVG(CASE WHEN membership_type = 'Basic' THEN price ELSE 0 END) AS price_diff FROM gym_memberships WHERE start_date BETWEEN '2022-0... |
What was the maximum number of likes on a post containing the hashtag "#vegan" in the United Kingdom, in the past month? | CREATE TABLE posts (id INT,country VARCHAR(255),likes INT,created_at TIMESTAMP); | SELECT MAX(likes) FROM posts WHERE country = 'United Kingdom' AND hashtags LIKE '%#vegan%' AND created_at > NOW() - INTERVAL '1 month'; |
List the average salary for each job title in the 'UnionMembers' table | CREATE TABLE UnionMembers (id INT,job_title VARCHAR(50),salary FLOAT); INSERT INTO UnionMembers (id,job_title,salary) VALUES (1,'Manager',70000.0),(2,'Assistant Manager',60000.0),(3,'Manager',75000.0); | SELECT job_title, AVG(salary) as avg_salary FROM UnionMembers GROUP BY job_title; |
Determine the total cost of inventory for non-dairy items. | CREATE TABLE inventory(inventory_id INT,item_id INT,quantity INT,cost_price DECIMAL); CREATE TABLE menu_items(menu_item_id INT,name TEXT,type TEXT,is_dairy BOOLEAN,price DECIMAL); | SELECT SUM(inventory.quantity * inventory.cost_price) FROM inventory JOIN menu_items ON inventory.item_id = menu_items.menu_item_id WHERE is_dairy = FALSE; |
What is the percentage of the population that has a chronic condition by age group? | CREATE TABLE population (id INT,age_group VARCHAR(255),chronic_condition BOOLEAN); INSERT INTO population VALUES (1,'0-10',false),(2,'11-20',false),(3,'21-30',true); | SELECT age_group, (COUNT(*) FILTER (WHERE chronic_condition) * 100.0 / COUNT(*)) AS pct_chronic_condition FROM population GROUP BY age_group; |
List the auto shows with more than 500 exhibitors | CREATE TABLE auto_shows (id INT,show_name VARCHAR(50),num_exhibitors INT,year INT); INSERT INTO auto_shows (id,show_name,num_exhibitors,year) VALUES (1,'North American International Auto Show',700,2022),(2,'Geneva International Motor Show',650,2022),(3,'Shanghai International Auto Show',800,2022),(4,'Tokyo Motor Show',... | SELECT show_name, year FROM auto_shows WHERE num_exhibitors > 500; |
What is the average number of building permits issued per month in Florida? | CREATE TABLE Permits (permit_id INT,state VARCHAR(255),issue_date DATE); INSERT INTO Permits (permit_id,state,issue_date) VALUES (1,'Florida','2022-01-01'),(2,'Florida','2022-02-01'); | SELECT AVG(EXTRACT(MONTH FROM issue_date)) FROM Permits WHERE state = 'Florida'; |
What is the total biomass of all deep-sea creatures in the Arctic Ocean? | CREATE TABLE deep_sea_creatures (species TEXT,biomass_kg FLOAT,ocean TEXT); INSERT INTO deep_sea_creatures (species,biomass_kg,ocean) VALUES ('Giant Squid',150.0,'Atlantic Ocean'),('Anglerfish',50.0,'Pacific Ocean'),('Northern Bottlenose Whale',30000.0,'Arctic Ocean'); | SELECT SUM(biomass_kg) FROM deep_sea_creatures WHERE ocean = 'Arctic Ocean'; |
What is the average song_length in the reggae genre? | CREATE TABLE genres (genre VARCHAR(10),song_id INT,song_length FLOAT); INSERT INTO genres (genre,song_id,song_length) VALUES ('reggae',16,210.5),('reggae',17,225.8),('reggae',18,195.4); | SELECT AVG(song_length) FROM genres WHERE genre = 'reggae'; |
Which heritage sites have less than 50 visitors per month? | CREATE TABLE HeritageSite (name VARCHAR(255),visitors_per_month INT); INSERT INTO HeritageSite (name,visitors_per_month) VALUES ('Tikal',45),('Machu Picchu',30),('Petra',40); | SELECT name FROM HeritageSite WHERE visitors_per_month < 50; |
What is the average depth of all marine protected areas (MPAs) that are deeper than 1000 meters? | CREATE TABLE mpa (id INT,name TEXT,depth FLOAT); INSERT INTO mpa (id,name,depth) VALUES (1,'Great Barrier Reef',344); INSERT INTO mpa (id,name,depth) VALUES (2,'Sargasso Sea',1500); | SELECT AVG(depth) FROM mpa WHERE depth > 1000; |
Identify the top 2 most popular sustainable fabric types, based on quantity used, in the 'production' table. | CREATE TABLE production (production_id INTEGER,fabric_type TEXT,sustainability_rating INTEGER,quantity INTEGER); INSERT INTO production (production_id,fabric_type,sustainability_rating,quantity) VALUES (1,'cotton',10,500),(2,'polyester',5,300),(3,'hemp',15,200),(4,'tencel',12,400); | SELECT fabric_type, SUM(quantity) FROM production WHERE sustainability_rating >= 10 GROUP BY fabric_type ORDER BY SUM(quantity) DESC LIMIT 2; |
What is the total fare collected for each day of the week? | CREATE TABLE trip (trip_id INT,fare DECIMAL(10,2),trip_date DATE); INSERT INTO trip (trip_id,fare,trip_date) VALUES (1,2.00,'2022-01-01'),(2,3.00,'2022-01-02'),(3,4.00,'2022-02-01'),(4,5.00,'2022-02-02'); | SELECT EXTRACT(DOW FROM trip_date) AS day_of_week, SUM(fare) AS total_fare FROM trip GROUP BY day_of_week; |
What is the total number of mental health parity laws by region? | CREATE TABLE Regions (RegionID INT,RegionName VARCHAR(50)); INSERT INTO Regions (RegionID,RegionName) VALUES (1,'Northeast'),(2,'Southeast'),(3,'Midwest'),(4,'West');CREATE TABLE MentalHealthParity (MHPId INT,Law VARCHAR(255),State VARCHAR(50),RegionID INT); INSERT INTO MentalHealthParity (MHPId,Law,State,RegionID) VAL... | SELECT R.RegionName, COUNT(MHP.MHPId) AS TotalLaws FROM Regions R INNER JOIN MentalHealthParity MHP ON R.RegionID = MHP.RegionID GROUP BY R.RegionName; |
What is the most popular genre of music in Japan in Q3 2022? | CREATE TABLE MusicGenrePreference (country VARCHAR(255),quarter INT,genre VARCHAR(255),popularity INT); | SELECT genre, SUM(popularity) AS total_popularity FROM MusicGenrePreference WHERE country = 'Japan' AND quarter = 3 GROUP BY genre ORDER BY total_popularity DESC LIMIT 1; |
Which art programs have the highest number of repeat visitors? | CREATE TABLE Visits (visit_id INT,visitor_id INT,event_id INT,visit_date DATE); CREATE TABLE Visitors (visitor_id INT,name VARCHAR(255),birthdate DATE); CREATE TABLE Events (event_id INT,name VARCHAR(255),date DATE,program_id INT); | SELECT E.name, COUNT(DISTINCT V.visitor_id) AS repeat_visitors FROM Visits V JOIN Visitors VV ON V.visitor_id = VV.visitor_id JOIN Events E ON V.event_id = E.event_id GROUP BY E.name ORDER BY repeat_visitors DESC LIMIT 1; |
Find the top 3 teams with the highest ticket revenue in the ticket_sales table. | CREATE TABLE ticket_sales (id INT,team VARCHAR(50),conference VARCHAR(50),tickets_sold INT,revenue FLOAT); | SELECT team, SUM(revenue) AS total_revenue FROM ticket_sales GROUP BY team ORDER BY total_revenue DESC LIMIT 3; |
How many paper recycling facilities exist in the state of Texas, USA, as of 2022? | CREATE TABLE recycling_facilities (name VARCHAR(50),state VARCHAR(20),type VARCHAR(20),capacity INT); INSERT INTO recycling_facilities (name,state,type,capacity) VALUES ('Paper Recycling','Texas','paper',4000),('Eco-Friendly','Texas','plastic',2000); | SELECT COUNT(*) FROM recycling_facilities WHERE state = 'Texas' AND type = 'paper'; |
How many satellites were deployed per year by country? | CREATE SCHEMA Satellite;CREATE TABLE Satellite.SatelliteDeployment (country VARCHAR(50),year INT,num_satellites INT);INSERT INTO Satellite.SatelliteDeployment (country,year,num_satellites) VALUES ('USA',2010,100),('China',2010,50),('Russia',2010,40),('India',2010,30),('USA',2011,120),('China',2011,60),('Russia',2011,45... | SELECT country, year, SUM(num_satellites) AS total_satellites FROM Satellite.SatelliteDeployment GROUP BY country, year; |
What is the distribution of agricultural innovation metrics for female and male farmers in South America, partitioned by country and ordered by the number of farmers? | CREATE TABLE Farmers_SA (FarmerID INT,Country VARCHAR(20),Gender VARCHAR(10),Metric FLOAT); INSERT INTO Farmers_SA (FarmerID,Country,Gender,Metric) VALUES (1,'Argentina','Male',4.1),(2,'Brazil','Female',3.5),(3,'Chile','Male',4.6),(4,'Colombia','Female',3.9),(5,'Peru','Male',4.7),(6,'Uruguay','Female',3.7),(7,'Argentin... | SELECT Country, Gender, COUNT(*) as Num_Farmers FROM Farmers_SA WHERE Country IN ('Argentina', 'Brazil', 'Chile', 'Colombia', 'Peru', 'Uruguay') GROUP BY Country, Gender ORDER BY Num_Farmers DESC; |
What is the average rating of products that use at least one vegan ingredient? | CREATE TABLE ingredient (id INT PRIMARY KEY,name VARCHAR(100),vegan BOOLEAN);CREATE TABLE product_ingredient (product_id INT,ingredient_id INT,FOREIGN KEY (product_id) REFERENCES product(id),FOREIGN KEY (ingredient_id) REFERENCES ingredient(id));CREATE TABLE product_review (product_id INT,rating INT); | SELECT AVG(pr.rating) as avg_rating FROM product_ingredient pi JOIN product p ON pi.product_id = p.id JOIN product_review pr ON p.id = pr.product_id JOIN ingredient i ON pi.ingredient_id = i.id WHERE i.vegan = TRUE; |
What is the total amount of money spent on education by each state in the past fiscal year? | CREATE TABLE education_spending (state VARCHAR(255),amount FLOAT,fiscal_year INT); INSERT INTO education_spending (state,amount,fiscal_year) VALUES ('California',100000,2021),('California',120000,2022),('Texas',80000,2021),('Texas',90000,2022),('New York',150000,2021),('New York',160000,2022); | SELECT s1.state, SUM(s1.amount) as total_spending FROM education_spending s1 WHERE s1.fiscal_year = 2021 GROUP BY s1.state; |
add a new column named 'year' to sales_data table with the sale year | CREATE TABLE sales_data (id INT,equipment_name TEXT,sale_date DATE,quantity INT,total_cost FLOAT); | ALTER TABLE sales_data ADD COLUMN year INT; UPDATE sales_data SET year = YEAR(sale_date); |
How many students are enrolled in the Computer Science department? | CREATE TABLE enrollment (id INT,student_id INT,department VARCHAR(50)); INSERT INTO enrollment (id,student_id,department) VALUES (1,101,'Computer Science'),(2,102,'Computer Science'),(3,103,'Electrical Engineering'); | SELECT COUNT(DISTINCT student_id) FROM enrollment WHERE department = 'Computer Science'; |
What is the minimum number of volunteers per program, for programs with at least one volunteer? | CREATE TABLE programs (id INT,name TEXT);CREATE TABLE volunteers (id INT,program_id INT,number INTEGER); INSERT INTO programs (id,name) VALUES (1,'Program A'),(2,'Program B'),(3,'Program C'),(4,'Program D'); INSERT INTO volunteers (id,program_id,number) VALUES (1,1,35),(2,1,75),(3,2,100),(4,3,20),(5,4,75),(6,4,100); | SELECT programs.name, MIN(volunteers.number) FROM programs INNER JOIN volunteers ON programs.id = volunteers.program_id GROUP BY programs.id HAVING MIN(volunteers.number) > 0; |
What is the total number of units of organic food items served in all cafeterias in the Midwest? | CREATE TABLE Cafeteria (CafeteriaID INT,Location VARCHAR(20),OrganicMeal BOOLEAN); INSERT INTO Cafeteria VALUES (1,'Midwest',true),(2,'Northeast',false); CREATE TABLE Meal (MealID INT,CaloricContent INT,MealType VARCHAR(10),Organic BOOLEAN); INSERT INTO Meal VALUES (1,500,'Organic',true),(2,700,'Non-Organic',false); CR... | SELECT SUM(Units) FROM CafeteriaMeal cm JOIN Meal m ON cm.MealID = m.MealID JOIN Cafeteria c ON cm.CafeteriaID = c.CafeteriaID WHERE m.Organic = true AND c.Location = 'Midwest'; |
List all evidence-based policy making data sets that are not present in both 'city' and 'county' schemas. | CREATE SCHEMA city; CREATE SCHEMA county; CREATE TABLE city.policy_data (id INT,name VARCHAR(255),is_evidence_based BOOLEAN); CREATE TABLE county.policy_data (id INT,name VARCHAR(255),is_evidence_based BOOLEAN); INSERT INTO city.policy_data (id,name,is_evidence_based) VALUES (1,'transportation',true),(2,'housing',false... | SELECT * FROM ( (SELECT * FROM city.policy_data WHERE is_evidence_based = true) EXCEPT (SELECT * FROM county.policy_data WHERE is_evidence_based = true) ) AS excepted_data; |
What is the total number of dams in the state of Washington? | CREATE TABLE Dams (id INT,name TEXT,state TEXT,height FLOAT); INSERT INTO Dams (id,name,state,height) VALUES (1,'Grand Coulee Dam','Washington',168.0); INSERT INTO Dams (id,name,state,height) VALUES (2,'Hoover Dam','Nevada',221.0); | SELECT COUNT(*) FROM Dams WHERE state = 'Washington' |
What is the number of workers involved in fair trade and living wage practices? | CREATE TABLE labor_practices (id INT,supplier VARCHAR(255),practice VARCHAR(255),num_workers INT); INSERT INTO labor_practices (id,supplier,practice,num_workers) VALUES (1,'Supplier A','Fair Trade',50),(2,'Supplier B','Living Wage',75),(3,'Supplier C','Fair Trade',100),(4,'Supplier D','Living Wage',125),(5,'Supplier E'... | SELECT practice, SUM(num_workers) FROM labor_practices WHERE practice IN ('Fair Trade', 'Living Wage') GROUP BY practice; |
List clients with more than 10 transactions in the 'Asia' region's 'Technology' sector. | CREATE TABLE client (client_id INT,client_name VARCHAR(50),region VARCHAR(50)); CREATE TABLE transaction (transaction_id INT,client_id INT,sector VARCHAR(50),amount DECIMAL(10,2)); INSERT INTO client (client_id,client_name,region) VALUES (1,'John Lee','Asia'),(2,'Sophia Chen','Asia'),(3,'Mateo Lopez','Europe'); INSERT ... | SELECT client_name FROM client c JOIN transaction t ON c.client_id = t.client_id WHERE c.region = 'Asia' AND sector = 'Technology' GROUP BY client_id HAVING COUNT(*) > 10; |
Insert new humidity data for field ID 88888 with the given values. | CREATE TABLE field_humidity_2 (field_id INT,date DATE,humidity DECIMAL(5,2)); INSERT INTO field_humidity_2 (field_id,date,humidity) VALUES (88888,'2022-03-01',50.0),(88888,'2022-03-02',52.0),(88888,'2022-03-03',48.0); | INSERT INTO field_humidity_2 (field_id, date, humidity) VALUES (88888, '2022-03-04', 55.0), (88888, '2022-03-05', 53.0), (88888, '2022-03-06', 57.0); |
What is the total number of members in unions with a focus on worker safety? | CREATE TABLE union_membership (member_id INT,union_id INT,member_name TEXT,member_since DATE); INSERT INTO union_membership (member_id,union_id,member_name,member_since) VALUES (1,1001,'John Doe','2010-01-01'); INSERT INTO union_membership (member_id,union_id,member_name,member_since) VALUES (2,1002,'Jane Smith','2012-... | SELECT COUNT(member_id) FROM union_membership m JOIN unions u ON m.union_id = u.union_id WHERE u.focus = 'worker safety'; |
What is the minimum total labor cost for construction projects in Los Angeles between 2018 and 2020? | CREATE TABLE construction_labor_costs (cost_id INT,project_name VARCHAR(100),city VARCHAR(50),start_year INT,end_year INT,total_cost DECIMAL(10,2)); INSERT INTO construction_labor_costs (cost_id,project_name,city,start_year,end_year,total_cost) VALUES (1,'CentralParkRevamp','New York City',2019,2020,1500000),(2,'Brookl... | SELECT MIN(total_cost) FROM construction_labor_costs WHERE city = 'Los Angeles' AND start_year >= 2018 AND end_year <= 2020; |
List all suppliers that provide recycled materials for products in the 'Supplier' table | CREATE TABLE Supplier (supplier_id INT PRIMARY KEY,supplier_name VARCHAR(50),uses_recycled_materials BOOLEAN); CREATE TABLE Product_Supplier (product_id INT,supplier_id INT,FOREIGN KEY (product_id) REFERENCES Product(product_id),FOREIGN KEY (supplier_id) REFERENCES Supplier(supplier_id)); | SELECT Supplier.supplier_name FROM Supplier INNER JOIN Product_Supplier ON Supplier.supplier_id = Product_Supplier.supplier_id WHERE Product_Supplier.product_id IN (SELECT Product.product_id FROM Product WHERE Product.material_recycled = TRUE); |
What is the total amount donated by each donor, sorted by the total donation amount in descending order? | CREATE TABLE donors (donor_id INT,donor_name TEXT,total_donation DECIMAL(10,2)); | SELECT donor_name, total_donation FROM donors ORDER BY total_donation DESC; |
List the hospitals in the "rural_hospitals" table that have been allocated resources for mental health programs. | CREATE TABLE rural_hospitals (id INT,name TEXT,location TEXT,num_beds INT,mental_health_resources BOOLEAN); INSERT INTO rural_hospitals (id,name,location,num_beds,mental_health_resources) VALUES (1,'Rural Hospital A','Rural Area 1',60,TRUE),(2,'Rural Hospital B','Rural Area 2',45,FALSE),(3,'Rural Hospital C','Rural Are... | SELECT name, location FROM rural_hospitals WHERE mental_health_resources = TRUE; |
What is the number of students who have ever enrolled in lifelong learning programs in each school type? | CREATE TABLE SchoolTypes (id INT,name VARCHAR(20)); INSERT INTO SchoolTypes (id,name) VALUES (1,'Public'),(2,'Private'),(3,'Charter'); CREATE TABLE StudentEnrollment (student_id INT,school_type_id INT); INSERT INTO StudentEnrollment (student_id,school_type_id) VALUES (1,1),(2,1),(3,2),(4,3),(5,1); | SELECT s.name, COUNT(DISTINCT se.student_id) FROM SchoolTypes s JOIN StudentEnrollment se ON s.id = se.school_type_id GROUP BY s.name; |
Insert a new donation of $200.00 from donor with ID 5 on March 15, 2022 | CREATE TABLE donations (id INT,donor_id INT,donation_date DATE,amount DECIMAL); INSERT INTO donations (id,donor_id,donation_date,amount) VALUES (1,1,'2022-03-01',50.00),(2,1,'2022-03-05',75.00),(3,2,'2022-03-07',100.00); CREATE TABLE donors (id INT,donor_name VARCHAR); INSERT INTO donors (id,donor_name) VALUES (1,'Jane... | INSERT INTO donations (id, donor_id, donation_date, amount) VALUES (4, 5, '2022-03-15', 200.00); |
Find the total number of visitors from New York that viewed digital exhibits since 2018. | CREATE TABLE Visitors (id INT,city VARCHAR(50),digital_exhibits INT,visit_year INT); INSERT INTO Visitors (id,city,digital_exhibits,visit_year) VALUES (1,'New York',2500,2019); | SELECT SUM(digital_exhibits) FROM Visitors WHERE city = 'New York' AND visit_year >= 2018; |
Show the number of new members and total workouts for each month in 2019. | CREATE TABLE membership_data (member_id INT,join_date DATE); CREATE TABLE workout_data (workout_id INT,member_id INT,workout_date DATE); | SELECT EXTRACT(MONTH FROM m.join_date) as month, COUNT(DISTINCT m.member_id) as new_members, SUM(w.workout_id) as total_workouts FROM membership_data m JOIN workout_data w ON m.member_id = w.member_id WHERE YEAR(m.join_date) = 2019 GROUP BY month; |
Insert a new hospital into 'rural_hospitals' | CREATE TABLE if not exists 'rural_hospitals' (id INT,name TEXT,address TEXT,worker_age INT,PRIMARY KEY(id)); | INSERT INTO 'rural_hospitals' (id, name, address, worker_age) VALUES (3, 'New Hospital', 'New Address', 45); |
What is the total number of building permits issued in each state, for the past year? | CREATE TABLE BuildingPermits (PermitID INT,PermitType TEXT,DateIssued DATE,State TEXT); | SELECT State, Count(PermitID) AS Count FROM BuildingPermits WHERE DateIssued >= DATEADD(year, -1, GETDATE()) GROUP BY State; |
What is the average cost of rural infrastructure projects in each state of India? | CREATE TABLE states (id INT,name VARCHAR(50),country VARCHAR(50)); INSERT INTO states (id,name,country) VALUES (1,'Andhra Pradesh','India'); CREATE TABLE rural_infrastructure_projects (id INT,cost FLOAT,state_id INT); INSERT INTO rural_infrastructure_projects (id,cost,state_id) VALUES (1,12000.0,1); | SELECT s.name, AVG(r.cost) as avg_cost FROM rural_infrastructure_projects r INNER JOIN states s ON r.state_id = s.id GROUP BY s.name; |
How many cruelty-free products are there in each product category? | CREATE TABLE Products (product_id INT,category VARCHAR(50),cruelty_free BOOLEAN); | SELECT category, COUNT(*) FROM Products WHERE cruelty_free = TRUE GROUP BY category; |
Calculate the environmental impact score for chemical 'J' by production date. | CREATE TABLE Chemical_Info (id INT,production_date DATE,chemical TEXT,environmental_impact_score FLOAT); INSERT INTO Chemical_Info (id,production_date,chemical,environmental_impact_score) VALUES (1,'2022-01-01','J',0.85),(2,'2022-01-02','J',0.88),(3,'2022-01-03','J',0.82); | SELECT production_date, environmental_impact_score FROM Chemical_Info WHERE chemical = 'J'; |
What is the total revenue for all restaurants? | CREATE TABLE restaurant (restaurant_id INT,revenue INT); INSERT INTO restaurant (restaurant_id,revenue) VALUES (1,5000),(2,6000),(3,7000),(4,4000); | SELECT SUM(revenue) FROM restaurant; |
Which garments are most often sold in the 'Sustainable' category between May and August 2023? | CREATE TABLE garments (id INT PRIMARY KEY,name VARCHAR(255),category VARCHAR(255),price DECIMAL(10,2)); CREATE TABLE sales (id INT PRIMARY KEY,garment_id INT,date DATE,quantity INT); CREATE VIEW sales_by_category AS SELECT category,name,SUM(quantity) as total_sold FROM sales JOIN garments ON sales.garment_id = garments... | SELECT category, name, total_sold FROM sales_by_category WHERE category = 'Sustainable' AND date BETWEEN '2023-05-01' AND '2023-08-31' ORDER BY total_sold DESC; |
How many volunteers have contributed more than 100 hours in total? | CREATE TABLE Volunteers (VolunteerID INT,DonorID INT,NonprofitID INT,Hours INT,Year INT); INSERT INTO Volunteers (VolunteerID,DonorID,NonprofitID,Hours,Year) VALUES (1,1,1,50,2020); INSERT INTO Volunteers (VolunteerID,DonorID,NonprofitID,Hours,Year) VALUES (2,2,2,75,2019); INSERT INTO Volunteers (VolunteerID,DonorID,No... | SELECT COUNT(*) FROM (SELECT DonorID, SUM(Hours) as TotalHours FROM Volunteers GROUP BY DonorID) as VolunteerTotals WHERE TotalHours > 100; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.