instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the total funding allocated for climate communication initiatives in 2022?
CREATE TABLE climate_funding (id INT,initiative_type TEXT,allocation FLOAT,year INT); INSERT INTO climate_funding (id,initiative_type,allocation,year) VALUES (1,'Mitigation',500000.00,2022),(2,'Adaptation',750000.00,2022),(3,'Communication',300000.00,2022);
SELECT SUM(allocation) FROM climate_funding WHERE initiative_type = 'Communication' AND year = 2022;
What is the difference in 'HabitatSize' between the 'HabitatPreservation' table and the 'AnimalPopulation' table?
CREATE TABLE AnimalPopulation (AnimalID int,AnimalName varchar(50),Population int,HabitatSize int); INSERT INTO AnimalPopulation (AnimalID,AnimalName,Population,HabitatSize) VALUES (1,'Tiger',2000,300),(2,'Elephant',500,400); CREATE TABLE HabitatPreservation (AnimalID int,HabitatSize int); INSERT INTO HabitatPreservation (AnimalID,HabitatSize) VALUES (1,250),(2,350);
SELECT SUM(AnimalPopulation.HabitatSize) - SUM(HabitatPreservation.HabitatSize) FROM AnimalPopulation, HabitatPreservation;
What is the total amount of donations received by the top 10 refugee camps, ordered from highest to lowest, for the year 2021?
CREATE TABLE refugee_camps (id INT,camp_name TEXT,country TEXT,total_donations DECIMAL(10,2)); INSERT INTO refugee_camps (id,camp_name,country,total_donations) VALUES (1,'Kakuma','Kenya',5000000.00),(2,'Dadaab','Kenya',7000000.00),(3,'Zaatari','Jordan',12000000.00),(4,'Azraq','Jordan',8000000.00);
SELECT SUM(total_donations) as total_donations, camp_name FROM refugee_camps GROUP BY camp_name ORDER BY total_donations DESC LIMIT 10;
List all vehicles exhibited at the Tokyo Auto Show and their safety ratings.
CREATE TABLE AutoShows (Id INT,Name VARCHAR(100),Location VARCHAR(100),StartDate DATE,EndDate DATE); CREATE TABLE Exhibits (Id INT,AutoShowId INT,VehicleId INT,SafetyRating FLOAT); CREATE TABLE Vehicles (Id INT,Name VARCHAR(100),Type VARCHAR(50)); INSERT INTO AutoShows (Id,Name,Location,StartDate,EndDate) VALUES (5,'Tokyo Auto Show','Tokyo','2021-12-10','2021-12-18'); INSERT INTO Exhibits (Id,AutoShowId,VehicleId,SafetyRating) VALUES (6,5,1,4.8),(7,5,2,5.0); INSERT INTO Vehicles (Id,Name,Type) VALUES (1,'Tesla Model S','Electric'),(2,'Toyota Corolla','Gasoline');
SELECT Vehicles.Name, Exhibits.SafetyRating FROM Exhibits INNER JOIN Vehicles ON Exhibits.VehicleId = Vehicles.Id INNER JOIN AutoShows ON Exhibits.AutoShowId = AutoShows.Id WHERE AutoShows.Name = 'Tokyo Auto Show';
List all theater performances with their corresponding funding sources and amounts.
CREATE TABLE theater_performances (performance_id INT,performance_name VARCHAR(50)); CREATE TABLE funding_sources (source_id INT,source_name VARCHAR(50)); CREATE TABLE performance_funding (performance_id INT,source_id INT,amount DECIMAL(5,2)); INSERT INTO theater_performances (performance_id,performance_name) VALUES (1,'The Nutcracker'),(2,'Hamlet'),(3,'Mamma Mia'); INSERT INTO funding_sources (source_id,source_name) VALUES (1,'Government Grant'),(2,'Private Donors'),(3,'Corporate Sponsors'); INSERT INTO performance_funding (performance_id,source_id,amount) VALUES (1,1,10000),(1,2,5000),(2,1,7000),(2,3,15000),(3,2,8000),(3,3,12000);
SELECT p.performance_name, f.source_name, f.amount FROM theater_performances p INNER JOIN performance_funding f ON p.performance_id = f.performance_id INNER JOIN funding_sources fs ON f.source_id = fs.source_id;
List the top 5 states with the lowest mental health parity scores.
CREATE TABLE states (state_id INT,state_name VARCHAR(50),parity_score DECIMAL(3,2)); INSERT INTO states (state_id,state_name,parity_score) VALUES (1,'California',85.2),(2,'New York',82.7),(3,'Texas',78.3),(4,'Florida',76.8),(5,'Illinois',74.5),(6,'Ohio',72.1),(7,'Pennsylvania',71.9),(8,'Georgia',70.6),(9,'North Carolina',69.8),(10,'Michigan',68.2);
SELECT state_name, parity_score FROM states ORDER BY parity_score ASC LIMIT 5;
What are the annual trends of resource depletion for copper and aluminum?
CREATE TABLE resource_depletion (id INT,year INT,resource VARCHAR(50),quantity INT); INSERT INTO resource_depletion (id,year,resource,quantity) VALUES (1,2021,'Copper',1000); INSERT INTO resource_depletion (id,year,resource,quantity) VALUES (2,2021,'Aluminum',2000); INSERT INTO resource_depletion (id,year,resource,quantity) VALUES (3,2022,'Copper',1200); INSERT INTO resource_depletion (id,year,resource,quantity) VALUES (4,2022,'Aluminum',2100);
SELECT year, SUM(CASE WHEN resource = 'Copper' THEN quantity ELSE 0 END) as copper_quantity, SUM(CASE WHEN resource = 'Aluminum' THEN quantity ELSE 0 END) as aluminum_quantity FROM resource_depletion GROUP BY year;
What is the total cost, start year, and end year of infrastructure projects in Chicago and Seattle, grouped by project type?
CREATE TABLE Projects (Id INT,City VARCHAR(50),Type VARCHAR(50),Cost FLOAT,StartYear INT,EndYear INT); INSERT INTO Projects (Id,City,Type,Cost,StartYear,EndYear) VALUES (1,'Chicago','Tunnel',10000000,2005,2010); INSERT INTO Projects (Id,City,Type,Cost,StartYear,EndYear) VALUES (2,'Seattle','Airport',20000000,2012,2017);
SELECT City, Type, SUM(Cost) as Total_Cost, StartYear, EndYear FROM Projects GROUP BY City, Type, StartYear, EndYear;
What is the minimum transaction amount for customers from India?
CREATE TABLE customers (id INT,name VARCHAR(255),country VARCHAR(255)); INSERT INTO customers (id,name,country) VALUES (1,'John Doe','USA'),(2,'Jane Smith','Canada'),(3,'Jim Brown','UK'),(4,'Amit Patel','India'); CREATE TABLE transactions (id INT,customer_id INT,amount DECIMAL(10,2)); INSERT INTO transactions (id,customer_id,amount) VALUES (1,1,1200.00),(2,1,800.00),(3,2,500.00),(4,4,200.00),(5,4,150.00);
SELECT MIN(t.amount) FROM transactions t JOIN customers c ON t.customer_id = c.id WHERE c.country = 'India';
What is the maximum revenue generated by a single stream in the genre of R&B in Canada?
CREATE TABLE streams (id INT,track_id INT,user_id INT,region VARCHAR(255),genre VARCHAR(255),revenue DECIMAL(10,2),timestamp TIMESTAMP);
SELECT MAX(revenue) FROM streams WHERE genre = 'R&B' AND region = 'Canada';
Insert new records into the Menus table for restaurant G with menu items and their prices.
CREATE TABLE Menus (RestaurantID varchar(50),MenuItem varchar(50),Price decimal(10,2));
INSERT INTO Menus (RestaurantID, MenuItem, Price) VALUES ('G', 'Quinoa Salad', 12.99), ('G', 'Tofu Stir Fry', 14.99), ('G', 'Vegan Burger', 13.49), ('G', 'Chickpea Curry', 13.99);
What is the average billing amount for cases handled by male attorneys?
CREATE TABLE attorneys (attorney_id INT,name TEXT,gender TEXT); INSERT INTO attorneys (attorney_id,name,gender) VALUES (1,'Jane Smith','Female'),(2,'Bob Johnson','Male'),(3,'Alex Rodriguez','Male'); CREATE TABLE cases (case_id INT,attorney_id INT,billing_amount INT); INSERT INTO cases (case_id,attorney_id,billing_amount) VALUES (1,1,5000),(2,1,7000),(3,2,6000),(4,3,8000);
SELECT AVG(billing_amount) FROM cases WHERE attorney_id IN (SELECT attorney_id FROM attorneys WHERE gender = 'Male')
List all the wastewater treatment plants in Texas that have had issues with water quality in the past 5 years.
CREATE TABLE wastewater_plants (id INT,name VARCHAR(100),state VARCHAR(20)); CREATE TABLE water_quality_issues (id INT,plant_id INT,issue_date DATE);
SELECT w.name FROM wastewater_plants w INNER JOIN water_quality_issues i ON w.id = i.plant_id WHERE w.state = 'Texas' AND i.issue_date >= DATE(YEAR(CURRENT_DATE) - 5);
What is the total quantity of recycled materials used in production by each company, and what percentage does it represent of their total production?
CREATE TABLE companies (company_id INT,name TEXT);CREATE TABLE production (company_id INT,recycled_qty INT,total_qty INT);
SELECT c.name, SUM(p.recycled_qty) AS total_recycled, (SUM(p.recycled_qty) / SUM(p.total_qty)) * 100 AS pct_of_total FROM companies c INNER JOIN production p ON c.company_id = p.company_id GROUP BY c.name;
What is the earliest launch date of a satellite by India?
CREATE TABLE Satellites (name TEXT,launch_date DATE,country TEXT); INSERT INTO Satellites (name,launch_date,country) VALUES ('GSAT-1','2001-06-18','India'); INSERT INTO Satellites (name,launch_date,country) VALUES ('PSLV-C51','2021-02-28','India');
SELECT MIN(launch_date) FROM Satellites WHERE country = 'India';
What is the percentage of recycled materials used in each product category?
CREATE TABLE Products (id INT,category VARCHAR,material VARCHAR,percentage DECIMAL);
SELECT category, AVG(percentage) as avg_percentage FROM Products WHERE material LIKE '%recycled%' GROUP BY category;
Identify food safety violations in restaurants located in 'New York' and their respective violation counts.
CREATE TABLE Restaurants (RestaurantID int,RestaurantName varchar(50),City varchar(50)); INSERT INTO Restaurants (RestaurantID,RestaurantName,City) VALUES (1,'Fresh Eats','New York'); INSERT INTO Restaurants (RestaurantID,RestaurantName,City) VALUES (2,'Tasty Bites','New York'); CREATE TABLE Inspections (InspectionID int,RestaurantID int,ViolationCount int,InspectionDate date); INSERT INTO Inspections (InspectionID,RestaurantID,ViolationCount,InspectionDate) VALUES (1,1,2,'2021-06-01'); INSERT INTO Inspections (InspectionID,RestaurantID,ViolationCount,InspectionDate) VALUES (2,1,1,'2021-07-15'); INSERT INTO Inspections (InspectionID,RestaurantID,ViolationCount,InspectionDate) VALUES (3,2,3,'2021-05-05');
SELECT R.RestaurantName, I.ViolationCount FROM Restaurants R JOIN Inspections I ON R.RestaurantID = I.RestaurantID WHERE R.City = 'New York';
List all marine protected areas that are in the Eastern Hemisphere.
CREATE TABLE marine_protected_areas (area_name TEXT,longitude DECIMAL(11,8)); INSERT INTO marine_protected_areas (area_name,longitude) VALUES ('Great Barrier Reef',147.75),('Galapagos Islands',-90.81);
SELECT area_name FROM marine_protected_areas WHERE longitude > 0;
What is the total organic certified farmed fish production in the last 3 years in the US?
CREATE TABLE Production(id INT,country VARCHAR(50),year INT,certified BOOLEAN,quantity INT); INSERT INTO Production(id,country,year,certified,quantity) VALUES (1,'US',2019,TRUE,30000),(2,'US',2020,TRUE,35000),(3,'US',2021,TRUE,40000),(4,'US',2019,FALSE,25000),(5,'US',2020,FALSE,28000),(6,'US',2021,FALSE,32000);
SELECT SUM(quantity) FROM Production WHERE country = 'US' AND certified = TRUE AND year BETWEEN 2019 AND 2021;
What is the total CO2 emissions of the food supply chain in the US?
CREATE TABLE emissions (id INT,year INT,country TEXT,co2_emissions INT); INSERT INTO emissions (id,year,country,co2_emissions) VALUES (1,2020,'US',50000);
SELECT SUM(co2_emissions) FROM emissions WHERE country = 'US' AND year = 2020;
List all virtual tours in the United States with their URLs, excluding those in New York.
CREATE TABLE VirtualTours (TourID int,TourName varchar(50),Location varchar(50),URL varchar(100)); INSERT INTO VirtualTours (TourID,TourName,Location,URL) VALUES (1,'Statue of Liberty','New York','https://www.statueoflibertyvirtualtour.com'); INSERT INTO VirtualTours (TourID,TourName,Location,URL) VALUES (2,'Grand Canyon','Arizona','https://www.grandcanyonvirtualtour.com');
SELECT TourName, URL FROM VirtualTours WHERE Location != 'New York' AND Country = 'USA'
What is the name and capacity of the largest hydroelectric power plant in the database?
CREATE TABLE hydroelectric_plants (id INT,name VARCHAR(100),capacity FLOAT,country VARCHAR(50)); INSERT INTO hydroelectric_plants (id,name,capacity,country) VALUES (1,'Hydroelectric Plant 1',1000.5,'Norway'),(2,'Hydroelectric Plant 2',1500.3,'Brazil');
SELECT name, capacity FROM hydroelectric_plants ORDER BY capacity DESC LIMIT 1;
What is the percentage of vegan makeup products?
CREATE TABLE products (product_id INT,vegan BOOLEAN,product_type TEXT); INSERT INTO products (product_id,vegan,product_type) VALUES (1,true,'Makeup'),(2,false,'Skincare'),(3,true,'Makeup');
SELECT (COUNT(*) FILTER (WHERE vegan = true)) * 100.0 / COUNT(*) FROM products WHERE product_type = 'Makeup';
Delete all records of whale sightings in 2021 from the WhaleWatching table.
CREATE TABLE WhaleWatching (id INT,sighting_date DATE,species VARCHAR(20),location VARCHAR(50)); INSERT INTO WhaleWatching (id,sighting_date,species,location) VALUES (1,'2020-08-01','Blue Whale','Pacific Ocean'),(2,'2021-03-15','Humpback Whale','Atlantic Ocean'),(3,'2021-12-30','Orca','Arctic Ocean');
DELETE FROM WhaleWatching WHERE sighting_date >= '2021-01-01' AND sighting_date <= '2021-12-31' AND species LIKE '%Whale%';
What is the total revenue generated from prepaid mobile plans in California for the year 2021?
CREATE TABLE mobile_plans (id INT,plan_type VARCHAR(10),state VARCHAR(20),revenue DECIMAL(10,2));
SELECT SUM(revenue) FROM mobile_plans WHERE plan_type = 'prepaid' AND state = 'California' AND YEAR(order_date) = 2021;
What is the total budget for community education programs?
CREATE VIEW Community_Education AS SELECT 'Future_Guardians' AS program,14000 AS budget UNION SELECT 'Earth_Stewards',16000;
SELECT SUM(budget) FROM Community_Education;
What is the name of the smart contract with the most transactions?
CREATE TABLE transactions (id INT,contract_name TEXT,timestamp TIMESTAMP); INSERT INTO transactions (id,contract_name,timestamp) VALUES (1,'Contract1','2022-01-01 10:00:00'),(2,'Contract1','2022-01-01 12:00:00'),(3,'Contract2','2022-01-01 14:00:00'); CREATE TABLE smart_contracts (id INT,name TEXT); INSERT INTO smart_contracts (id,name) VALUES (1,'Contract1'),(2,'Contract2');
SELECT name FROM smart_contracts JOIN transactions ON smart_contracts.name = transactions.contract_name GROUP BY name ORDER BY COUNT(*) DESC LIMIT 1;
What is the maximum billing amount for cases in the month of April?
CREATE TABLE cases (case_id INT,case_month INT,billing_amount INT);
SELECT MAX(billing_amount) FROM cases WHERE case_month = 4;
What are the top 3 busiest stations in the city?
CREATE TABLE Stations (StationID INT,StationName VARCHAR(50),City VARCHAR(50),DailyPassengers INT); INSERT INTO Stations (StationID,StationName,City,DailyPassengers) VALUES (1,'StationX','CityA',2000),(2,'StationY','CityA',3000),(3,'StationZ','CityB',1500);
SELECT StationName, SUM(DailyPassengers) as TotalPassengers FROM Stations GROUP BY StationName ORDER BY TotalPassengers DESC LIMIT 3;
What is the maximum speed reached during autonomous driving research in each country?
CREATE TABLE Autonomous_Driving_Tests (id INT,vehicle_model VARCHAR(50),test_location VARCHAR(50),max_speed FLOAT);
SELECT test_location, MAX(max_speed) FROM Autonomous_Driving_Tests GROUP BY test_location;
What is the maximum number of vulnerabilities reported in a single day?
CREATE TABLE vulnerabilities (id INT,date DATE,vulnerability VARCHAR(50),frequency INT);
SELECT date, MAX(frequency) FROM vulnerabilities GROUP BY date ORDER BY MAX(frequency) DESC LIMIT 1;
What is the average age of visitors who attended the family day event?
CREATE TABLE Events (id INT,name VARCHAR(20)); INSERT INTO Events (id,name) VALUES (1,'Family Day'); CREATE TABLE Visitor_Events (visitor_id INT,event_id INT); ALTER TABLE Visitors ADD COLUMN age INT;
SELECT AVG(Visitors.age) FROM Visitors JOIN Visitor_Events ON Visitors.id = Visitor_Events.visitor_id JOIN Events ON Visitor_Events.event_id = Events.id WHERE Events.name = 'Family Day';
What is the average number of virtual tour views for hotels in 'Australia'?
CREATE TABLE hotel_views (hotel_id INT,country TEXT,views INT); INSERT INTO hotel_views (hotel_id,country,views) VALUES (1,'Australia',200),(2,'New Zealand',300),(3,'Australia',400),(4,'New Zealand',150),(5,'Australia',50);
SELECT AVG(views) FROM hotel_views WHERE country LIKE 'Australia%';
What is the minimum balance for low-risk accounts in the Europe region?
CREATE TABLE balances (id INT,risk_level VARCHAR(10),region VARCHAR(20),balance DECIMAL(15,2)); INSERT INTO balances (id,risk_level,region,balance) VALUES (1,'high','Africa',200000.00),(2,'medium','Europe',150000.00),(3,'low','North America',100000.00),(4,'high','Asia-Pacific',300000.00);
SELECT MIN(balance) FROM balances WHERE risk_level = 'low' AND region = 'Europe';
Which plants have a CO2 emission rate higher than the average for all plants?
CREATE TABLE co2_emissions (id INT PRIMARY KEY,plant_name VARCHAR(255),chemical_name VARCHAR(255),co2_emission_per_ton_produced DECIMAL(5,2)); INSERT INTO co2_emissions (id,plant_name,chemical_name,co2_emission_per_ton_produced) VALUES (1,'Plant A','Nitric Acid',2.3); INSERT INTO co2_emissions (id,plant_name,chemical_name,co2_emission_per_ton_produced) VALUES (2,'Plant B','Acetic Acid',1.8);
SELECT plant_name FROM co2_emissions GROUP BY plant_name HAVING AVG(co2_emission_per_ton_produced) > (SELECT AVG(co2_emission_per_ton_produced) FROM co2_emissions);
Get the number of users who posted content in each month of 2022, for users in the 'music' network.
CREATE TABLE posts (id INT,user_id INT,timestamp DATETIME,content TEXT,hashtags TEXT); INSERT INTO posts (id,user_id,timestamp,content,hashtags) VALUES (1,1,'2022-01-01 10:00:00','New song out now!',''),(2,2,'2022-02-01 15:00:00','','');
SELECT MONTH(timestamp) AS month, COUNT(DISTINCT user_id) AS user_count FROM posts WHERE network = 'music' AND YEAR(timestamp) = 2022 GROUP BY month;
What is the average water temperature for each species of fish in the aquaculture farms?
CREATE TABLE Farm (FarmID INT,FishSpecies VARCHAR(255),WaterTemperature DECIMAL(5,2)); INSERT INTO Farm (FarmID,FishSpecies,WaterTemperature) VALUES (1,'Tilapia',28.5),(2,'Salmon',12.3),(3,'Tilapia',29.0),(4,'Catfish',24.2);
SELECT FishSpecies, AVG(WaterTemperature) OVER (PARTITION BY FishSpecies) AS AvgWaterTemp FROM Farm;
How many autonomous vehicles have been sold in each state in the autonomousvehiclesales schema?
CREATE TABLE States (id INT,name VARCHAR(50)); CREATE TABLE AutonomousVehiclesSales (id INT,state_id INT,vehicle_id INT,quantity INT,PRIMARY KEY (id),FOREIGN KEY (state_id) REFERENCES States(id)); CREATE TABLE AutonomousVehicles (id INT,make VARCHAR(50),model VARCHAR(50),PRIMARY KEY (id)); CREATE TABLE AutonomousVehicleSales (sales_id INT,vehicle_id INT,PRIMARY KEY (sales_id),FOREIGN KEY (sales_id) REFERENCES AutonomousVehiclesSales(id),FOREIGN KEY (vehicle_id) REFERENCES AutonomousVehicles(id));
SELECT s.name, SUM(avs.quantity) FROM AutonomousVehiclesSales avs JOIN States s ON avs.state_id = s.id JOIN AutonomousVehicleSales av ON avs.sales_id = av.id GROUP BY s.name;
What is the total number of cases handled by each attorney in the last year, and their respective win rates?
CREATE TABLE Attorneys (ID INT,Name VARCHAR(255)); CREATE TABLE Cases (ID INT,AttorneyID INT,Date DATE,Outcome VARCHAR(255)); INSERT INTO Attorneys (ID,Name) VALUES (1,'Alex Garcia'),(2,'Fatima Nguyen'),(3,'Ricardo Mendoza'); INSERT INTO Cases (ID,AttorneyID,Date,Outcome) VALUES (1,1,'2022-01-01','Won'),(2,2,'2022-02-15','Lost'),(3,1,'2022-03-28','Won');
SELECT AttorneyID, COUNT(*) as TotalCases, SUM(CASE WHEN Outcome = 'Won' THEN 1 ELSE 0 END) * 100.0 / COUNT(*) as WinRate FROM Cases WHERE Date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY AttorneyID;
List the number of tourists visiting each country in 2022 and the percentage of female tourists.
CREATE TABLE international_visitors_2022 (id INT,country VARCHAR(50),num_visitors INT); INSERT INTO international_visitors_2022 (id,country,num_visitors) VALUES (1,'France',4000000),(2,'Spain',3500000),(3,'Germany',5000000); CREATE TABLE tourists_demographics (id INT,country VARCHAR(50),gender VARCHAR(50),num_tourists INT); INSERT INTO tourists_demographics (id,country,gender,num_tourists) VALUES (1,'France','Female',2000000),(2,'France','Male',2000000),(3,'Spain','Female',1500000),(4,'Spain','Male',2000000),(5,'Germany','Female',2500000),(6,'Germany','Male',2500000);
SELECT i2022.country, SUM(i2022.num_visitors) AS total_tourists, (SUM(t.female_tourists) / SUM(t.total_tourists)) * 100 AS female_percentage FROM international_visitors_2022 i2022 JOIN ( SELECT country, SUM(num_visitors) AS total_tourists, SUM(CASE WHEN gender = 'Female' THEN num_tourists ELSE 0 END) AS female_tourists FROM tourists_demographics GROUP BY country ) t ON i2022.country = t.country GROUP BY i2022.country;
How many traffic accidents were there in each neighborhood in the last 3 months, grouped by day?
CREATE TABLE neighborhoods (id INT,name TEXT);CREATE TABLE accidents (id INT,neighborhood_id INT,date DATE);
SELECT n.name, DATEADD(day, DATEDIFF(day, 0, a.date), 0) AS truncated_date, COUNT(a.id) FROM neighborhoods n JOIN accidents a ON n.id = a.neighborhood_id WHERE a.date >= DATEADD(month, -3, GETDATE()) GROUP BY n.id, truncated_date ORDER BY truncated_date;
What is the average GRE score for domestic graduate students in the Computer Science department?
CREATE TABLE cs_students (id INT,student_type VARCHAR(10),gre_score INT); INSERT INTO cs_students (id,student_type,gre_score) VALUES (1,'domestic',320),(2,'international',330);
SELECT AVG(gre_score) FROM cs_students WHERE student_type = 'domestic';
What is the minimum age of clients in the 'California' region?
CREATE TABLE clients (id INT,name TEXT,age INT,region TEXT); INSERT INTO clients (id,name,age,region) VALUES (1,'John Doe',35,'California');
SELECT MIN(age) FROM clients WHERE region = 'California';
Show all audience demographics and their corresponding attendance
CREATE TABLE Audience (id INT,name TEXT,age INT,gender TEXT,city TEXT,attendance INT); INSERT INTO Audience (id,name,age,gender,city,attendance) VALUES (1,'John Doe',25,'Male','New York',200),(2,'Jane Smith',35,'Female','Los Angeles',300),(3,'Bob Johnson',45,'Male','Chicago',400);
SELECT * FROM Audience;
How many customers are there from each country?
CREATE TABLE customers (id INT,name TEXT,age INT,country TEXT,assets FLOAT); INSERT INTO customers (id,name,age,country,assets) VALUES (1,'John Doe',45,'USA',250000.00); INSERT INTO customers (id,name,age,country,assets) VALUES (2,'Jane Smith',34,'Canada',320000.00); INSERT INTO customers (id,name,age,country,assets) VALUES (3,'Alice Johnson',29,'USA',750000.00);
SELECT country, COUNT(*) FROM customers GROUP BY country;
What is the average donation amount per country, for countries that have received donations?
CREATE TABLE donations (id INT,country TEXT,amount DECIMAL(10,2)); INSERT INTO donations (id,country,amount) VALUES (1,'Country A',500.00),(2,'Country A',750.00),(3,'Country B',300.00),(4,'Country C',1000.00);
SELECT country, AVG(amount) FROM donations GROUP BY country;
Who are the investors who have not made any investments in the healthcare sector?
CREATE TABLE investments (id INT PRIMARY KEY,investor_id INT,nonprofit_id INT,amount DECIMAL(10,2),investment_date DATE); INSERT INTO investments (id,investor_id,nonprofit_id,amount,investment_date) VALUES (1,1,2,1500.00,'2020-03-01'),(2,2,4,2000.00,'2020-05-01'),(3,3,5,1000.00,'2020-09-01'); CREATE TABLE investors (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255)); INSERT INTO investors (id,name,location) VALUES (1,'Alice','USA'),(2,'Bob','Canada'),(3,'Charlie','UK'); CREATE TABLE nonprofits (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),sector VARCHAR(255)); INSERT INTO nonprofits (id,name,location,sector) VALUES (2,'Doctors Without Borders','Switzerland','Healthcare'),(4,'SolarAid','UK','Renewable Energy'),(5,'WindAid','Peru','Renewable Energy');
SELECT i.id, i.name FROM investors i LEFT JOIN (SELECT investor_id FROM investments WHERE nonprofit_id IN (SELECT id FROM nonprofits WHERE sector = 'Healthcare')) sub ON i.id = sub.investor_id WHERE sub.investor_id IS NULL;
What is the percentage of the population that is vaccinated by ethnicity in rural areas of New Zealand?
CREATE TABLE nz_population (id INT,age INT,location VARCHAR(50),ethnicity VARCHAR(50),vaccinated BOOLEAN); INSERT INTO nz_population (id,age,location,ethnicity,vaccinated) VALUES (1,20,'Rural','Maori',true);
SELECT ethnicity, (SUM(vaccinated_count) * 100.0 / SUM(total_count)) as vaccination_percentage FROM (SELECT ethnicity, SUM(vaccinated) as vaccinated_count, COUNT(*) as total_count FROM nz_population WHERE location = 'Rural' GROUP BY ethnicity) as subquery GROUP BY ethnicity;
What is the total number of military equipment of each type sold and the total quantity sold, ordered by the total quantity sold in descending order?
CREATE TABLE military_sales (id INT PRIMARY KEY,seller VARCHAR(255),buyer VARCHAR(255),equipment_type VARCHAR(255),quantity INT);
SELECT equipment_type, SUM(quantity) FROM military_sales GROUP BY equipment_type ORDER BY SUM(quantity) DESC;
Delete records with a Population less than 1000 from the 'AnimalPopulation' table.
CREATE TABLE AnimalPopulation (AnimalID int,AnimalName varchar(50),Population int); INSERT INTO AnimalPopulation (AnimalID,AnimalName,Population) VALUES (1,'Tiger',2000),(2,'Elephant',500),(3,'Giraffe',1200);
DELETE FROM AnimalPopulation WHERE Population < 1000;
What is the total quantity of mineral extracted for each mine in the first quarter of a specific year?
CREATE TABLE ExtractionData (ExtractionDataID INT,MineID INT,Date DATE,Mineral TEXT,Quantity INT);
SELECT MineID, SUM(Quantity) FROM ExtractionData WHERE Date BETWEEN '2022-01-01' AND '2022-03-31' GROUP BY MineID;
What is the total number of military personnel in Southeast Asia?
CREATE TABLE military_personnel (id INT,country VARCHAR(255),num_personnel INT); INSERT INTO military_personnel (id,country,num_personnel) VALUES (1,'Indonesia',400000); INSERT INTO military_personnel (id,country,num_personnel) VALUES (2,'Vietnam',350000);
SELECT SUM(num_personnel) AS total_personnel FROM military_personnel WHERE country IN ('Indonesia', 'Vietnam', 'Philippines', 'Myanmar', 'Thailand');
What are the details of military operations in the Middle East since 2010?
CREATE TABLE military_operations (id INT,operation_name VARCHAR(50),country VARCHAR(50),start_date DATE,end_date DATE);
SELECT * FROM military_operations WHERE country = 'Middle East' AND start_date >= '2010-01-01';
What is the total number of cases handled by female attorneys?
CREATE TABLE attorney_gender (case_id INT,attorney_gender VARCHAR(50)); INSERT INTO attorney_gender (case_id,attorney_gender) VALUES (1,'female'),(2,'male'),(3,'female');
SELECT COUNT(*) FROM attorney_gender WHERE attorney_gender = 'female';
What is the average age of vessels in the fleet_management table?
CREATE TABLE fleet_management (vessel_id INT,vessel_name VARCHAR(50),launch_date DATE); INSERT INTO fleet_management (vessel_id,vessel_name,launch_date) VALUES (1,'Vessel_A','2015-01-01'),(2,'Vessel_B','2016-01-01'),(3,'Vessel_C','2017-01-01');
SELECT AVG(DATEDIFF(CURDATE(), launch_date) / 365.25) FROM fleet_management;
What is the average data usage for each country's mobile subscribers, ordered from highest to lowest?
CREATE TABLE mobile_subscribers (subscriber_id INT,data_usage FLOAT,country VARCHAR(255)); INSERT INTO mobile_subscribers (subscriber_id,data_usage,country) VALUES (1,5.5,'USA'),(2,3.2,'Canada'),(3,6.1,'Mexico');
SELECT country, AVG(data_usage) as avg_data_usage FROM mobile_subscribers GROUP BY country ORDER BY avg_data_usage DESC;
What was the average number of cybersecurity incidents reported in Canada between 2018 and 2020?
CREATE TABLE canada_cybersecurity_incidents (id INT,year INT,incidents INT); INSERT INTO canada_cybersecurity_incidents (id,year,incidents) VALUES (1,2018,300),(2,2019,450),(3,2020,520);
SELECT AVG(incidents) FROM canada_cybersecurity_incidents WHERE year BETWEEN 2018 AND 2020;
List all Ytterbium suppliers and their respective number of shipments in 2020.
CREATE TABLE ytterbium_suppliers (supplier VARCHAR(50),shipments INT); CREATE TABLE ytterbium_shipments (supplier VARCHAR(50),year INT);
SELECT s.supplier, COUNT(*) FROM ytterbium_shipments sh INNER JOIN ytterbium_suppliers s ON sh.supplier = s.supplier WHERE sh.year = 2020 GROUP BY s.supplier;
How many dolphin sightings were reported in the Mediterranean Sea in 2019?
CREATE TABLE dolphin_sightings (year INT,location TEXT,sightings INT); INSERT INTO dolphin_sightings (year,location,sightings) VALUES (2017,'Mediterranean Sea',120),(2018,'Mediterranean Sea',150),(2019,'Mediterranean Sea',170);
SELECT sightings FROM dolphin_sightings WHERE year = 2019 AND location = 'Mediterranean Sea';
How many art pieces are there in the 'Impressionism' category?
CREATE TABLE ArtPieces (id INT,category VARCHAR(20)); INSERT INTO ArtPieces (id,category) VALUES (1,'Impressionism'),(2,'Cubism'),(3,'Impressionism');
SELECT COUNT(*) FROM ArtPieces WHERE category = 'Impressionism';
Who are the top 3 donors by total donation amount for the 'Health' program?
CREATE TABLE donors (id INT,name VARCHAR(255)); INSERT INTO donors (id,name) VALUES (101,'Alice'),(102,'Bob'),(103,'Charlie'),(104,'David'),(105,'Eve'); CREATE TABLE donations (id INT,donor_id INT,program_id INT,donation_amount DECIMAL(10,2)); INSERT INTO donations (id,donor_id,program_id,donation_amount) VALUES (1,101,2,50.00),(2,102,2,100.00),(3,103,3,75.00),(4,104,4,25.00),(5,105,2,150.00); CREATE TABLE programs (id INT,name VARCHAR(255)); INSERT INTO programs (id,name) VALUES (2,'Health'),(3,'Environment'),(4,'Arts');
SELECT d.donor_id, d.name, SUM(d.donation_amount) as total_donation_amount FROM donations d JOIN donors don ON d.donor_id = don.id WHERE d.program_id = 2 GROUP BY d.donor_id ORDER BY total_donation_amount DESC LIMIT 3;
What is the total number of successful and failed flight tests for each spacecraft manufacturer?
CREATE TABLE Spacecraft (spacecraft_id INT,manufacturer VARCHAR(255),flight_test_result VARCHAR(10)); INSERT INTO Spacecraft (spacecraft_id,manufacturer,flight_test_result) VALUES (1,'AstroSpace','successful'),(2,'Galactic Enterprise','failed'),(3,'AstroSpace','successful'),(4,'Galactic Enterprise','successful');
SELECT manufacturer, COUNT(*) as total_tests, SUM(flight_test_result = 'successful') as successful_tests, SUM(flight_test_result = 'failed') as failed_tests FROM Spacecraft GROUP BY manufacturer;
What is the total amount spent on equipment maintenance, by type, in the 'maintenance_expenses' table?
CREATE TABLE maintenance_expenses (id INT,equipment_type VARCHAR(50),maintenance_date DATE,expense DECIMAL(10,2)); INSERT INTO maintenance_expenses (id,equipment_type,maintenance_date,expense) VALUES (1,'Excavator','2021-03-15',1000.00),(2,'Drill','2021-03-17',750.00),(3,'Excavator','2021-03-20',1200.00);
SELECT equipment_type, SUM(expense) as total_expense FROM maintenance_expenses GROUP BY equipment_type;
What is the total number of cases in the 'civil_cases' and 'criminal_cases' tables?
CREATE TABLE civil_cases (case_id INT,case_name VARCHAR(255),case_status VARCHAR(255)); INSERT INTO civil_cases VALUES (1,'Case A','Open'),(2,'Case B','Closed'); CREATE TABLE criminal_cases (case_id INT,case_name VARCHAR(255),case_status VARCHAR(255)); INSERT INTO criminal_cases VALUES (3,'Case C','In Progress'),(4,'Case D','Closed');
SELECT COUNT(*) FROM civil_cases UNION SELECT COUNT(*) FROM criminal_cases;
What is the average cost of space missions for each country?
CREATE TABLE space_missions (id INT,mission_name VARCHAR(255),country VARCHAR(255),cost FLOAT); INSERT INTO space_missions (id,mission_name,country,cost) VALUES (1,'Apollo 11','USA',25500000),(2,'Mars Orbiter Mission','India',73000000),(3,'Chandrayaan-1','India',79000000),(4,'Grail','USA',496000000);
SELECT country, AVG(cost) as avg_cost FROM space_missions GROUP BY country;
Find the number of aircraft with more than 10000 flight hours for each airline?
CREATE TABLE Aircraft (id INT,tail_number VARCHAR(20),model VARCHAR(100),airline VARCHAR(100),flight_hours DECIMAL(10,2)); INSERT INTO Aircraft (id,tail_number,model,airline,flight_hours) VALUES (5,'N56789','737-800','GreenAirlines',12000.00); INSERT INTO Aircraft (id,tail_number,model,airline,flight_hours) VALUES (6,'N67890','787-900','GreenAirlines',18000.00); INSERT INTO Aircraft (id,tail_number,model,airline,flight_hours) VALUES (7,'N78901','A320-200','YellowAir',9000.00); INSERT INTO Aircraft (id,tail_number,model,airline,flight_hours) VALUES (8,'N89012','A321-200','YellowAir',12000.00);
SELECT airline, COUNT(*) OVER (PARTITION BY airline) as count FROM Aircraft WHERE flight_hours > 10000;
List all marine species with observed population declines.
CREATE TABLE marine_species (id INTEGER,species_name VARCHAR(255),population_trend VARCHAR(255));
SELECT species_name FROM marine_species WHERE population_trend = 'decline';
What is the average revenue of games released in 2021, excluding those that have not been released yet?
CREATE TABLE games (id INT,title VARCHAR(20),release_year INT,revenue INT); INSERT INTO games (id,title,release_year,revenue) VALUES (1,'Galactic Gold',2021,50000000),(2,'Mystic Mayhem',2020,40000000),(3,'Quantum Quandary',2021,60000000),(4,'Retro Rampage',2019,30000000),(5,'Solar System Siege',2021,70000000);
SELECT AVG(games.revenue) FROM games WHERE games.release_year = 2021 AND games.revenue IS NOT NULL;
What are the total annual revenues of the top 2 rare earth element producers?
CREATE TABLE Producers(producer VARCHAR(50),year INT,revenue INT); INSERT INTO Producers(producer,year,revenue) VALUES ('Producer A',2018,100000),('Producer A',2019,120000),('Producer B',2018,110000),('Producer B',2019,130000),('Producer C',2018,90000),('Producer C',2019,100000);
SELECT producer, SUM(revenue) FROM Producers WHERE year = 2019 AND revenue IN (SELECT MAX(revenue) FROM Producers WHERE year = 2019) OR year = 2018 AND revenue IN (SELECT MAX(revenue) FROM Producers WHERE year = 2018) GROUP BY producer;
Delete records in the "equipment" table where the "country" is "China" and the "type" is "drill" that were purchased before 2018
CREATE TABLE equipment (id INT,type VARCHAR(50),country VARCHAR(50),purchase_date DATE); INSERT INTO equipment (id,type,country,purchase_date) VALUES (1,'drill','China','2017-01-01'),(2,'truck','China','2020-01-01');
DELETE FROM equipment WHERE country = 'China' AND type = 'drill' AND purchase_date < '2018-01-01';
List the total duration of each type of workout for members who have used a wearable device for more than 270 days.
CREATE TABLE Workout (id INT,member_id INT,session_start TIMESTAMP,session_end TIMESTAMP); INSERT INTO Workout (id,member_id,session_start,session_end) VALUES (1,1001,'2022-01-01 08:00:00','2022-01-01 09:00:00');
SELECT wt.workout_name, SUM(DATEDIFF('second', session_start, session_end)) as total_duration FROM Workout w JOIN WorkoutSession ws ON w.id = ws.id JOIN Member m ON w.member_id = m.id JOIN WearableDevice wd ON m.id = wd.member_id WHERE DATEDIFF('day', device_start_date, device_end_date) > 270 GROUP BY wt.workout_name;
What are the top 3 countries with the highest total revenue for the "AdventureGames" genre?
CREATE TABLE Games (GameID INT,GameName VARCHAR(255),Genre VARCHAR(255));CREATE TABLE Players (PlayerID INT,PlayerName VARCHAR(255),GameID INT,Spend DECIMAL(10,2));CREATE VIEW Revenue AS SELECT g.Genre,c.Country,SUM(p.Spend) as TotalRevenue FROM Games g JOIN Players p ON g.GameID = p.GameID JOIN (SELECT PlayerID,Country FROM PlayerProfile GROUP BY PlayerID) c ON p.PlayerID = c.PlayerID GROUP BY g.Genre,c.Country;
SELECT Genre, Country, TotalRevenue FROM Revenue WHERE Genre = 'AdventureGames' ORDER BY TotalRevenue DESC LIMIT 3;
Show the customer ratings for products with paraben-free and fragrance-free labels
CREATE TABLE product_labels (product VARCHAR(255),paraben_free BOOLEAN,fragrance_free BOOLEAN,customer_rating DECIMAL(2,1)); INSERT INTO product_labels (product,paraben_free,fragrance_free,customer_rating) VALUES ('Cleanser',TRUE,TRUE,4.2),('Toner',FALSE,TRUE,3.8);
SELECT product, customer_rating FROM product_labels WHERE paraben_free = TRUE AND fragrance_free = TRUE;
How many ocean acidification monitoring stations are there in the Arctic and Antarctic regions?
CREATE TABLE ocean_acidification_monitoring_stations (id INT,name VARCHAR(255),location VARCHAR(255)); INSERT INTO ocean_acidification_monitoring_stations (id,name,location) VALUES (1,'Hans Island Station','Arctic'); INSERT INTO ocean_acidification_monitoring_stations (id,name,location) VALUES (2,'Rothera Station','Antarctic');
SELECT COUNT(*) FROM ocean_acidification_monitoring_stations WHERE location IN ('Arctic', 'Antarctic');
Which countries have manufactured spacecraft using solar panel technology?
CREATE TABLE Spacecraft (SpacecraftID INT,Name VARCHAR(50),ManufacturerCountry VARCHAR(50),LaunchDate DATE,SolarPanel BOOLEAN); INSERT INTO Spacecraft (SpacecraftID,Name,ManufacturerCountry,LaunchDate,SolarPanel) VALUES (1,'Voyager 1','USA','1977-09-05',TRUE); INSERT INTO Spacecraft (SpacecraftID,Name,ManufacturerCountry,LaunchDate,SolarPanel) VALUES (2,'Galileo Orbiter','USA','1989-10-18',TRUE);
SELECT DISTINCT ManufacturerCountry FROM Spacecraft WHERE SolarPanel = TRUE;
Show the total funds allocated to each project in the current year.
CREATE TABLE ProjectFunds (FundID int,ProjectID int,FundsAllocated money,FundDate date);
SELECT ProjectID, SUM(FundsAllocated) as TotalFundsAllocated FROM ProjectFunds WHERE DATEPART(YEAR, FundDate) = DATEPART(YEAR, GETDATE()) GROUP BY ProjectID;
What are the top 5 donors for 'disaster response' sector in Bangladesh in 2018 and the total amount donated by each?
CREATE TABLE donors (id INT,name TEXT,country TEXT); INSERT INTO donors VALUES (1,'USAID','USA'); INSERT INTO donors VALUES (2,'DFID','UK'); CREATE TABLE donations (id INT,donor_id INT,sector TEXT,amount INT,donation_date YEAR); INSERT INTO donations VALUES (1,1,'disaster response',3000,2018);
SELECT d.name, SUM(donations.amount) FROM donations INNER JOIN donors ON donations.donor_id = donors.id WHERE donations.sector = 'disaster response' AND donations.donation_date = 2018 AND donors.country = 'Bangladesh' GROUP BY donations.donor_id ORDER BY SUM(donations.amount) DESC LIMIT 5;
List the genres that have no associated revenue.
CREATE TABLE Genre (Genre VARCHAR(50)); CREATE TABLE GenreRevenue (Genre VARCHAR(50),ReleaseDate DATE,Revenue DECIMAL(10,2)); INSERT INTO Genre (Genre) VALUES ('Pop'); INSERT INTO GenreRevenue (Genre,ReleaseDate,Revenue) VALUES ('Rock','2020-01-01',5000);
SELECT Genre FROM Genre WHERE Genre NOT IN (SELECT Genre FROM GenreRevenue);
Delete all 'Monorail' routes
CREATE TABLE monorail_routes (route_id INT PRIMARY KEY,start_location TEXT,end_location TEXT);
DELETE FROM monorail_routes;
Delete the 'readers' table
CREATE TABLE readers (reader_id INT PRIMARY KEY,age INT,gender VARCHAR(10),location VARCHAR(100));
DROP TABLE readers;
Insert new records for a new research vessel into the 'ResearchVessels' table
CREATE TABLE ResearchVessels (id INT,name VARCHAR(50),type VARCHAR(50),length INT,year INT); INSERT INTO ResearchVessels (id,name,type,length,year) VALUES (1,'Ocean Explorer','Research',100,2010),(2,'Marine Discoverer','Exploration',120,2015),(3,'Sea Surveyor','Survey',90,2005);
INSERT INTO ResearchVessels (id, name, type, length, year) VALUES (4, 'Ocean Odyssey', 'Research', 110, 2018);
How many satellites were launched in 2020?
CREATE TABLE launches (launch_id INT,launch_date DATE); INSERT INTO launches (launch_id,launch_date) VALUES (1,'2020-01-01'),(2,'2019-12-15'),(3,'2021-03-03'); CREATE TABLE satellites (satellite_id INT,launch_id INT,launch_date DATE); INSERT INTO satellites (satellite_id,launch_id,launch_date) VALUES (1,1,'2020-01-01'),(2,2,'2019-12-15'),(3,3,'2021-03-03');
SELECT COUNT(*) FROM satellites WHERE YEAR(launch_date) = 2020;
List the names and measurement types of IoT sensors in the 'PrecisionFarming' schema that have a 'moisture' measurement.
CREATE SCHEMA PrecisionFarming; CREATE TABLE IoT_Sensors (sensor_id INT,sensor_name VARCHAR(50),measurement VARCHAR(50)); INSERT INTO PrecisionFarming.IoT_Sensors (sensor_id,sensor_name,measurement) VALUES (1,'Sensor1','temperature'),(2,'Sensor2','humidity'),(4,'Sensor4','moisture'),(5,'Sensor5','moisture');
SELECT sensor_name, measurement FROM PrecisionFarming.IoT_Sensors WHERE measurement = 'moisture';
List the unique game genres for games designed for non-VR platforms.
CREATE TABLE Games (GameID INT,Name VARCHAR(100),Genre VARCHAR(50),VRPossible BOOLEAN); INSERT INTO Games (GameID,Name,Genre,VRPossible) VALUES (1,'Game1','Action',true),(2,'Game2','Adventure',true),(3,'Game3','Simulation',false),(4,'Game4','Strategy',false),(5,'Game5','Puzzle',false);
SELECT DISTINCT Genre FROM Games WHERE VRPossible = false;
Who are the top 5 users with the most followers who have posted about vegan food in the past month?
CREATE TABLE users (user_id INT,user_name VARCHAR(50),join_date DATE,follower_count INT);CREATE TABLE posts (post_id INT,user_id INT,post_content TEXT,post_date DATE);INSERT INTO users (user_id,user_name,join_date,follower_count) VALUES (1,'user1','2021-01-01',15000),(2,'user2','2021-02-01',12000),(3,'user3','2021-03-01',18000);
SELECT u.user_name, u.follower_count FROM users u JOIN posts p ON u.user_id = p.user_id WHERE p.post_content LIKE '%vegan food%' AND p.post_date >= DATEADD(month, -1, GETDATE()) ORDER BY u.follower_count DESC, u.user_name DESC LIMIT 5;
What is the maximum safety score for models trained on the 'creative_ai' dataset?
CREATE TABLE creative_ai (model_name TEXT,dataset TEXT,safety_score INTEGER); INSERT INTO creative_ai (model_name,dataset,safety_score) VALUES ('model1','creative_ai',85),('model2','creative_ai',92);
SELECT MAX(safety_score) FROM creative_ai WHERE dataset = 'creative_ai';
What is the minimum salary of workers in the aerospace industry by country?
CREATE TABLE AerospaceWorkers (WorkerID INT,Country VARCHAR(50),Salary DECIMAL(10,2)); INSERT INTO AerospaceWorkers (WorkerID,Country,Salary) VALUES (1,'USA',12000),(2,'Canada',13000),(3,'UK',14000);
SELECT Country, MIN(Salary) as MinSalary FROM AerospaceWorkers GROUP BY Country;
Find the total number of transactions processed by Ripple and Stellar networks.
CREATE TABLE transactions (network VARCHAR(255),transaction_count INT); INSERT INTO transactions (network,transaction_count) VALUES ('Ripple',200000); INSERT INTO transactions (network,transaction_count) VALUES ('Stellar',150000);
SELECT SUM(transaction_count) FROM transactions WHERE network IN ('Ripple', 'Stellar');
What is the total number of cases handled by each mediator?
CREATE TABLE mediators (mediator_id INT,name TEXT); INSERT INTO mediators (mediator_id,name) VALUES (1,'John'),(2,'Jane'),(3,'Mike'); CREATE TABLE cases (case_id INT,mediator_id INT,date TEXT); INSERT INTO cases (case_id,mediator_id,date) VALUES (1,1,'2022-01-01'),(2,1,'2022-02-01'),(3,2,'2022-03-01'),(4,3,'2022-04-01');
SELECT mediators.name, COUNT(cases.case_id) as total_cases FROM mediators INNER JOIN cases ON mediators.mediator_id = cases.mediator_id GROUP BY mediators.name;
How many security incidents were recorded in the Asia-Pacific region in the past year?
CREATE TABLE security_incidents (id INT,region TEXT,incident_date DATE); INSERT INTO security_incidents (id,region,incident_date) VALUES (1,'Asia-Pacific','2021-03-01'); INSERT INTO security_incidents (id,region,incident_date) VALUES (2,'Europe','2021-05-15'); INSERT INTO security_incidents (id,region,incident_date) VALUES (3,'Asia-Pacific','2020-12-20');
SELECT COUNT(*) FROM security_incidents WHERE region = 'Asia-Pacific' AND incident_date >= DATEADD(year, -1, GETDATE());
Update the donation amount to $6000 for donor_id 2 in 2020.
CREATE TABLE donors (donor_id INT,donation_amount DECIMAL(10,2),donation_year INT); INSERT INTO donors (donor_id,donation_amount,donation_year) VALUES (1,5000.00,2020),(2,3000.00,2019),(3,7000.00,2020);
UPDATE donors SET donation_amount = 6000 WHERE donor_id = 2 AND donation_year = 2020;
Find the minimum billing rate for attorneys in 'billing' table
CREATE TABLE billing (attorney_id INT,client_id INT,hours_billed INT,billing_rate DECIMAL(5,2));
SELECT MIN(billing_rate) FROM billing;
List the fare types that are not offered on any route starting with 'A'.
CREATE TABLE RouteFares (RouteID int,RouteName varchar(50),FareType varchar(50)); INSERT INTO RouteFares VALUES (1,'Route A1','Standard'); INSERT INTO RouteFares VALUES (1,'Route A1','Discounted'); INSERT INTO RouteFares VALUES (2,'Route A2','Standard'); INSERT INTO RouteFares VALUES (3,'Route B1','Standard'); INSERT INTO RouteFares VALUES (3,'Route B1','Discounted'); INSERT INTO RouteFares VALUES (4,'Route C1','Premium'); INSERT INTO RouteFares VALUES (5,'Route D1','Standard');
SELECT FareType FROM RouteFares WHERE RouteName NOT LIKE 'A%' EXCEPT SELECT FareType FROM RouteFares WHERE RouteName LIKE 'A%';
What is the total quantity of vegan skincare products sold in France and Germany?
CREATE TABLE skincare_sales (product_id INT,product_name VARCHAR(255),sale_quantity INT,is_vegan BOOLEAN,country VARCHAR(255)); CREATE TABLE products (product_id INT,product_name VARCHAR(255),category VARCHAR(255)); INSERT INTO skincare_sales (product_id,product_name,sale_quantity,is_vegan,country) VALUES (1,'Cleanser',100,true,'France'),(2,'Moisturizer',200,false,'Germany'); INSERT INTO products (product_id,product_name,category) VALUES (1,'Cleanser','Skincare'),(2,'Moisturizer','Skincare');
SELECT SUM(skincare_sales.sale_quantity) FROM skincare_sales INNER JOIN products ON skincare_sales.product_id = products.product_id WHERE skincare_sales.is_vegan = true AND (skincare_sales.country = 'France' OR skincare_sales.country = 'Germany') AND products.category = 'Skincare';
Identify the three chemical compounds with the highest water usage per liter of chemical produced and their corresponding ranks.
CREATE TABLE chemical_water_usage (compound_name VARCHAR(50),water_usage FLOAT,liter_of_chemical FLOAT); INSERT INTO chemical_water_usage (compound_name,water_usage,liter_of_chemical) VALUES ('Compound A',15,10),('Compound B',18,10),('Compound C',12,10),('Compound D',14,10),('Compound E',19,10),('Compound F',16,10),('Compound G',13,10),('Compound H',20,10),('Compound I',17,10),('Compound J',11,10);
SELECT compound_name, water_usage, RANK() OVER (ORDER BY water_usage/liter_of_chemical DESC) as water_usage_rank FROM chemical_water_usage WHERE water_usage_rank <= 3;
Create a view named 'marine_protected_areas_view' that includes all records from the 'marine_protected_areas' table.
CREATE VIEW marine_protected_areas_view AS SELECT * FROM marine_protected_areas;
CREATE VIEW marine_protected_areas_view AS SELECT * FROM marine_protected_areas;
How many algorithmic fairness incidents were reported in Oceania in the last month?
CREATE TABLE fairness_incidents (incident_id INT,incident_date DATE,region TEXT); INSERT INTO fairness_incidents (incident_id,incident_date,region) VALUES (1,'2022-06-15','Oceania'),(2,'2022-07-11','Oceania'),(3,'2022-08-01','Oceania');
SELECT COUNT(*) FROM fairness_incidents WHERE region = 'Oceania' AND incident_date >= '2022-07-01' AND incident_date < '2022-08-01';
Find the top 3 countries with the highest solar irradiance?
CREATE TABLE SolarIrradiance (Country VARCHAR(255),AnnualIrradiance FLOAT);
SELECT Country, AnnualIrradiance FROM (SELECT Country, AnnualIrradiance, ROW_NUMBER() OVER(ORDER BY AnnualIrradiance DESC) as rank FROM SolarIrradiance) AS subquery WHERE rank <= 3;
What is the local economic impact of tourism in Paris?
CREATE TABLE cities (city_id INT,city_name TEXT,country TEXT); INSERT INTO cities (city_id,city_name,country) VALUES (1,'Paris','France'); CREATE TABLE tourism_impact (impact_id INT,city_id INT,economic_impact FLOAT); INSERT INTO tourism_impact (impact_id,city_id,economic_impact) VALUES (1,1,1000.0),(2,1,1500.0);
SELECT SUM(economic_impact) FROM tourism_impact WHERE city_id = (SELECT city_id FROM cities WHERE city_name = 'Paris');
What is the total revenue generated from Platinum memberships in the month of January 2022?
CREATE TABLE Memberships (MemberID INT,MembershipType VARCHAR(20),StartDate DATE,EndDate DATE,MonthlyFee DECIMAL(5,2)); INSERT INTO Memberships (MemberID,MembershipType,StartDate,EndDate,MonthlyFee) VALUES (1,'Platinum','2021-12-01','2022-11-30',50.00),(2,'Gold','2022-01-01','2022-12-31',30.00);
SELECT SUM(MonthlyFee) FROM Memberships WHERE MembershipType = 'Platinum' AND StartDate <= '2022-01-31' AND EndDate >= '2022-01-01';