instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the total number of public transportation trips taken by people with disabilities in each year?
CREATE TABLE trip (id INT,year INT,disability BOOLEAN,trips INT); INSERT INTO trip (id,year,disability,trips) VALUES (1,2018,false,50000),(2,2018,true,45000),(3,2019,false,60000),(4,2019,true,50000),(5,2020,false,70000),(6,2020,true,65000),(7,2021,false,80000),(8,2021,true,75000);
SELECT year, SUM(trips) FROM trip WHERE disability = true GROUP BY year
How many unique engine types have been used by Airbus?
CREATE TABLE airbus_aircraft (id INT,model VARCHAR(255),engine_type VARCHAR(255)); INSERT INTO airbus_aircraft (id,model,engine_type) VALUES (1,'A320','CFM56'),(2,'A330','Rolls-Royce Trent 700');
SELECT COUNT(DISTINCT engine_type) FROM airbus_aircraft;
What is the percentage of male patients who have had a colonoscopy in the last year in the state of Texas?
CREATE TABLE screenings (screening_id INT,patient_id INT,screening VARCHAR(20),date DATE,gender VARCHAR(10)); INSERT INTO screenings (screening_id,patient_id,screening,date,gender) VALUES (1,5,'Mammogram','2021-03-15','Female'); INSERT INTO screenings (screening_id,patient_id,screening,date,gender) VALUES (2,6,'Colonos...
SELECT (COUNT(*) / (SELECT COUNT(*) FROM screenings WHERE date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) AND CURRENT_DATE AND gender = 'Male')) * 100 FROM screenings WHERE date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) AND CURRENT_DATE AND screening = 'Colonoscopy' AND gender = 'Male'
What was the total revenue from cannabis-infused topicals sold by each dispensary in the city of Vancouver in the month of March 2022?
CREATE TABLE Dispensaries (id INT,name VARCHAR(255),city VARCHAR(255),state VARCHAR(255));CREATE TABLE Inventory (id INT,dispensary_id INT,revenue DECIMAL(10,2),product_type VARCHAR(255),month INT,year INT);INSERT INTO Dispensaries (id,name,city,state) VALUES (1,'Maple Leaf Cannabis','Vancouver','BC');INSERT INTO Inven...
SELECT d.name, SUM(i.revenue) as total_revenue FROM Dispensaries d JOIN Inventory i ON d.id = i.dispensary_id WHERE d.city = 'Vancouver' AND i.product_type = 'topicals' AND i.month = 3 AND i.year = 2022 GROUP BY d.name;
What is the total amount of greenhouse gas emissions for each mining operation, broken down by emission source, in the past year?
CREATE TABLE mining_operations (id INT,name TEXT); CREATE TABLE emission_sources (id INT,operation_id INT,type TEXT); CREATE TABLE emissions (id INT,source_id INT,year INT,amount FLOAT); INSERT INTO mining_operations (id,name) VALUES (1,'Operation A'),(2,'Operation B'),(3,'Operation C'); INSERT INTO emission_sources (i...
SELECT emission_sources.type, mining_operations.name, SUM(emissions.amount) FROM emissions INNER JOIN emission_sources ON emissions.source_id = emission_sources.id INNER JOIN mining_operations ON emission_sources.operation_id = mining_operations.id WHERE emissions.year = 2021 GROUP BY emission_sources.type, mining_oper...
List all the public parks in the state of New York and Pennsylvania, including their size in acres.
CREATE TABLE Parks (name VARCHAR(50),state VARCHAR(20),size_acres INT); INSERT INTO Parks (name,state,size_acres) VALUES ('ParkA','New York',100),('ParkB','New York',200),('ParkC','Pennsylvania',150);
SELECT name, state, size_acres FROM Parks WHERE state IN ('New York', 'Pennsylvania');
List all artworks and their corresponding acquisition dates from museums located in the Pacific region.
CREATE TABLE museums (id INT,name VARCHAR(255),city VARCHAR(255),region VARCHAR(255)); CREATE TABLE artworks (id INT,museum_id INT,title VARCHAR(255),acquisition_date DATE);
SELECT a.title, a.acquisition_date FROM artworks a JOIN museums m ON a.museum_id = m.id WHERE m.region = 'Pacific';
What is the total quantity of vegan dishes sold in the city of Tokyo for the month of December 2022?
CREATE TABLE Dishes (dish_id INT,dish_name TEXT,dish_type TEXT,quantity_sold INT,sale_date DATE,city TEXT); INSERT INTO Dishes (dish_id,dish_name,dish_type,quantity_sold,sale_date,city) VALUES (1,'Ramen','vegan',80,'2022-12-01','Tokyo');
SELECT SUM(quantity_sold) FROM Dishes WHERE city = 'Tokyo' AND dish_type = 'vegan' AND sale_date >= '2022-12-01' AND sale_date < '2023-01-01';
Which beauty products have been flagged for containing harmful ingredients in any region?
CREATE TABLE beauty_products (product_id INT,product_name VARCHAR(100),region VARCHAR(50),harmful_ingredients BOOLEAN); INSERT INTO beauty_products (product_id,product_name,region,harmful_ingredients) VALUES (1,'Cleanser A','North America',true),(2,'Toner B','Europe',false),(3,'Moisturizer C','Asia',true),(4,'Sunscreen...
SELECT product_name FROM beauty_products WHERE harmful_ingredients = true;
What is the total revenue from ticket sales for the 'Basketball' team, including merchandise and concessions, in the 'team_revenue' table?
CREATE TABLE team_revenue (id INT PRIMARY KEY,team VARCHAR(50),revenue_type VARCHAR(50),revenue DECIMAL(5,2)); CREATE TABLE teams (id INT PRIMARY KEY,name VARCHAR(100),sport VARCHAR(50));
SELECT SUM(tr.revenue) as total_revenue FROM team_revenue tr JOIN teams t ON tr.team = t.name WHERE t.sport = 'Basketball' AND tr.revenue_type IN ('Ticket Sales', 'Merchandise', 'Concessions');
number of missions for each spacecraft
CREATE TABLE Spacecraft_Manufacturing(name VARCHAR(50),mass FLOAT,country VARCHAR(50));
CREATE VIEW Spacecraft_Missions AS SELECT name, COUNT(*) as missions FROM Spacecraft_Manufacturing JOIN Missions ON Spacecraft_Manufacturing.name = Missions.spacecraft;SELECT country, SUM(missions) FROM Spacecraft_Missions GROUP BY country;
List the total cargo weight for each type of cargo that was transported by the vessel with ID 5 in the past week?
CREATE TABLE Cargo_Tracking(Vessel_ID INT,Cargo_Type VARCHAR(50),Transport_Date DATE,Total_Weight INT); INSERT INTO Cargo_Tracking VALUES (5,'Coal','2022-03-20',2000),(5,'Iron Ore','2022-03-21',3000),(5,'Grain','2022-03-23',1500);
SELECT Cargo_Type, SUM(Total_Weight) FROM Cargo_Tracking WHERE Vessel_ID = 5 AND Transport_Date >= DATEADD(WEEK, -1, GETDATE()) GROUP BY Cargo_Type;
Display the top three most common colors in the 'Inventory' table, across all garment types.
CREATE TABLE Inventory (garment_type VARCHAR(20),color VARCHAR(20),quantity INT); INSERT INTO Inventory (garment_type,color,quantity) VALUES ('Dress','Black',500),('Dress','Blue',400),('Shirt','White',300),('Shirt','Black',200),('Pants','Blue',150);
SELECT color, SUM(quantity) AS total_quantity FROM Inventory GROUP BY color ORDER BY total_quantity DESC LIMIT 3;
Update the 'vehicle_type' to 'Minibus' for all records in the 'vehicles' table where the 'vehicle_id' is 'BUS-111'
CREATE TABLE vehicles (vehicle_id VARCHAR(20),vehicle_type VARCHAR(20),vehicle_name VARCHAR(20)); INSERT INTO vehicles (vehicle_id,vehicle_type,vehicle_name) VALUES ('BUS-111','Bus','BusA'),('TRAIN-123','Train','TrainA');
UPDATE vehicles SET vehicle_type = 'Minibus' WHERE vehicle_id = 'BUS-111';
What is the total quantity of gluten-free products ordered in Texas?
CREATE TABLE Products (ProductID INT,ProductName VARCHAR(50),SupplierID INT,Category VARCHAR(50),IsGlutenFree BOOLEAN,Price DECIMAL(5,2)); INSERT INTO Products (ProductID,ProductName,SupplierID,Category,IsGlutenFree,Price) VALUES (1,'Quinoa Pasta',1,'Pasta',true,5.00); CREATE TABLE Orders (OrderID INT,ProductID INT,Qua...
SELECT SUM(Quantity) FROM Orders JOIN Products ON Orders.ProductID = Products.ProductID WHERE Products.IsGlutenFree = true AND CustomerLocation = 'Texas';
What is the total number of news articles published by independent outlets in the United States and Canada?
CREATE TABLE news_articles (id INT,outlet VARCHAR(255),location VARCHAR(255),article_type VARCHAR(255)); INSERT INTO news_articles (id,outlet,location,article_type) VALUES (1,'LA Independent','United States','News'); INSERT INTO news_articles (id,outlet,location,article_type) VALUES (2,'NY Indie Press','United States',...
SELECT COUNT(*) FROM news_articles WHERE location IN ('United States', 'Canada') AND article_type = 'News';
What is the total number of aircraft manufactured by 'Boeing' and 'Airbus'?
CREATE TABLE AircraftManufacturers (Company VARCHAR(50),Model VARCHAR(50)); INSERT INTO AircraftManufacturers (Company,Model) VALUES ('Boeing','747'),('Boeing','787 Dreamliner'),('Airbus','A320'),('Airbus','A380'),('Bombardier','CRJ700');
SELECT SUM(CASE WHEN Company IN ('Boeing', 'Airbus') THEN 1 ELSE 0 END) FROM AircraftManufacturers;
What is the distribution of language preservation initiatives by language and country?
CREATE TABLE language_preservation (id INT,language VARCHAR(255),initiative VARCHAR(255),country VARCHAR(255)); INSERT INTO language_preservation (id,language,initiative,country) VALUES (1,'Quechua','Quechua Education','Peru'),(2,'Gaelic','Gaelic Language Revitalization','Scotland'); CREATE VIEW language_preservation_b...
SELECT country, language, initiative_count FROM language_preservation_by_country_language;
What is the total billing amount for clients by demographic?
CREATE TABLE ClientDemographics (ClientID INT,ClientName VARCHAR(50),Age INT,Gender VARCHAR(50),Race VARCHAR(50),BillingAmount DECIMAL(10,2)); INSERT INTO ClientDemographics (ClientID,ClientName,Age,Gender,Race,BillingAmount) VALUES (1,'John Doe',35,'Male','White',5000.00),(2,'Jane Doe',45,'Female','Asian',7000.00),(3,...
SELECT Gender, Race, SUM(BillingAmount) AS TotalBillingAmount FROM ClientDemographics GROUP BY Gender, Race;
What is the maximum temperature recorded per sensor per hour?
create table SensorData (Sensor varchar(255),Temperature int,Timestamp datetime); insert into SensorData values ('Sensor1',20,'2022-01-01 00:00:00'),('Sensor2',22,'2022-01-01 01:00:00'),('Sensor1',25,'2022-01-02 02:00:00');
select Sensor, DATE_PART('hour', Timestamp) as Hour, MAX(Temperature) as MaxTemperature from SensorData group by Sensor, Hour;
How many circular economy initiatives were launched by organization?
CREATE TABLE circular_economy_initiatives (id INT,organization VARCHAR(255),initiative VARCHAR(255),launch_date DATE);
SELECT organization, COUNT(*) as total_initiatives FROM circular_economy_initiatives GROUP BY organization HAVING total_initiatives > 1;
How many traditional arts are practiced in Oceania?
CREATE TABLE traditional_arts (id INT,name TEXT,type TEXT,region TEXT); INSERT INTO traditional_arts (id,name,type,region) VALUES (1,'Aboriginal Rock Art','Painting','Oceania');
SELECT COUNT(*) FROM traditional_arts WHERE region = 'Oceania';
Which NHL team has the highest average goal difference per season over the last 15 years?
CREATE TABLE nhl_teams (team_id INT,team_name VARCHAR(50)); INSERT INTO nhl_teams (team_id,team_name) VALUES (1,'Montreal Canadiens'),(2,'Toronto Maple Leafs'); CREATE TABLE nhl_games (game_id INT,team_id INT,year INT,goals_for INT,goals_against INT);
SELECT team_id, AVG(goals_for - goals_against) FROM nhl_games WHERE year BETWEEN 2007 AND 2021 GROUP BY team_id ORDER BY AVG(goals_for - goals_against) DESC LIMIT 1;
Find the maximum depth for each type of marine habitat.
CREATE TABLE species (id INT,name VARCHAR(50),habitat_type VARCHAR(50),habitat_depth FLOAT);
SELECT habitat_type, MAX(habitat_depth) FROM species GROUP BY habitat_type;
What is the sum of all transaction values (in USD) for Binance Smart Chain in the past week?
CREATE TABLE binance_smart_chain (transaction_time TIMESTAMP,transaction_value DECIMAL(18,2));
SELECT SUM(transaction_value) FROM binance_smart_chain WHERE transaction_time >= NOW() - INTERVAL '1 week';
Which contractors have completed sustainable building projects in the state of Oregon?
CREATE TABLE Contractors (ContractorID INT,ContractorName TEXT); INSERT INTO Contractors (ContractorID,ContractorName) VALUES (1,'ABC Builders'),(2,'Green Construction'),(3,'Eco Builders'); CREATE TABLE SustainableProjects (ProjectID INT,ContractorID INT,State TEXT); INSERT INTO SustainableProjects (ProjectID,Contracto...
SELECT DISTINCT ContractorName FROM Contractors C INNER JOIN SustainableProjects SP ON C.ContractorID = SP.ContractorID WHERE SP.State = 'OR';
What is the average price of cosmetics sold in the US, grouped by brand and categorized as luxury or mass-market?
CREATE TABLE sales (id INT,brand VARCHAR(255),product_category VARCHAR(255),country VARCHAR(255),sales_amount DECIMAL(10,2),sale_date DATE);
SELECT brand, AVG(sales_amount) as avg_price FROM sales WHERE country = 'US' AND product_category IN ('luxury', 'mass-market') GROUP BY brand;
List the product names and their sourcing countries for cosmetic products with a sales volume above 5000.
CREATE TABLE product_sales (product_id INT,sales INT); INSERT INTO product_sales (product_id,sales) VALUES (1,6000),(2,4000),(3,9000);
SELECT products.product_name, sourcing.country_name FROM products JOIN sourcing ON products.product_id = sourcing.product_id JOIN product_sales ON products.product_id = product_sales.product_id WHERE products.sales > 5000;
Create a new table named 'smart_grid'
CREATE TABLE smart_grid (id INT PRIMARY KEY,city VARCHAR(50),power_sources VARCHAR(50));
CREATE TABLE smart_grid (id INT PRIMARY KEY, city VARCHAR(50), power_sources VARCHAR(50));
What is the total budget for the organization?
CREATE TABLE Budget (id INT,amount DECIMAL(10,2));
SELECT SUM(Budget.amount) as total_budget FROM Budget;
What is the average sea level rise for the Pacific region?
CREATE TABLE sea_level_data (id INT,region VARCHAR(50),sea_level_rise DECIMAL); INSERT INTO sea_level_data (id,region,sea_level_rise) VALUES (1,'Pacific',0.3); INSERT INTO sea_level_data (id,region,sea_level_rise) VALUES (2,'Atlantic',0.2);
SELECT AVG(sea_level_rise) FROM sea_level_data WHERE region = 'Pacific';
What is the maximum number of streams for any Afrobeats song in Lagos?
CREATE TABLE Streams (song_genre VARCHAR(255),city VARCHAR(255),stream_count INT,stream_date DATE); INSERT INTO Streams (song_genre,city,stream_count,stream_date) VALUES ('Afrobeats','Lagos',6000,'2022-02-01'),('hip-hop','Accra',7000,'2022-02-02');
SELECT MAX(stream_count) FROM Streams WHERE song_genre = 'Afrobeats' AND city = 'Lagos';
What is the average number of citizen feedback messages received per day in each city?
CREATE TABLE city_feedback (feedback_id INT,city_name VARCHAR(50),feedback_date DATE); INSERT INTO city_feedback VALUES (1,'CityD','2021-05-01'),(2,'CityE','2021-05-02'),(3,'CityD','2021-05-03'),(4,'CityF','2021-05-04'),(5,'CityE','2021-05-05');
SELECT city_name, AVG(ROW_NUMBER() OVER (PARTITION BY city_name ORDER BY feedback_date)) as avg_feedback_per_day FROM city_feedback GROUP BY city_name;
What is the total number of workers in each role across all factories?
CREATE TABLE factories (factory_id INT,department VARCHAR(255)); INSERT INTO factories VALUES (1,'Assembly'),(1,'Quality Control'),(2,'Design'),(2,'Testing'); CREATE TABLE workers (worker_id INT,factory_id INT,department VARCHAR(255),role VARCHAR(255)); INSERT INTO workers VALUES (1,1,'Assembly','Engineer'),(2,1,'Assem...
SELECT w.role, COUNT(w.worker_id) as total_workers FROM workers w JOIN factories f ON w.factory_id = f.factory_id GROUP BY w.role;
Calculate the total area of ocean floor mapping projects in a specific region.
CREATE TABLE mapping_projects (project_id INT,name VARCHAR(255),area_km FLOAT,region VARCHAR(255));
SELECT region, SUM(area_km) AS total_area FROM mapping_projects WHERE region = 'Caribbean' GROUP BY region;
Insert new records into the 'Farmers' table, representing farmers in the 'Africa' region
CREATE TABLE Farmers (id INT,name VARCHAR(50),age INT,region VARCHAR(20),innovation_score FLOAT);
INSERT INTO Farmers (id, name, age, region, innovation_score) VALUES (1, 'Nana', 35, 'Africa', 7.2), (2, 'Kofi', 42, 'Africa', 8.5), (3, 'Akosua', 28, 'Africa', 6.8);
What is the maximum depth of the ocean floor in the Southern Ocean?
CREATE TABLE southern_ocean_depths (location TEXT,depth FLOAT); INSERT INTO southern_ocean_depths (location,depth) VALUES ('Southern Ocean',7235.0),('Antarctic Ocean',7280.0),('Weddell Sea',7400.0);
SELECT MAX(depth) FROM southern_ocean_depths WHERE location = 'Southern Ocean';
average retail price of garments in the 'Dresses' category that are made of 'Silk' fabric
CREATE TABLE Fabrics (fabric_id INT,fabric_type VARCHAR(25)); INSERT INTO Fabrics (fabric_id,fabric_type) VALUES (1,'Cotton'),(2,'Polyester'),(3,'Hemp'),(4,'Silk'); CREATE TABLE Garments (garment_id INT,price DECIMAL(5,2),fabric_id INT,category VARCHAR(25)); INSERT INTO Garments (garment_id,price,fabric_id,category) VA...
SELECT AVG(price) FROM Garments INNER JOIN Fabrics ON Garments.fabric_id = Fabrics.fabric_id WHERE category = 'Dresses' AND fabric_type = 'Silk';
List all economic diversification efforts in the 'economic_diversification' table and their respective start dates.
CREATE TABLE economic_diversification (project_name VARCHAR(255),project_type VARCHAR(255),start_date DATE); INSERT INTO economic_diversification (project_name,project_type,start_date) VALUES ('Renewable Energy Park','Economic Diversification','2020-01-01'),('Local Craft Market','Economic Diversification','2019-05-15')...
SELECT project_name, project_type, start_date FROM economic_diversification;
Which ingredients have been sourced from organic farms for cosmetic products in the past year?
CREATE TABLE ingredient_sourcing (ingredient_name VARCHAR(255),sourcing_location VARCHAR(255),last_updated DATE); INSERT INTO ingredient_sourcing (ingredient_name,sourcing_location,last_updated) VALUES ('Aloe Vera','Organic Farm,Arizona,USA','2022-03-01'),('Rosehip Oil','Organic Farm,Chile','2022-02-15'),('Shea Butter'...
SELECT ingredient_name FROM ingredient_sourcing WHERE sourcing_location LIKE '%Organic Farm%' AND last_updated >= DATEADD(year, -1, GETDATE());
How many vulnerabilities were discovered in the financial sector each year since 2018?
CREATE TABLE vulnerabilities (vuln_id INT,sector TEXT,year INT,discovered BOOLEAN); INSERT INTO vulnerabilities (vuln_id,sector,year,discovered) VALUES (1,'Financial',2018,TRUE),(2,'Financial',2019,TRUE),(3,'Financial',2020,TRUE),(4,'Financial',2021,TRUE),(5,'Financial',2022,TRUE);
SELECT year, COUNT(*) FROM vulnerabilities WHERE sector = 'Financial' AND discovered = TRUE GROUP BY year;
What is the average age of attendees at music concerts in Nashville, TN?
CREATE TABLE events (event_id INT,event_name VARCHAR(50),location VARCHAR(50),event_type VARCHAR(50)); INSERT INTO events (event_id,event_name,location,event_type) VALUES (1,'Music Concert','Nashville','Concert'); CREATE TABLE visitors (visitor_id INT,event_id INT,age INT); INSERT INTO visitors (visitor_id,event_id,age...
SELECT AVG(age) FROM visitors INNER JOIN events ON visitors.event_id = events.event_id WHERE events.location = 'Nashville' AND events.event_type = 'Concert';
Which open pedagogy initiatives have the lowest student engagement in the Humanities?
CREATE TABLE open_pedagogy (initiative_id INT,subject_area VARCHAR(50),student_engagement INT); INSERT INTO open_pedagogy (initiative_id,subject_area,student_engagement) VALUES (1,'Mathematics',25),(2,'Science',30),(3,'History',35),(4,'Arts',50),(5,'English',40),(6,'Philosophy',20),(7,'Literature',22);
SELECT subject_area, student_engagement FROM open_pedagogy WHERE subject_area = 'Philosophy' OR subject_area = 'Literature' ORDER BY student_engagement ASC;
What is the average yield of crops for each farmer in the rural district of Chitwan, Nepal, in 2021, grouped by crop type?
CREATE TABLE farmers (farmer_id INT,name TEXT,district TEXT,annual_yield FLOAT); INSERT INTO farmers (farmer_id,name,district,annual_yield) VALUES (1,'Ram','Chitwan',2500),(2,'Sita','Chitwan',3000),(3,'Hari','Chitwan',2200); CREATE TABLE crops (crop_type TEXT,yield INT); INSERT INTO crops (crop_type,yield) VALUES ('Pad...
SELECT c.crop_type, AVG(f.annual_yield) as avg_yield FROM farmers f INNER JOIN crops c ON f.district = 'Chitwan' AND f.annual_yield IS NOT NULL AND YEAR(f.date) = 2021 GROUP BY c.crop_type;
What is the minimum number of beds in rural_hospitals for hospitals in Australia?
CREATE TABLE rural_hospitals (hospital_id INT,beds INT,location VARCHAR(20));
SELECT MIN(beds) FROM rural_hospitals WHERE location = 'Australia';
What is the average number of wins per season for teams in the American league?
CREATE TABLE teams (team_id INT,team_name VARCHAR(50),league VARCHAR(50),wins INT,season INT);
SELECT AVG(teams.wins) FROM teams WHERE teams.league = 'American' GROUP BY teams.season;
Calculate the ratio of claims to policies for each underwriter, excluding underwriters with no policies.
CREATE TABLE underwriters (id INT,name VARCHAR(100)); CREATE TABLE policies (id INT,underwriter_id INT); CREATE TABLE claims (id INT,policy_id INT); INSERT INTO underwriters (id,name) VALUES (1,'Gina'),(2,'Harry'),(3,'Irene'); INSERT INTO policies (id,underwriter_id) VALUES (1,1),(2,1),(3,2),(4,3),(5,NULL); INSERT INTO...
SELECT underwriters.name, COUNT(claims.id) * 1.0 / COUNT(DISTINCT policies.id) as claims_to_policies_ratio FROM underwriters LEFT JOIN policies ON underwriters.id = policies.underwriter_id LEFT JOIN claims ON policies.id = claims.policy_id GROUP BY underwriters.id HAVING COUNT(DISTINCT policies.id) > 0;
How many circular economy initiatives are in place in city D?
CREATE TABLE circular_economy_initiatives(city TEXT,initiative_count INTEGER); INSERT INTO circular_economy_initiatives(city,initiative_count) VALUES('D',5),('E',3),('F',6);
SELECT COUNT(*) FROM circular_economy_initiatives WHERE city = 'D';
Retrieve total rare earth element reserves by region.
CREATE TABLE mine (id INT,name VARCHAR(255),location VARCHAR(255),reserves FLOAT); INSERT INTO mine (id,name,location,reserves) VALUES (1,'DEF Mine','North America',50000.0),(2,'GHI Mine','South America',70000.0);
SELECT SUBSTRING_INDEX(location, ' ', 1) AS region, reserves AS total_reserves FROM mine;
What is the average number of employees for each sector in the ai_companies table?
CREATE TABLE ai_companies (id INT,name VARCHAR(20),location VARCHAR(20),sector VARCHAR(20),employees INT,ethical_ai BOOLEAN); INSERT INTO ai_companies (id,name,location,sector,employees,ethical_ai) VALUES (4,'GHI Tech','USA','Robotics',60,false);
SELECT sector, AVG(employees) as avg_employees FROM ai_companies GROUP BY sector;
Create a new table named 'DonorPrograms' with columns DonorID, Program, and DonationAmount.
CREATE TABLE Donors (DonorID int); INSERT INTO Donors (DonorID) VALUES (1),(2); CREATE TABLE Programs (Program varchar(50)); INSERT INTO Programs (Program) VALUES ('ProgramA'),('ProgramB');
CREATE TABLE DonorPrograms (DonorID int, Program varchar(50), DonationAmount numeric(10,2));
What is the average number of home runs hit by a baseball team in a season?
CREATE TABLE season_stats (id INT,team VARCHAR(50),sport VARCHAR(20),season VARCHAR(10),home_runs INT);
SELECT AVG(home_runs) FROM season_stats WHERE sport = 'Baseball' GROUP BY season;
What is the average monthly data usage for residential broadband customers in Texas?
CREATE TABLE residential_customers (customer_id INT,state VARCHAR(255),monthly_data_usage DECIMAL(5,2)); INSERT INTO residential_customers (customer_id,state,monthly_data_usage) VALUES (1,'Texas',50.5),(2,'California',60.3),(3,'Texas',45.8);
SELECT AVG(monthly_data_usage) FROM residential_customers WHERE state = 'Texas';
Which countries are involved in defense diplomacy with India?
CREATE TABLE defense_diplomacy (id INT,country VARCHAR(50),partner VARCHAR(50)); INSERT INTO defense_diplomacy (id,country,partner) VALUES (1,'India','Russia'),(2,'India','France'),(3,'India','Israel'),(4,'India','United States');
SELECT DISTINCT partner FROM defense_diplomacy WHERE country = 'India';
How many energy efficiency projects are there in Argentina and South Africa with less than 20 MWh capacity?
CREATE TABLE energy_efficiency_projects (country VARCHAR(20),capacity INT); INSERT INTO energy_efficiency_projects (country,capacity) VALUES ('Argentina',15),('Argentina',18),('Argentina',22),('South Africa',10),('South Africa',12),('South Africa',17);
SELECT COUNT(*) FROM energy_efficiency_projects WHERE country IN ('Argentina', 'South Africa') AND capacity < 20;
What is the minimum number of military satellites owned by countries in the 'Africa' region?
CREATE TABLE regions (id INT,name VARCHAR(255)); CREATE TABLE countries (id INT,name VARCHAR(255),region_id INT); CREATE TABLE military_satellites (id INT,country_id INT,number INT);
SELECT c.name as country, MIN(ms.number) as min_satellites_owned FROM regions r JOIN countries c ON r.id = c.region_id JOIN military_satellites ms ON c.id = ms.country_id WHERE r.name = 'Africa' GROUP BY c.id;
Find the total sales of the top 3 most expensive items
CREATE TABLE sales (item_id INT,sales_amount DECIMAL(5,2)); INSERT INTO sales VALUES (1,150.00),(2,200.00),(3,120.00);
SELECT SUM(sales.sales_amount) FROM sales JOIN menu ON sales.item_id = menu.item_id WHERE menu.item_id IN (SELECT item_id FROM menu ORDER BY price DESC LIMIT 3);
What are the top 3 countries with the most security incidents in the past month?
CREATE TABLE security_incidents (id INT,incident_date DATE,country VARCHAR(50)); INSERT INTO security_incidents (id,incident_date,country) VALUES (1,'2022-01-01','USA'),(2,'2022-01-05','Canada'),(3,'2022-01-10','Mexico');
SELECT country, COUNT(*) as incident_count FROM security_incidents WHERE incident_date >= DATEADD(month, -1, GETDATE()) GROUP BY country ORDER BY incident_count DESC LIMIT 3;
How many items were shipped from each warehouse in the USA?
CREATE TABLE Warehouse (id INT,city VARCHAR(50),country VARCHAR(50)); INSERT INTO Warehouse (id,city,country) VALUES (1,'Los Angeles','USA'),(2,'New York','USA'); CREATE TABLE Shipment (id INT,quantity INT,warehouse_id INT,destination_country VARCHAR(50)); INSERT INTO Shipment (id,quantity,warehouse_id,destination_coun...
SELECT Warehouse.city, SUM(Shipment.quantity) FROM Warehouse INNER JOIN Shipment ON Warehouse.id = Shipment.warehouse_id WHERE Warehouse.country = 'USA' GROUP BY Warehouse.city;
What is the ratio of male to female patients in Texas who received a pneumonia vaccine in the last month?
CREATE TABLE patient (patient_id INT,age INT,gender VARCHAR(10),state VARCHAR(10)); INSERT INTO patient (patient_id,age,gender,state) VALUES (1,45,'Female','Texas'); INSERT INTO patient (patient_id,age,gender,state) VALUES (2,50,'Male','Texas');
SELECT (SELECT COUNT(*) FROM patient WHERE gender = 'Male' AND state = 'Texas' AND pneumonia_vaccine_date >= DATEADD(month, -1, GETDATE())) / (SELECT COUNT(*) FROM patient WHERE gender = 'Female' AND state = 'Texas' AND pneumonia_vaccine_date >= DATEADD(month, -1, GETDATE())) AS ratio;
What is the total value of defense contracts issued per year, ranked by total value in descending order?
CREATE TABLE Contract_Values (Contract_ID INT,Year INT,Value DECIMAL(18,2)); INSERT INTO Contract_Values (Contract_ID,Year,Value) VALUES (1,2018,5000000),(2,2019,6000000),(3,2020,7000000),(4,2021,8000000),(5,2018,9000000),(6,2019,10000000),(7,2020,11000000),(8,2021,12000000);
SELECT Year, SUM(Value) as Total_Value FROM Contract_Values GROUP BY Year ORDER BY Total_Value DESC;
Remove esports events with a prize pool lower than a given value
CREATE TABLE EsportsEvents (EventID INT PRIMARY KEY,Name VARCHAR(50),Location VARCHAR(50),Date DATE,PrizePool FLOAT); INSERT INTO EsportsEvents (EventID,Name,Location,Date,PrizePool) VALUES (1,'Event 1','City 1','2023-01-01',100000); INSERT INTO EsportsEvents (EventID,Name,Location,Date,PrizePool) VALUES (2,'Event 2','...
DELETE FROM EsportsEvents WHERE PrizePool < 75000;
What is the monthly average trading volume for all stocks in the 'Tech' sector, ordered by volume in descending order?
CREATE TABLE stocks (id INT,symbol VARCHAR(10),sector VARCHAR(20),volume INT); INSERT INTO stocks (id,symbol,sector,volume) VALUES (1,'AAPL','Tech',1000000); INSERT INTO stocks (id,symbol,sector,volume) VALUES (2,'GOOG','Tech',800000);
SELECT sector, AVG(volume) as avg_volume FROM stocks WHERE sector = 'Tech' GROUP BY sector ORDER BY avg_volume DESC;
How many containers were handled by port 'XYZ' in the month of January 2022?
CREATE TABLE containers (id INT,port VARCHAR(255),handled_date DATE); INSERT INTO containers (id,port,handled_date) VALUES (1,'XYZ','2022-01-02'),(2,'ABC','2022-01-03');
SELECT COUNT(*) FROM containers WHERE port = 'XYZ' AND handled_date BETWEEN '2022-01-01' AND '2022-01-31';
What is the total number of players who play games on console and PC?
CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10),Country VARCHAR(20),Console BOOLEAN,PC BOOLEAN); INSERT INTO Players (PlayerID,Age,Gender,Country,Console,PC) VALUES (1,25,'Male','USA',TRUE,TRUE),(2,30,'Female','Canada',FALSE,TRUE),(3,35,'Female','Mexico',TRUE,FALSE);
SELECT COUNT(*) FROM Players WHERE Console = TRUE AND PC = TRUE;
What is the total value of transactions for each smart contract in the 'Decentralized Finance' category?
CREATE TABLE smart_contracts (contract_name TEXT,category TEXT,total_value FLOAT); INSERT INTO smart_contracts (contract_name,category,total_value) VALUES ('Compound','Decentralized Finance',1200000),('Aave','Decentralized Finance',1000000),('Uniswap','Decentralized Finance',800000),('Sushiswap','Decentralized Finance'...
SELECT category, SUM(total_value) FROM smart_contracts WHERE category = 'Decentralized Finance' GROUP BY category;
What is the average weight of containers shipped from the Port of Oakland to Canada in 2020?
CREATE TABLE ports (port_id INT,port_name TEXT,country TEXT);CREATE TABLE shipments (shipment_id INT,shipment_weight INT,ship_date DATE,port_id INT); INSERT INTO ports VALUES (1,'Port of Oakland','USA'),(2,'Port of Vancouver','Canada'); INSERT INTO shipments VALUES (1,2000,'2020-01-01',1),(2,1500,'2020-02-15',1);
SELECT AVG(shipment_weight) FROM shipments JOIN ports ON shipments.port_id = ports.port_id WHERE ports.port_name = 'Port of Oakland' AND ports.country = 'USA' AND ship_date BETWEEN '2020-01-01' AND '2020-12-31';
How many sustainable and fair trade learning experiences have customers from India had?
CREATE TABLE customer_education (customer_id INT,country VARCHAR(50),learned_sustainability BOOLEAN,learned_fairtrade BOOLEAN); INSERT INTO customer_education (customer_id,country,learned_sustainability,learned_fairtrade) VALUES (1,'India',true,true),(2,'Nepal',false,true),(3,'India',true,false);
SELECT country, SUM(learned_sustainability + learned_fairtrade) as total_learned FROM customer_education WHERE country = 'India';
Insert new record into waste_generation table for location 'São Paulo' and waste generation 450 tons
CREATE TABLE waste_generation (location VARCHAR(50),waste_type VARCHAR(50),generation INT);
INSERT INTO waste_generation (location, waste_type, generation) VALUES ('São Paulo', 'paper', 450);
What is the minimum size of a property co-owned by 'Alice'?
CREATE TABLE co_ownership (id INT,property_id INT,owner TEXT,city TEXT,size INT); INSERT INTO co_ownership (id,property_id,owner,city,size) VALUES (1,101,'Alice','Austin',1200),(2,104,'Alice','Seattle',800),(3,105,'Alice','Portland',1000);
SELECT MIN(size) FROM co_ownership WHERE owner = 'Alice';
Determine the average number of hospital beds per hospital in each state, for hospitals that offer cancer treatment.
CREATE TABLE hospitals (hospital_name VARCHAR(50),state VARCHAR(50),num_beds INTEGER,offers_cancer_treatment BOOLEAN); INSERT INTO hospitals (hospital_name,state,num_beds,offers_cancer_treatment) VALUES ('Hospital A','California',250,TRUE),('Hospital B','California',150,FALSE),('Hospital C','Texas',300,TRUE),('Hospital...
SELECT state, AVG(num_beds) as avg_beds_per_hospital FROM hospitals WHERE offers_cancer_treatment = TRUE GROUP BY state;
What is the latest cybersecurity strategy published in the 'CyberSecurityStrategies' table?
CREATE TABLE CyberSecurityStrategies (id INT PRIMARY KEY,title VARCHAR(100),description TEXT,publish_date DATE,category VARCHAR(50)); INSERT INTO CyberSecurityStrategies (id,title,description,publish_date,category) VALUES (1,'Global Cybersecurity Initiative','A comprehensive plan to secure global networks...','2022-06-...
SELECT title, description, publish_date FROM CyberSecurityStrategies ORDER BY publish_date DESC LIMIT 1;
Find the number of units of women's garments produced using recycled materials.
CREATE TABLE garment_units_recycled_materials (id INT,garment_type VARCHAR(50),units INT,recycled_material BOOLEAN); INSERT INTO garment_units_recycled_materials (id,garment_type,units,recycled_material) VALUES (1,'Dress',300,true); INSERT INTO garment_units_recycled_materials (id,garment_type,units,recycled_material) ...
SELECT SUM(units) FROM garment_units_recycled_materials WHERE garment_type LIKE '%Women%' AND recycled_material = true;
Which soccer players have scored the most goals for their national teams?
CREATE TABLE players (id INT,name VARCHAR(50),sport VARCHAR(20),goals INT,nationality VARCHAR(50)); INSERT INTO players (id,name,sport,goals,nationality) VALUES (1,'Cristiano Ronaldo','Soccer',100,'Portugal'); INSERT INTO players (id,name,sport,goals,nationality) VALUES (2,'Lionel Messi','Soccer',80,'Argentina');
SELECT name, goals FROM players WHERE sport = 'Soccer' AND nationality IS NOT NULL ORDER BY goals DESC;
What is the average cost of projects per category?
CREATE TABLE Infrastructure (id INT,category VARCHAR(20),cost FLOAT); INSERT INTO Infrastructure (id,category,cost) VALUES (1,'Transportation',5000000),(2,'WaterSupply',3000000),(3,'Transportation',7000000),(4,'WaterSupply',1000000);
SELECT category, AVG(cost) FROM Infrastructure GROUP BY category;
List the top 3 contributors to the environment program, ordered by the total donation amount.
CREATE TABLE Donors (id INT,name VARCHAR(255),contact_info VARCHAR(255)); CREATE TABLE Donations (id INT,donor_id INT,program VARCHAR(255),amount DECIMAL(10,2)); INSERT INTO Donors (id,name,contact_info) VALUES (1,'John Doe','johndoe@example.com'),(2,'Jane Smith','janesmith@example.com'); INSERT INTO Donations (id,dono...
SELECT Donors.name, SUM(Donations.amount) as total_donation FROM Donors INNER JOIN Donations ON Donors.id = Donations.donor_id WHERE program = 'Environment' GROUP BY Donors.name ORDER BY total_donation DESC LIMIT 3;
What is the total sustainability score for sustainable fashion products in a specific country?
CREATE TABLE TextileSources (SourceID INT,Country VARCHAR(255),Material VARCHAR(255),SustainabilityScore INT); INSERT INTO TextileSources (SourceID,Country,Material,SustainabilityScore) VALUES (1,'India','Cotton',85),(2,'Brazil','Rayon',70),(3,'USA','Hemp',90);
SELECT Country, SUM(SustainabilityScore) AS TotalSustainabilityScore FROM TextileSources WHERE Country = 'USA' GROUP BY Country;
Identify the number of female and male workers in factories with Industry 4.0 initiatives.
CREATE TABLE factories (factory_id INT,name TEXT,location TEXT,industry4 BOOLEAN); CREATE TABLE workers (worker_id INT,factory_id INT,gender TEXT); INSERT INTO factories (factory_id,name,location,industry4) VALUES (1,'Factory A','City A',true),(2,'Factory B','City B',false),(3,'Factory C','City C',true); INSERT INTO wo...
SELECT i4.industry4, w.gender, COUNT(*) as total FROM workers w JOIN factories i4 ON w.factory_id = i4.factory_id WHERE i4.industry4 = true GROUP BY i4.industry4, w.gender;
Remove hotel_tech_adoption_table records where hotel_id is not present in the hotels_table
CREATE TABLE hotels (hotel_id INT,hotel_name VARCHAR(50));
DELETE hta FROM hotel_tech_adoption hta LEFT JOIN hotels h ON hta.hotel_id = h.hotel_id WHERE h.hotel_id IS NULL;
What is the total revenue for each fitness program, in descending order?
CREATE TABLE sales (sale_id INT,program_id INT,revenue FLOAT); INSERT INTO sales (sale_id,program_id,revenue) VALUES (1,1,500),(2,2,750),(3,3,300);
SELECT program_id, SUM(revenue) as total_revenue FROM sales GROUP BY program_id ORDER BY total_revenue DESC;
What is the average number of posts per user in the 'social_media' table?
CREATE TABLE social_media (user_id INT,posts_count INT);
SELECT AVG(posts_count) FROM social_media;
What is the average mental health score of students grouped by their participation in open pedagogy activities?
CREATE TABLE students (student_id INT,mental_health_score INT,participated_in_open_pedagogy BOOLEAN); INSERT INTO students (student_id,mental_health_score,participated_in_open_pedagogy) VALUES (1,80,TRUE),(2,60,FALSE),(3,90,TRUE),(4,70,FALSE),(5,50,FALSE);
SELECT participated_in_open_pedagogy, AVG(mental_health_score) FROM students GROUP BY participated_in_open_pedagogy;
What is the total biomass of marine life in the Arctic Ocean?
CREATE TABLE marine_life (location VARCHAR(255),biomass FLOAT); INSERT INTO marine_life (location,biomass) VALUES ('Arctic Ocean',12500000),('Atlantic Ocean',15000000);
SELECT SUM(biomass) FROM marine_life WHERE location = 'Arctic Ocean';
Insert a new animal 'Puma' into the 'Mountains' habitat. If the habitat doesn't exist, insert a new record for the 'Mountains' habitat and the 'Puma'.
CREATE TABLE habitats (id INT,habitat_type VARCHAR(255)); CREATE TABLE animals (id INT,animal_name VARCHAR(255),habitat_id INT); INSERT INTO habitats (id,habitat_type) VALUES (1,'Forest'),(2,'Savannah'),(3,'Wetlands'); INSERT INTO animals (id,animal_name,habitat_id) VALUES (1,'Lion',2),(2,'Elephant',1),(3,'Hippo',3),(4...
INSERT INTO habitats (id, habitat_type) VALUES (4, 'Mountains') ON CONFLICT (id) DO NOTHING; INSERT INTO animals (id, animal_name, habitat_id) VALUES (5, 'Puma', 4) ON CONFLICT (id) DO UPDATE SET animal_name = EXCLUDED.animal_name;
Add the following records to the 'ev_statistics' table: 'Tesla Model X' with 371 miles, 'Lucid Air' with 517 miles
CREATE TABLE ev_statistics (id INT PRIMARY KEY,vehicle_model VARCHAR(255),battery_range FLOAT);
INSERT INTO ev_statistics (vehicle_model, battery_range) VALUES ('Tesla Model X', 371), ('Lucid Air', 517);
Delete records in recycling_rates table where the region is not 'Asia', 'NA', 'EU'
CREATE TABLE recycling_rates (region VARCHAR(50),recycling_rate INT); INSERT INTO recycling_rates (region,recycling_rate) VALUES ('Asia',45),('EU',50),('NA',60),('Africa',30),('South America',40);
DELETE FROM recycling_rates WHERE region NOT IN ('Asia', 'NA', 'EU');
Which underrepresented communities received the least budget allocation for public services in the state of New York for the year 2021?
CREATE TABLE CommunityData (Community VARCHAR(20),State VARCHAR(20),Year INT); CREATE TABLE BudgetAllocation (State VARCHAR(20),Year INT,Community VARCHAR(20),Allocation DECIMAL(10,2)); INSERT INTO CommunityData VALUES ('African American','New York',2021),('Asian','New York',2021),('Hispanic','New York',2021),('Native ...
SELECT Community, MIN(Allocation) FROM BudgetAllocation b INNER JOIN CommunityData c ON b.Community = c.Community WHERE c.State = 'New York' AND c.Year = 2021 GROUP BY Community;
What is the average number of flight hours per aircraft model?
CREATE TABLE AircraftModels (Id INT,Manufacturer VARCHAR(50),Model VARCHAR(50)); INSERT INTO AircraftModels (Id,Manufacturer,Model) VALUES (1,'Boeing','737'),(2,'Boeing','747'),(3,'Airbus','A320'),(4,'Airbus','A330'); CREATE TABLE FlightHours (Id INT,AircraftModelId INT,Hours INT); INSERT INTO FlightHours (Id,AircraftM...
SELECT am.Manufacturer, am.Model, AVG(fh.Hours) as AvgHours FROM AircraftModels am JOIN FlightHours fh ON am.Id = fh.AircraftModelId GROUP BY am.Manufacturer, am.Model;
What is the total co-ownership price for properties in each city, grouped by category?
CREATE TABLE city (id INT,name VARCHAR(255)); INSERT INTO city (id,name) VALUES (1,'CityA'),(2,'CityB'); CREATE TABLE property (id INT,co_ownership_price DECIMAL(10,2),city_id INT,category VARCHAR(255)); INSERT INTO property (id,co_ownership_price,city_id,category) VALUES (1,500000,1,'sustainable urbanism'),(2,600000,1...
SELECT c.name AS city, p.category AS category, SUM(p.co_ownership_price) AS total_price FROM property p JOIN city c ON p.city_id = c.id GROUP BY c.name, p.category;
What is the total cargo weight for all shipments that share a delivery route with shipment ID 67890?
CREATE TABLE Shipments (ShipmentID int,DeliveryRoute int,CargoWeight int); INSERT INTO Shipments VALUES (12345,999,5000),(67890,999,7000),(11121,888,6000),(22232,777,8000);
SELECT SUM(CargoWeight) as TotalCargoWeight FROM Shipments WHERE DeliveryRoute IN (SELECT DeliveryRoute FROM Shipments WHERE ShipmentID = 67890);
Find the number of wells drilled per operator in the Northern region
CREATE TABLE wells (id INT,operator VARCHAR(50),region VARCHAR(50)); INSERT INTO wells (id,operator,region) VALUES (1,'ABC Oil','Northern'),(2,'XYZ Energy','Southern'),(3,' DEF Petroleum','Northern');
SELECT operator, COUNT(*) as num_wells FROM wells WHERE region = 'Northern' GROUP BY operator;
What is the donor retention rate for the organization?
CREATE TABLE donor_history (donor_id INT,is_donor_active BOOLEAN); INSERT INTO donor_history VALUES (1,TRUE),(2,TRUE),(3,FALSE),(4,TRUE),(5,FALSE),(6,TRUE);
SELECT (COUNT(DISTINCT CASE WHEN is_donor_active THEN donor_id END) - COUNT(DISTINCT CASE WHEN is_donor_active THEN donor_id END) FILTER (WHERE is_donor_active = FALSE)) * 100.0 / COUNT(DISTINCT donor_id) as donor_retention_rate FROM donor_history;
Delete all TV shows with a viewership count less than 2 million
CREATE TABLE tv_shows (id INT,title VARCHAR(100),viewership_count INT); INSERT INTO tv_shows (id,title,viewership_count) VALUES (1,'TVShowA',3000000); INSERT INTO tv_shows (id,title,viewership_count) VALUES (2,'TVShowB',1500000);
DELETE FROM tv_shows WHERE viewership_count < 2000000;
Update the total donation amount for donor 'Pedro Garcia' to $4500.
CREATE TABLE donors (donor_id INT,donor_name TEXT,country TEXT,total_donation_amount FLOAT); INSERT INTO donors (donor_id,donor_name,country,total_donation_amount) VALUES (1,'Juan Rodriguez','Mexico',4000.00),(2,'Natalia Ivanova','Russia',5000.00),(3,'Pedro Garcia','Brazil',2500.00);
WITH updated_pedro_garcia AS (UPDATE donors SET total_donation_amount = 4500.00 WHERE donor_name = 'Pedro Garcia' AND country = 'Brazil' RETURNING *) SELECT * FROM updated_pedro_garcia;
Show all records from 'humanitarian_assistance' table
CREATE TABLE humanitarian_assistance (id INT PRIMARY KEY,operation VARCHAR(255),location VARCHAR(255),start_date DATE,end_date DATE);
SELECT * FROM humanitarian_assistance;
What was the average monthly donation amount in the 'Health' project category for the past 12 months?
CREATE TABLE donations (donation_id INT,donation_amount DECIMAL,donation_date DATE,project_category VARCHAR(255)); INSERT INTO donations (donation_id,donation_amount,donation_date,project_category) VALUES (1,500,'2022-01-05','Health'),(2,300,'2022-01-10','Health'),(3,700,'2022-02-15','Environment');
SELECT AVG(donation_amount) / 12 as avg_monthly_donation FROM donations WHERE project_category = 'Health' AND donation_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 12 MONTH) AND CURDATE();
What are the names and ages of all victims who have participated in restorative justice programs in the state of California?
CREATE TABLE restorative_justice_programs (victim_name TEXT,victim_age INT,program_state TEXT); INSERT INTO restorative_justice_programs (victim_name,victim_age,program_state) VALUES ('John Doe',34,'California');
SELECT victim_name, victim_age FROM restorative_justice_programs WHERE program_state = 'California';
Which building permits were issued in the last 90 days for sustainable building practices?
CREATE TABLE BuildingPermits (PermitID INT,PermitDate DATE,Practice TEXT); INSERT INTO BuildingPermits VALUES (1,'2022-04-01','Green Roofs'),(2,'2022-06-15','Solar Panels'),(3,'2022-05-05','Insulation');
SELECT PermitID, PermitDate FROM BuildingPermits WHERE Practice IN ('Green Roofs', 'Solar Panels', 'Insulation') AND PermitDate >= DATE(NOW()) - INTERVAL 90 DAY;
Find the unique AI safety algorithms that do not have any transactions.
CREATE TABLE ai_safety_algorithms (id INT,algorithm_name VARCHAR(30)); INSERT INTO ai_safety_algorithms (id,algorithm_name) VALUES (1,'Algorithm X'); INSERT INTO ai_safety_algorithms (id,algorithm_name) VALUES (2,'Algorithm Y');
SELECT algorithm_name FROM ai_safety_algorithms WHERE id NOT IN (SELECT id FROM transactions WHERE algorithm_type = 'AI Safety');
How many cultivation licenses were issued per month in Canada in 2021?
CREATE TABLE Licenses (id INT,issue_date DATE,license_type TEXT); INSERT INTO Licenses (id,issue_date,license_type) VALUES (1,'2021-01-15','Cultivation'); INSERT INTO Licenses (id,issue_date,license_type) VALUES (2,'2021-01-20','Cultivation'); INSERT INTO Licenses (id,issue_date,license_type) VALUES (3,'2021-02-05','Cu...
SELECT DATE_FORMAT(issue_date, '%Y-%m') as month, COUNT(*) as num_licenses FROM Licenses WHERE license_type = 'Cultivation' AND issue_date BETWEEN '2021-01-01' AND '2021-12-31' GROUP BY month;