instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
List the top 5 donors by total donation amount in descending order for disaster relief in Haiti.
CREATE TABLE donors (id INT,name TEXT); INSERT INTO donors (id,name) VALUES (1,'John Doe'),(2,'Jane Smith'),(3,'Alice Johnson'),(4,'Bob Williams'),(5,'Charlie Brown'); CREATE TABLE donations (id INT,donor_id INT,amount INT,cause TEXT); INSERT INTO donations (id,donor_id,amount,cause) VALUES (1,1,500,'Disaster relief in Haiti'),(2,1,700,'Community development in India'),(3,2,600,'Disaster relief in Haiti'),(4,3,800,'Disaster relief in Haiti'),(5,4,900,'Community development in India'),(6,5,400,'Disaster relief in Haiti');
SELECT donors.name, SUM(donations.amount) AS total_donation FROM donors INNER JOIN donations ON donors.id = donations.donor_id WHERE donations.cause = 'Disaster relief in Haiti' GROUP BY donors.name ORDER BY total_donation DESC LIMIT 5;
What are the average ingredient costs for halal products?
CREATE TABLE Products (ProductID INT,Halal BOOLEAN,IngredientCost DECIMAL(5,2)); INSERT INTO Products (ProductID,Halal,IngredientCost) VALUES (1,TRUE,16.99),(2,FALSE,11.49),(3,TRUE,13.25);
SELECT AVG(IngredientCost) FROM Products WHERE Halal = TRUE;
Delete the 'peacekeeping_view' view
CREATE VIEW peacekeeping_view AS SELECT operation_id,name,location FROM peacekeeping_operations
DROP VIEW peacekeeping_view
Which production companies are based in the US and have produced both movies and TV shows?
CREATE TABLE movie (id INT,title VARCHAR(100),production_company VARCHAR(50),country VARCHAR(50)); CREATE TABLE tv_show (id INT,title VARCHAR(100),production_company VARCHAR(50),country VARCHAR(50)); INSERT INTO movie (id,title,production_company,country) VALUES (1,'Movie1','ProductionCompany1','USA'); INSERT INTO tv_show (id,title,production_company,country) VALUES (1,'TVShow1','ProductionCompany1','USA');
SELECT production_company FROM movie INNER JOIN tv_show ON movie.production_company = tv_show.production_company WHERE movie.country = 'USA';
Insert a new artist from the Surrealist movement.
CREATE TABLE Artists (ArtistID INT,Name VARCHAR(50),BirthDate DATE,DeathDate DATE,Movement VARCHAR(50)); INSERT INTO Artists (ArtistID,Name,BirthDate,DeathDate,Movement) VALUES (1,'Salvador Dalí','1904-05-11','1989-01-23','Surrealism');
INSERT INTO Artists (ArtistID, Name, BirthDate, DeathDate, Movement) VALUES (2, 'Meret Oppenheim', '1913-10-06', '1985-11-15', 'Surrealism');
Which countries had the highest total donations in 2021 and 2022?
CREATE TABLE Donations (donor_id INT,donation_amount DECIMAL(10,2),donation_year INT,donor_country VARCHAR(50)); INSERT INTO Donations (donor_id,donation_amount,donation_year,donor_country) VALUES (1,5000,2021,'USA'),(2,7000,2021,'Canada'),(3,6000,2022,'Mexico'),(4,8000,2022,'Brazil');
SELECT donor_country, SUM(donation_amount) FROM Donations WHERE donation_year IN (2021, 2022) GROUP BY donor_country ORDER BY SUM(donation_amount) DESC;
Identify customers who made transactions in both New York and London.
CREATE TABLE customer_transactions (customer_id INT,transaction_city VARCHAR(20)); INSERT INTO customer_transactions (customer_id,transaction_city) VALUES (1,'New York'),(2,'London'),(3,'New York'),(4,'Paris'),(5,'London');
SELECT customer_id FROM customer_transactions WHERE transaction_city IN ('New York', 'London') GROUP BY customer_id HAVING COUNT(DISTINCT transaction_city) = 2;
What is the total number of employees who have completed accessibility training in the Midwest region?
CREATE TABLE accessibility_training (region VARCHAR(20),training VARCHAR(30),participants INT); INSERT INTO accessibility_training (region,training,participants) VALUES ('Midwest','Accessibility Training',100); INSERT INTO accessibility_training (region,training,participants) VALUES ('Midwest','Accessibility Training',150); INSERT INTO accessibility_training (region,training,participants) VALUES ('Northeast','Accessibility Training',200);
SELECT region, SUM(participants) FROM accessibility_training WHERE region = 'Midwest' AND training = 'Accessibility Training';
How many patients with depression were treated in India in the last year?
CREATE TABLE patients (patient_id INT,has_depression BOOLEAN,treatment_date DATE); INSERT INTO patients (patient_id,has_depression,treatment_date) VALUES (1,TRUE,'2021-01-01'),(2,FALSE,'2020-12-25'),(3,TRUE,'2022-03-15');
SELECT COUNT(*) FROM patients WHERE has_depression = TRUE AND treatment_date >= '2021-01-01' AND country = 'India';
Which countries have astronauts with the fewest medical issues?
CREATE TABLE AstronautMedicalData (astronaut_name VARCHAR(30),country VARCHAR(20),medical_issues INT); INSERT INTO AstronautMedicalData (astronaut_name,country,medical_issues) VALUES ('Michael Johnson','Canada',1),('Jessica Smith','Australia',1),('Oliver Lee','UK',1);
SELECT country, SUM(medical_issues) as total_issues FROM AstronautMedicalData GROUP BY country ORDER BY total_issues ASC;
List all the drugs and their respective trials for completed trials in the neurology indication.
CREATE TABLE trials (id INT,drug_id INT,start_date DATE,end_date DATE,status VARCHAR(20)); INSERT INTO trials (id,drug_id,start_date,end_date,status) VALUES (1,1,'2020-01-01','2022-12-31','Completed'); CREATE TABLE drugs (id INT,name VARCHAR(50),company VARCHAR(50),indication VARCHAR(50)); INSERT INTO drugs (id,name,company,indication) VALUES (1,'DrugA','ABC Corp','Neurology');
SELECT t.drug_id, d.name, COUNT(*) as trial_count FROM trials t JOIN drugs d ON t.drug_id = d.id WHERE t.status = 'Completed' AND d.indication = 'Neurology' GROUP BY t.drug_id
What is the total number of research grants awarded to female professors in the Art department who have published at least two papers?
CREATE TABLE department (name VARCHAR(255),id INT);CREATE TABLE professor (name VARCHAR(255),gender VARCHAR(255),department_id INT,grant_amount DECIMAL(10,2),publication_year INT);
SELECT COUNT(DISTINCT p.name) FROM professor p WHERE p.gender = 'Female' AND p.department_id IN (SELECT id FROM department WHERE name = 'Art') AND p.publication_year IS NOT NULL GROUP BY p.name HAVING COUNT(p.publication_year) >= 2;
Update the community_policing table and add a new record for neighborhood 'Oakwood' with a score of 85
CREATE TABLE community_policing (neighborhood VARCHAR(255),safety_score INT); INSERT INTO community_policing (neighborhood,safety_score) VALUES ('Pinewood',80),('Elmwood',88),('Maplewood',92);
INSERT INTO community_policing (neighborhood, safety_score) VALUES ('Oakwood', 85);
What is the minimum age of players who participate in esports events?
CREATE TABLE Players (PlayerID INT,Age INT); INSERT INTO Players (PlayerID,Age) VALUES (1,20),(2,25),(3,18),(4,30);
SELECT MIN(Age) FROM Players;
What is the total loan amount disbursed by socially responsible lending organizations in India?
CREATE TABLE tlad_orgs (org_name TEXT,loan_amount NUMERIC); INSERT INTO tlad_orgs (org_name,loan_amount) VALUES ('Socially Responsible India',1000000),('Lending with Care',1500000),('Fair Lending Foundation',800000);
SELECT SUM(loan_amount) FROM tlad_orgs WHERE org_name IN ('Socially Responsible India', 'Lending with Care', 'Fair Lending Foundation') AND country = 'India';
Find the number of vessels and their corresponding safety inspection ratings in the 'vessel_safety' table
CREATE TABLE vessel_safety (id INT,vessel_name VARCHAR(50),safety_rating INT);
SELECT vessel_name, safety_rating FROM vessel_safety;
List the unique court locations where legal aid was provided in Alberta and Manitoba in the last 5 years.
CREATE TABLE legal_aid_alberta (court_location VARCHAR(50),date DATE); INSERT INTO legal_aid_alberta VALUES ('Edmonton','2022-02-01'),('Calgary','2021-06-15'),('Red Deer','2020-09-03'); CREATE TABLE legal_aid_manitoba (court_location VARCHAR(50),date DATE); INSERT INTO legal_aid_manitoba VALUES ('Winnipeg','2022-03-10'),('Brandon','2021-12-20'),('Thompson','2020-07-25');
SELECT DISTINCT court_location FROM legal_aid_alberta WHERE date >= DATE_SUB(CURRENT_DATE, INTERVAL 5 YEAR) UNION ALL SELECT DISTINCT court_location FROM legal_aid_manitoba WHERE date >= DATE_SUB(CURRENT_DATE, INTERVAL 5 YEAR);
What is the average rating of hotels in 'Europe' that have a spa?
CREATE TABLE hotels (id INT,name TEXT,rating FLOAT,country TEXT,has_spa BOOLEAN); INSERT INTO hotels (id,name,rating,country,has_spa) VALUES (1,'Hotel Europa',4.5,'Italy',true),(2,'Paris Palace',4.7,'France',false),(3,'Berlin Spa Resort',4.2,'Germany',true);
SELECT AVG(rating) FROM hotels WHERE country LIKE 'Europe%' AND has_spa = true;
What is the maximum depth of any point in the Indian Ocean?
CREATE TABLE ocean_floors (id INT,region TEXT,point TEXT,depth INT); INSERT INTO ocean_floors (id,region,point,depth) VALUES (1,'Indian Ocean','Java Trench',8075),(2,'Indian Ocean','Sunda Trench',7450);
SELECT MAX(depth) FROM ocean_floors WHERE region = 'Indian Ocean';
Show the average area size for each habitat type in the "habitats" table
CREATE TABLE habitats (habitat_type VARCHAR(255),area_size FLOAT);
SELECT habitat_type, AVG(area_size) as avg_area_size FROM habitats GROUP BY habitat_type;
Find the number of streams for songs with 'love' in the title, for artists from Japan, in descending order by number of streams.
CREATE TABLE songs (id INT,title VARCHAR(255),artist_id INT,streams BIGINT); CREATE TABLE artists (id INT,country VARCHAR(255));
SELECT artist_id, SUM(streams) as total_streams FROM songs INNER JOIN artists ON songs.artist_id = artists.id WHERE title LIKE '%love%' AND country = 'Japan' GROUP BY artist_id ORDER BY total_streams DESC;
How many vessels transported liquefied natural gas in the Caribbean Sea in each month of 2021?
CREATE TABLE VesselTypes (id INT,vessel_type VARCHAR(50),capacity INT); CREATE TABLE CargoTransports (id INT,vessel_id INT,transport_weight INT,transport_time TIMESTAMP);
SELECT EXTRACT(MONTH FROM CT.transport_time) as month, COUNT(DISTINCT CT.vessel_id) as vessels_count FROM CargoTransports CT JOIN VesselTypes VT ON CT.vessel_id = VT.id WHERE VT.vessel_type = 'Liquefied Natural Gas Carrier' AND CT.transport_time > '2021-01-01' AND CT.transport_time < '2022-01-01' AND CT.latitude BETWEEN 10 AND 25 AND CT.longitude BETWEEN -90 AND -55 GROUP BY month;
Count of agricultural projects by funding source
CREATE TABLE agricultural_projects (id INT PRIMARY KEY,name VARCHAR(100),location VARCHAR(50),funding_source VARCHAR(50),start_date DATE,end_date DATE); INSERT INTO agricultural_projects (id,name,location,funding_source,start_date,end_date) VALUES (1,'Solar Powered Irrigation','Rural Kenya','World Bank','2022-01-01','2023-12-31'),(2,'Crop Diversification','Rural Peru','USAID','2022-06-15','2024-06-14'),(3,'Mechanized Farming','Rural India','IFC','2021-09-01','2025-08-31');
SELECT funding_source, COUNT(*) FROM agricultural_projects GROUP BY funding_source;
Who are the top 3 donors from Asian countries?
CREATE TABLE donors (id INT,donor_name VARCHAR(50),donation_amount DECIMAL(10,2),country VARCHAR(50)); INSERT INTO donors (id,donor_name,donation_amount,country) VALUES (1,'Li Mei',800.00,'China'); INSERT INTO donors (id,donor_name,donation_amount,country) VALUES (2,'Raj Patel',900.00,'India');
SELECT donor_name, donation_amount FROM (SELECT donor_name, donation_amount, country, ROW_NUMBER() OVER (PARTITION BY country ORDER BY donation_amount DESC) as rank FROM donors WHERE country IN ('China', 'India', 'Japan', 'South Korea', 'Vietnam')) as donor_ranks WHERE rank <= 3;
Find the minimum depth at which corals are found in the Atlantic Ocean.
CREATE TABLE Coral_Distribution (coral_species text,point_longitude numeric,point_latitude numeric,point_depth numeric);
SELECT MIN(point_depth) FROM Coral_Distribution WHERE coral_species = 'Any Coral Species' AND point_longitude BETWEEN -90 AND -10 AND point_latitude BETWEEN 0 AND 60;
How many properties are there in the 'affordable_housing' table for each city?
CREATE TABLE affordable_housing (id INT,address VARCHAR(255),city VARCHAR(255),state VARCHAR(255)); INSERT INTO affordable_housing (id,address,city,state) VALUES (1,'789 Pine St','Seattle','WA'),(2,'321 Cedar Rd','Seattle','WA'),(3,'543 Elm Ave','Portland','OR');
SELECT city, COUNT(*) FROM affordable_housing GROUP BY city;
Identify the total number of investments in startups founded by BIPOC individuals
CREATE TABLE diversity_metrics (company_name VARCHAR(100),founders_race VARCHAR(50),investments INT);
SELECT SUM(investments) FROM diversity_metrics WHERE founders_race LIKE '%BIPOC%';
How many vessels are currently docked at ports in the Caribbean region?
CREATE TABLE regions (region_id INT,name VARCHAR(255)); INSERT INTO regions (region_id,name) VALUES (1,'Caribbean'); CREATE TABLE ports (port_id INT,name VARCHAR(255),region_id INT); INSERT INTO ports (port_id,name,region_id) VALUES (1,'Caribbean Port 1',1),(2,'Caribbean Port 2',1); CREATE TABLE vessel_status (vessel_id INT,port_id INT,status VARCHAR(255),status_date DATE); INSERT INTO vessel_status (vessel_id,port_id,status,status_date) VALUES (1,1,'Docked','2021-01-01'),(2,1,'Docked','2021-01-02'),(3,2,'Docked','2021-01-01');
SELECT COUNT(DISTINCT vessel_id) FROM vessel_status vs JOIN ports p ON vs.port_id = p.port_id JOIN regions r ON p.region_id = r.region_id WHERE r.name = 'Caribbean' AND vs.status = 'Docked';
Get the conservation status of the bluefin tuna
CREATE TABLE fish_species (species_id INT PRIMARY KEY,species_name VARCHAR(50),conservation_status VARCHAR(20))
SELECT conservation_status FROM fish_species WHERE species_name = 'bluefin tuna'
Update the location of museum stores if they are in the same country as the artist's birthplace
MUSEUM_STORES(store_id,name,location,country_id); ARTIST(artist_id,name,gender,birth_place)
UPDATE MUSEUM_STORES SET location = ar.birth_place FROM MUSEUM_STORES ms INNER JOIN ARTIST ar ON ms.country_id = ar.country_id;
How many players identify as female and have participated in esports events in the last year?
CREATE TABLE Players (PlayerID int,Age int,Gender varchar(10),LastEsportsParticipation date); INSERT INTO Players (PlayerID,Age,Gender,LastEsportsParticipation) VALUES (1,25,'Female','2021-06-01');
SELECT COUNT(*) FROM Players WHERE Gender = 'Female' AND LastEsportsParticipation >= DATEADD(year, -1, GETDATE());
What is the total number of crimes reported in each location in 2021?
CREATE TABLE Crime (cid INT,year INT,category VARCHAR(255),location VARCHAR(255));
SELECT location, COUNT(*) FROM Crime WHERE year = 2021 GROUP BY location;
Show which beauty products have a higher price than the average face cream.
CREATE TABLE BeautyProducts (product_name VARCHAR(100),product_type VARCHAR(50),product_price DECIMAL(10,2)); INSERT INTO BeautyProducts (product_name,product_type,product_price) VALUES ('Brightening Eye Serum','Face Cream',75.00),('Volumizing Shampoo','Shampoo',24.50);
SELECT product_name, product_type, product_price FROM BeautyProducts WHERE product_price > (SELECT AVG(product_price) FROM BeautyProducts WHERE product_type = 'Face Cream');
What is the average amount of copper extracted per year in the state "Arizona" in the period 2015-2020?
CREATE TABLE copper_extraction (id INT,mine TEXT,state TEXT,country TEXT,year INT,amount INT); INSERT INTO copper_extraction (id,mine,state,country,year,amount) VALUES (1,'Copper Mine 1','Arizona','United States',2015,500); INSERT INTO copper_extraction (id,mine,state,country,year,amount) VALUES (2,'Copper Mine 2','Arizona','United States',2016,600);
SELECT AVG(amount) FROM copper_extraction WHERE state = 'Arizona' AND country = 'United States' AND year BETWEEN 2015 AND 2020;
What are the total number of agricultural innovation projects in the 'rural_infrastructure' and 'community_development' tables?
CREATE TABLE rural_infrastructure (id INT,project_name VARCHAR(50),project_type VARCHAR(50),location VARCHAR(50),cost DECIMAL(10,2)); INSERT INTO rural_infrastructure VALUES (1,'Solar Irrigation System','Agricultural Innovation','Village A',25000.00); CREATE TABLE community_development (id INT,project_name VARCHAR(50),project_type VARCHAR(50),location VARCHAR(50),cost DECIMAL(10,2)); INSERT INTO community_development VALUES (1,'Community Center','Community Development','Village A',15000.00),(2,'Green Spaces','Community Development','Village B',10000.00);
SELECT COUNT(*) FROM (SELECT * FROM rural_infrastructure WHERE project_type = 'Agricultural Innovation' UNION ALL SELECT * FROM community_development WHERE project_type = 'Agricultural Innovation') AS combined_projects;
Rank policies for a system based on their last update date.
CREATE TABLE policies (id INT,policy_id TEXT,system TEXT,description TEXT,last_updated DATE);INSERT INTO policies (id,policy_id,system,description,last_updated) VALUES (1,'PS-001','firewall','Block all incoming traffic','2021-01-03');
SELECT policy_id, system, description, last_updated, RANK() OVER (PARTITION BY system ORDER BY last_updated DESC) as rank FROM policies WHERE system = 'firewall';
What is the total revenue generated from art sales at the "Metropolitan Museum" in 2022?
CREATE TABLE ArtSales4 (MuseumName TEXT,SaleDate DATE,NumPieces INTEGER,PricePerPiece FLOAT); INSERT INTO ArtSales4 (MuseumName,SaleDate,NumPieces,PricePerPiece) VALUES ('Metropolitan Museum','2022-01-01',5,100.5),('Metropolitan Museum','2022-02-15',8,120.0),('Metropolitan Museum','2022-04-20',12,150.0);
SELECT SUM(NumPieces * PricePerPiece) FROM ArtSales4 WHERE MuseumName = 'Metropolitan Museum' AND YEAR(SaleDate) = 2022;
What is the total number of students who have ever enrolled in a course offered by each department?
CREATE TABLE departments (department_id INT,department_name TEXT); CREATE TABLE courses (course_id INT,course_name TEXT,department_id INT); CREATE TABLE enrollments (enrollment_id INT,student_id INT,course_id INT,enrollment_date DATE); INSERT INTO departments VALUES (1,'Mathematics'),(2,'Science'),(3,'English'); INSERT INTO courses VALUES (1,'Algebra I',1),(2,'Geometry',2),(3,'Algebra II',1),(4,'Biology',2),(5,'English Composition',3); INSERT INTO enrollments VALUES (1,1,1,'2021-08-01'),(2,2,1,'2021-08-01'),(3,3,2,'2021-08-01'),(4,4,2,'2021-08-01'),(5,5,3,'2021-08-01');
SELECT d.department_name, COUNT(DISTINCT e.student_id) FROM departments d INNER JOIN courses c ON d.department_id = c.department_id INNER JOIN enrollments e ON c.course_id = e.course_id GROUP BY d.department_id;
What's the total energy production from solar projects?
CREATE TABLE solar_projects (id INT,name VARCHAR(255),energy_production FLOAT);
SELECT SUM(energy_production) FROM solar_projects;
What are the names of aquatic farms in the 'Caribbean Sea' region?
CREATE TABLE aquatic_farms (id INT,name TEXT,region TEXT); INSERT INTO aquatic_farms (id,name,region) VALUES (1,'Farm A','Caribbean Sea'),(2,'Farm B','Atlantic Ocean'),(3,'Farm C','Caribbean Sea');
SELECT DISTINCT aquatic_farms.name FROM aquatic_farms WHERE aquatic_farms.region = 'Caribbean Sea';
What is the average torque of electric vehicles, partitioned by vehicle make?
CREATE TABLE vehicles (vehicle_id INT,vehicle_make VARCHAR(20),torque FLOAT); INSERT INTO vehicles (vehicle_id,vehicle_make,torque) VALUES (1,'Tesla',443),(2,'Tesla',431),(3,'Rivian',405),(4,'Rivian',418),(5,'Fisker',310);
SELECT vehicle_make, AVG(torque) avg_torque FROM vehicles WHERE vehicle_make IN ('Tesla', 'Rivian', 'Fisker') GROUP BY vehicle_make;
What is the average ticket price for each event hosted by the 'NBA'?
CREATE TABLE Events (event_id INT,event_name VARCHAR(255),team VARCHAR(255),price DECIMAL(5,2)); INSERT INTO Events VALUES (1,'Game 1','NBA',150.00),(2,'Game 2','NBA',160.00);
SELECT event_name, AVG(price) FROM Events WHERE team = 'NBA' GROUP BY event_name;
What are the names and languages of all endangered language programs in Africa, sorted by the number of speakers?
CREATE TABLE Endangered_Languages (Language_Name VARCHAR(50),Country VARCHAR(50),Number_Speakers INT); INSERT INTO Endangered_Languages (Language_Name,Country,Number_Speakers) VALUES ('Tigrinya','Eritrea',2000000),('Amharic','Ethiopia',21000000),('Zulu','South Africa',12000000);
SELECT Language_Name, Country, Number_Speakers FROM Endangered_Languages WHERE Country IN ('Eritrea', 'Ethiopia', 'South Africa') ORDER BY Number_Speakers DESC;
Calculate the average number of steps taken per day for all users in the last week?
CREATE TABLE steps_data (id INT,user_id INT,steps INT,date DATE);
SELECT AVG(steps) FROM steps_data WHERE date >= DATE(NOW()) - INTERVAL 1 WEEK GROUP BY date;
What is the total number of artworks donated by individual donors, and their respective donation dates, sorted by the earliest donation date?
CREATE TABLE Donations (donor_id INT,artwork_id INT,donation_date DATE); INSERT INTO Donations (donor_id,artwork_id,donation_date) VALUES (1,101,'2020-01-01'),(2,105,'2019-12-01'),(1,201,'2020-02-01'),(3,303,'2018-05-15');
SELECT donor_id, COUNT(artwork_id) AS total_artworks, MIN(donation_date) AS earliest_donation_date FROM Donations GROUP BY donor_id ORDER BY earliest_donation_date;
What is the average donation amount for each non-social cause category?
CREATE TABLE donations (id INT,donor_id INT,amount DECIMAL(10,2),cause_id INT); INSERT INTO donations (id,donor_id,amount,cause_id) VALUES (1,1,500.00,3),(2,1,300.00,3),(3,2,250.00,4),(4,2,400.00,4),(5,3,100.00,3),(6,4,700.00,4),(7,5,1200.00,3);
SELECT c.type, AVG(d.amount) FROM donations d JOIN causes c ON d.cause_id = c.id GROUP BY c.type HAVING c.type != 'Social';
Which rural infrastructure projects were initiated in Mexico's rural areas between 2012 and 2015, and what was their combined budget?
CREATE TABLE rural_infrastructure (project VARCHAR(50),country VARCHAR(50),start_year INT,end_year INT,budget FLOAT); INSERT INTO rural_infrastructure (project,country,start_year,end_year,budget) VALUES ('Rural Electrification','Mexico',2012,2015,30000000),('Rural Water Supply','Mexico',2012,2015,40000000);
SELECT project, SUM(budget) FROM rural_infrastructure WHERE country = 'Mexico' AND start_year BETWEEN 2012 AND 2015 AND end_year BETWEEN 2012 AND 2015 GROUP BY project;
What was the total cost of agricultural innovation projects in the 'Latin America' region for the year 2019, grouped by project_type?
CREATE TABLE agricultural_innovation (id INT,project_name VARCHAR(100),project_location VARCHAR(100),project_type VARCHAR(50),project_status VARCHAR(50),total_cost FLOAT,start_date DATE,end_date DATE);
SELECT project_type, SUM(total_cost) FROM agricultural_innovation WHERE project_location LIKE 'Latin%' AND YEAR(start_date) = 2019 GROUP BY project_type;
How many factories in the United States have implemented industry 4.0 technologies in the past 5 years?
CREATE TABLE factories (id INT,name VARCHAR(50),country VARCHAR(50),industry4 INT,year INT);
SELECT COUNT(*) FROM factories WHERE country = 'United States' AND industry4 = 1 AND year BETWEEN 2017 AND 2021;
List clients with more than 15 hours of billing in the 'billing' table?
CREATE TABLE billing (attorney_id INT,client_id INT,hours FLOAT,rate FLOAT); INSERT INTO billing (attorney_id,client_id,hours,rate) VALUES (1,101,10,300),(2,102,8,350),(3,103,12,250);
SELECT client_id, SUM(hours) FROM billing GROUP BY client_id HAVING SUM(hours) > 15;
What is the total quantity of kosher products sold in New York in the last week?
CREATE TABLE Products (ProductID INT,ProductName VARCHAR(50),SupplierID INT,Category VARCHAR(50),IsKosher BOOLEAN,Price DECIMAL(5,2)); INSERT INTO Products (ProductID,ProductName,SupplierID,Category,IsKosher,Price) VALUES (1,'Kosher Chicken',1,'Meat',true,12.99); CREATE TABLE Orders (OrderID INT,ProductID INT,Quantity INT,OrderDate DATE,CustomerLocation VARCHAR(50)); INSERT INTO Orders (OrderID,ProductID,Quantity,OrderDate,CustomerLocation) VALUES (1,1,20,'2022-04-01','New York');
SELECT SUM(Quantity) FROM Orders JOIN Products ON Orders.ProductID = Products.ProductID WHERE Products.IsKosher = true AND CustomerLocation = 'New York' AND Orders.OrderDate >= DATEADD(WEEK, -1, GETDATE());
How many donors from each country donated in 2022?
CREATE TABLE donors (donor_id INT,donation_date DATE,donation_amount DECIMAL(10,2),country VARCHAR(50)); INSERT INTO donors VALUES (1,'2022-01-01',50.00,'USA'),(2,'2022-01-15',100.00,'Canada'),(3,'2022-03-05',200.00,'Mexico');
SELECT country, COUNT(DISTINCT donor_id) FROM donors WHERE donation_date BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY country;
What is the total fairness score for each AI model, grouped by model type?
CREATE TABLE fairness_scores (score_id INT PRIMARY KEY,model_id INT,score_date DATE,model_type VARCHAR(50),fairness_score FLOAT); INSERT INTO fairness_scores (score_id,model_id,score_date,model_type,fairness_score) VALUES (1,1,'2021-01-01','Deep Learning',0.75),(2,2,'2021-02-01','Tree Based',0.87),(3,1,'2021-03-01','Deep Learning',0.82),(4,3,'2021-04-01','Logistic Regression',0.91),(5,2,'2021-05-01','Tree Based',0.95);
SELECT model_type, AVG(fairness_score) FROM fairness_scores GROUP BY model_type;
Show the number of satellites in each type of orbit
CREATE TABLE satellites_by_country (satellite_id INT,country VARCHAR(50),orbit_type VARCHAR(50)); INSERT INTO satellites_by_country (satellite_id,country,orbit_type) VALUES (1,'USA','Geostationary'); INSERT INTO satellites_by_country (satellite_id,country,orbit_type) VALUES (2,'Russia','Low Earth Orbit'); INSERT INTO satellites_by_country (satellite_id,country,orbit_type) VALUES (3,'China','Geostationary');
SELECT orbit_type, COUNT(*) as num_satellites FROM satellites_by_country GROUP BY orbit_type;
What is the average delivery time for shipments from 'Frankfurt' to 'Chicago'?
CREATE TABLE Shipments (ID INT,Origin VARCHAR(50),Destination VARCHAR(50),DeliveryTime INT); INSERT INTO Shipments (ID,Origin,Destination,DeliveryTime) VALUES (1,'Frankfurt','Chicago',5),(2,'London','New York',7),(3,'Brazil','India',10);
SELECT AVG(Shipments.DeliveryTime) FROM Shipments WHERE Shipments.Origin = 'Frankfurt' AND Shipments.Destination = 'Chicago';
What is the second largest property size in New York?
CREATE TABLE properties (id INT,size FLOAT,city VARCHAR(20)); INSERT INTO properties (id,size,city) VALUES (1,1500,'New York'),(2,2000,'New York'),(3,1000,'New York');
SELECT size FROM (SELECT size, ROW_NUMBER() OVER (ORDER BY size DESC) as rn FROM properties WHERE city = 'New York') t WHERE rn = 2;
Insert a new virtual tourism event in Japan with 20000 visitors.
CREATE TABLE events (id INT,name TEXT,country TEXT,visitors INT);
INSERT INTO events (name, country, visitors) VALUES ('Virtual Tourism Japan', 'Japan', 20000);
Delete records with a maintenance cost greater than $50,000 in the 'military_equipment' table
CREATE TABLE military_equipment (equipment_id INT,equipment_name VARCHAR(255),maintenance_cost FLOAT); INSERT INTO military_equipment (equipment_id,equipment_name,maintenance_cost) VALUES (1,'Tank A',45000.00),(2,'Helicopter B',62000.00),(3,'Jet C',38000.00);
DELETE FROM military_equipment WHERE maintenance_cost > 50000;
What is the average market price of neodymium produced in Australia over the last 5 years?
CREATE TABLE neodymium_prices (year INT,country TEXT,price DECIMAL(10,2)); INSERT INTO neodymium_prices (year,country,price) VALUES (2017,'Australia',85.5),(2018,'Australia',88.3),(2019,'Australia',91.7),(2020,'Australia',95.2),(2021,'Australia',100.5);
SELECT AVG(price) FROM neodymium_prices WHERE country = 'Australia' AND year >= 2017;
What is the percentage of water treatment plants in the 'Coastal' region that have a water treatment capacity of less than 30,000 cubic meters?
CREATE TABLE WaterTreatmentPlants (id INT,plant_name VARCHAR(50),region VARCHAR(50),total_capacity INT); INSERT INTO WaterTreatmentPlants (id,plant_name,region,total_capacity) VALUES (1,'Plant A','Coastal',25000),(2,'Plant B','Inland',35000),(3,'Plant C','Coastal',45000),(4,'Plant D','Coastal',15000),(5,'Plant E','Inland',55000);
SELECT (COUNT(*) / (SELECT COUNT(*) FROM WaterTreatmentPlants WHERE region = 'Coastal') * 100) FROM WaterTreatmentPlants WHERE region = 'Coastal' AND total_capacity < 30000;
List all financial institutions that offer both Shariah-compliant and conventional loans.
CREATE TABLE financial_institutions (id INT,name VARCHAR(255),type VARCHAR(255),location VARCHAR(255)); INSERT INTO financial_institutions (id,name,type,location) VALUES (1,'ABC Bank','Islamic','India'); INSERT INTO financial_institutions (id,name,type,location) VALUES (2,'Islamic Bank','Conventional','UAE'); INSERT INTO financial_institutions (id,name,type,location) VALUES (3,'XYZ Bank','Islamic','Saudi Arabia'); CREATE TABLE loans (id INT,institution_id INT,type VARCHAR(255),amount DECIMAL(10,2),date DATE); INSERT INTO loans (id,institution_id,type,amount,date) VALUES (1,1,'Islamic',5000.00,'2022-01-01'); INSERT INTO loans (id,institution_id,type,amount,date) VALUES (2,1,'Conventional',6000.00,'2022-01-02'); INSERT INTO loans (id,institution_id,type,amount,date) VALUES (3,2,'Conventional',7000.00,'2022-01-03'); INSERT INTO loans (id,institution_id,type,amount,date) VALUES (4,3,'Islamic',8000.00,'2022-01-04');
SELECT name FROM financial_institutions WHERE id IN (SELECT institution_id FROM loans WHERE type = 'Islamic') AND id IN (SELECT institution_id FROM loans WHERE type = 'Conventional');
What is the total budget for each community engagement event at the specified language preservation program?
CREATE TABLE LanguagePreservationEvents (id INT,event VARCHAR(255),budget DECIMAL(10,2),program VARCHAR(255)); INSERT INTO LanguagePreservationEvents (id,event,budget,program) VALUES (1,'Maori Language Course',12000,'New Zealand'),(2,'Aboriginal Language Workshop',15000,'Australia'),(3,'Pacific Islander Language Symposium',9000,'Fiji');
SELECT event, SUM(budget) as total_budget FROM LanguagePreservationEvents WHERE program = 'New Zealand' GROUP BY event;
What is the maximum number of animals in the "HabitatPreservation" view that share the same habitat?
CREATE VIEW HabitatPreservation AS SELECT habitat_id,animal_id FROM AnimalHabitats; INSERT INTO AnimalHabitats (habitat_id,animal_id) VALUES (1,1),(1,2),(2,3),(3,4),(3,5),(4,6);
SELECT MAX(habitat_count) FROM (SELECT habitat_id, COUNT(DISTINCT animal_id) AS habitat_count FROM HabitatPreservation GROUP BY habitat_id) AS subquery;
What is the total defense spending for each branch?
CREATE TABLE defense_spending_branches (branch VARCHAR(50),spending NUMERIC(10,2)); INSERT INTO defense_spending_branches (branch,spending) VALUES ('Army',2000000000),('Navy',3000000000),('Air Force',4000000000),('Marines',1000000000);
SELECT branch, spending FROM defense_spending_branches;
What was the maximum price for any Abstract Expressionist pieces sold in any year?
CREATE TABLE art_pieces (id INT,artist VARCHAR(30),style VARCHAR(20),year_sold INT,price DECIMAL(10,2)); CREATE VIEW abstract_expressionist_sales AS SELECT style,MAX(price) AS max_price FROM art_pieces GROUP BY style;
SELECT style, max_price FROM abstract_expressionist_sales WHERE style = 'Abstract Expressionist';
Delete all records from the disaster_preparedness table where the 'equipment_type' column is 'Communication Equipment' and the 'status' column is 'Out_of_Service'?
CREATE TABLE disaster_preparedness (id INT,equipment_type VARCHAR(255),status VARCHAR(255)); INSERT INTO disaster_preparedness (id,equipment_type,status) VALUES (1,'Communication Equipment','Out_of_Service'),(2,'Generator','Functional'),(3,'Communication Equipment','Functional');
DELETE FROM disaster_preparedness WHERE equipment_type = 'Communication Equipment' AND status = 'Out_of_Service';
How many suppliers from Asia have a sustainability rating greater than 4?
CREATE TABLE suppliers (supplier_id INT,supplier_name VARCHAR(100),country VARCHAR(50),sustainability_rating INT); INSERT INTO suppliers (supplier_id,supplier_name,country,sustainability_rating) VALUES (1,'Supplier A','China',5),(2,'Supplier B','Japan',3),(3,'Supplier C','India',4);
SELECT COUNT(*) FROM suppliers WHERE country LIKE 'Asia%' AND sustainability_rating > 4;
What is the minimum age of residents who have participated in civic engagement activities?
CREATE TABLE resident (id INT PRIMARY KEY,name TEXT,age INT,city_id INT,gender TEXT,civic_participation BOOLEAN,FOREIGN KEY (city_id) REFERENCES city(id));
SELECT MIN(age) FROM resident WHERE civic_participation = TRUE;
Which genetic research projects in Canada have biosensor technology as a component?
CREATE TABLE research_projects (id INT,name TEXT,country TEXT,components TEXT); INSERT INTO research_projects (id,name,country,components) VALUES (1,'GenoMaple','Canada','Biosensor,Sequencing');
SELECT name FROM research_projects WHERE country = 'Canada' AND components LIKE '%Biosensor%';
What community initiatives related to health were active between January 2020 and December 2021?
CREATE TABLE CommunityInitiatives (id INT PRIMARY KEY,name VARCHAR(50),location VARCHAR(50),type VARCHAR(20),start_date DATE,end_date DATE); INSERT INTO CommunityInitiatives (id,name,location,type,start_date,end_date) VALUES (1,'Local Health Clinic','Rural Vietnam','Healthcare','2020-02-01','2021-12-31'),(2,'Nutrition Education','Rural Guatemala','Health Education','2021-03-01','2022-12-31');
SELECT name, location, type FROM CommunityInitiatives WHERE start_date <= '2020-12-31' AND end_date >= '2020-01-01' AND type = 'Healthcare';
What is the total fare collected on each route, grouped by day of the week?
CREATE TABLE routes (route_id INT,route_name TEXT);CREATE TABLE fares (fare_id INT,route_id INT,fare DECIMAL,fare_date DATE); INSERT INTO routes VALUES (123,'Route 123'); INSERT INTO routes VALUES (456,'Route 456'); INSERT INTO fares VALUES (1,123,2.5,'2022-01-01'); INSERT INTO fares VALUES (2,123,2.5,'2022-01-01'); INSERT INTO fares VALUES (3,456,3.0,'2022-01-02'); INSERT INTO fares VALUES (4,456,3.0,'2022-01-02'); INSERT INTO fares VALUES (5,456,3.0,'2022-01-02');
SELECT routes.route_name, DATE_FORMAT(fares.fare_date, '%W') as day_of_week, SUM(fares.fare) FROM routes INNER JOIN fares ON routes.route_id = fares.route_id GROUP BY routes.route_name, day_of_week;
What is the total cargo weight loaded in the Brazilian region?
CREATE TABLE CargoTracking (CargoID INT,LoadDate DATE,LoadLocation VARCHAR(50),CargoWeight INT); INSERT INTO CargoTracking (CargoID,LoadDate,LoadLocation,CargoWeight) VALUES (1,'2021-01-01','Sao Paulo',850),(2,'2021-02-15','Rio de Janeiro',900),(3,'2021-12-31','Brasilia',750);
SELECT SUM(CargoWeight) FROM CargoTracking WHERE LoadLocation LIKE 'Brazil%';
What is the total number of factories in the industry 4.0 sector that have implemented automation technologies and have a workforce diversity score above 80?
CREATE TABLE factories (factory_id INT,sector VARCHAR(255),has_automation BOOLEAN,workforce_diversity_score INT); INSERT INTO factories (factory_id,sector,has_automation,workforce_diversity_score) VALUES (1,'Industry 4.0',TRUE,85),(2,'Industry 4.0',TRUE,70),(3,'Industry 4.0',FALSE,90);
SELECT COUNT(*) FROM factories WHERE sector = 'Industry 4.0' AND has_automation = TRUE AND workforce_diversity_score > 80;
How many users in Canada and Mexico had their data privacy settings changed in Q2 2023?
CREATE SCHEMA socialmedia;CREATE TABLE user_settings (id INT,user_id INT,setting VARCHAR(255),timestamp TIMESTAMP,country VARCHAR(255));INSERT INTO user_settings (id,user_id,setting,timestamp,country) VALUES (1,1,'privacy','2023-04-01 12:00:00','Canada'),(2,2,'privacy','2023-05-15 15:00:00','Mexico');
SELECT SUM(CASE WHEN country = 'Canada' THEN 1 ELSE 0 END + CASE WHEN country = 'Mexico' THEN 1 ELSE 0 END) FROM socialmedia.user_settings WHERE setting = 'privacy' AND EXTRACT(YEAR FROM timestamp) = 2023 AND EXTRACT(QUARTER FROM timestamp) = 2;
Delete vehicle maintenance records for vehicle 103
CREATE TABLE vehicle_maintenance (id INT,vehicle_id INT,type TEXT,scheduled_time TIMESTAMP);
WITH cte AS (DELETE FROM vehicle_maintenance WHERE vehicle_id = 103 RETURNING id) SELECT * FROM cte;
What is the minimum risk score for ESG factors in Latin America?
CREATE TABLE esg_factors (id INT,risk_score INT,region VARCHAR(50)); INSERT INTO esg_factors (id,risk_score,region) VALUES (1,3,'Latin America'),(2,5,'North America'),(3,4,'Latin America');
SELECT MIN(risk_score) FROM esg_factors WHERE region = 'Latin America';
What was the total number of visitors from each continent in 2022?
CREATE TABLE if not exists VisitorContinents (Continent VARCHAR(50),Country VARCHAR(50),Visitors INT); INSERT INTO VisitorContinents (Continent,Country,Visitors) VALUES ('Africa','Egypt',110000),('Asia','Japan',220000),('Europe','France',330000),('South America','Brazil',130000),('North America','Canada',160000),('Oceania','Australia',260000);
SELECT a.Continent, SUM(a.Visitors) AS TotalVisitors FROM VisitorContinents a WHERE a.Year = 2022 GROUP BY a.Continent;
How many volunteers participated in each program in 2021?
CREATE TABLE VolunteerPrograms (VolunteerID INT,ProgramID INT,Hours INT,VolunteerDate DATE); INSERT INTO VolunteerPrograms VALUES (1,1,4,'2021-01-01'),(2,1,6,'2021-02-01'),(3,2,8,'2021-03-01');
SELECT ProgramID, COUNT(DISTINCT VolunteerID) FROM VolunteerPrograms WHERE YEAR(VolunteerDate) = 2021 GROUP BY ProgramID;
What is the average size of urban farms in hectares, grouped by continent, and only considering farms with more than 100 farms?
CREATE TABLE urban_farms (id INT,name VARCHAR(255),size FLOAT,continent VARCHAR(255)); INSERT INTO urban_farms (id,name,size,continent) VALUES (1,'Farm A',1.2,'Africa'),(2,'Farm B',2.0,'Asia'),(3,'Farm C',0.5,'South America');
SELECT continent, AVG(size) as avg_size FROM urban_farms GROUP BY continent HAVING COUNT(*) > 100;
Show the number of properties in each price range
CREATE TABLE price_ranges (price_range_id INT PRIMARY KEY,price_from DECIMAL(10,2),price_to DECIMAL(10,2)); INSERT INTO price_ranges (price_range_id,price_from,price_to) VALUES (1,0,200000),(2,200001,500000),(3,500001,1000000);
SELECT price_ranges.price_range_id, COUNT(properties.property_id) FROM properties JOIN price_ranges ON properties.property_price BETWEEN price_ranges.price_from AND price_ranges.price_to GROUP BY price_ranges.price_range_id;
Insert a new record into the emergency_response table for the 'Fire' incident type and a response_time of 4 minutes
CREATE TABLE emergency_response (incident_type VARCHAR(255),response_time INT);
INSERT INTO emergency_response (incident_type, response_time) VALUES ('Fire', 4);
What is the earliest date an article was published in the 'investigations' category?
CREATE TABLE articles (id INT,title TEXT,publish_date DATE,category TEXT); INSERT INTO articles (id,title,publish_date,category) VALUES ('1','Article 1','2021-01-01','investigations'),('2','Article 2','2022-03-15','news'),('3','Article 3','2020-12-25','investigations');
SELECT MIN(publish_date) FROM articles WHERE category = 'investigations';
Determine the number of sustainable items in each size
CREATE TABLE sizes (id INT,size VARCHAR(10)); INSERT INTO sizes (id,size) VALUES (1,'XS'),(2,'S'),(3,'M'),(4,'L'),(5,'XL'); CREATE TABLE inventory (id INT,item_name VARCHAR(20),size_id INT,is_sustainable BOOLEAN,quantity INT); INSERT INTO inventory (id,item_name,size_id,is_sustainable,quantity) VALUES (1,'t-shirt',1,false,100),(2,'blouse',3,true,50),(3,'jeans',4,true,75),(4,'skirt',2,false,150),(5,'jacket',5,true,100);
SELECT sizes.size, is_sustainable, SUM(quantity) FROM sizes JOIN inventory ON inventory.size_id = sizes.id GROUP BY sizes.size, is_sustainable;
Get the average salary for employees in each union
CREATE SCHEMA labor_unions; CREATE TABLE unions (id INT PRIMARY KEY,name VARCHAR(255)); CREATE TABLE employees (id INT PRIMARY KEY,name VARCHAR(255),union_id INT,salary DECIMAL(10,2),FOREIGN KEY (union_id) REFERENCES unions(id)); INSERT INTO unions (id,name) VALUES (1,'Union A'),(2,'Union B'); INSERT INTO employees (id,name,union_id,salary) VALUES (1,'John Doe',1,50000),(2,'Jane Smith',1,60000),(3,'Bob Johnson',2,55000);
SELECT u.name, AVG(e.salary) AS avg_salary FROM labor_unions.unions u INNER JOIN labor_unions.employees e ON u.id = e.union_id GROUP BY u.name;
Rank ethical fashion brands by their total sustainability score in ascending order.
CREATE TABLE ethical_fashion_brands (brand_id INT,brand_name VARCHAR(255),score INT); INSERT INTO ethical_fashion_brands (brand_id,brand_name,score) VALUES (1,'People Tree',85),(2,'Tentree',92),(3,'Everlane',88),(4,'Patagonia',78);
SELECT brand_name, score, RANK() OVER (ORDER BY score ASC) as sustainability_rank FROM ethical_fashion_brands;
What is the total investment in socially responsible funds by clients from the United States?
CREATE TABLE clients (id INT,name VARCHAR(255),country VARCHAR(255)); INSERT INTO clients (id,name,country) VALUES (1,'John Doe','USA'),(2,'Jane Smith','Canada'); CREATE TABLE investments (id INT,client_id INT,fund_type VARCHAR(255),amount DECIMAL(10,2)); INSERT INTO investments (id,client_id,fund_type,amount) VALUES (1,1,'Socially Responsible',5000),(2,1,'Standard',3000),(3,2,'Standard',7000);
SELECT SUM(amount) FROM investments i JOIN clients c ON i.client_id = c.id WHERE c.country = 'USA' AND i.fund_type = 'Socially Responsible';
What is the average temperature (in degrees Celsius) for each month in the climate_data dataset?
CREATE TABLE climate_data (id INT,month VARCHAR(255),temperature INT);
SELECT month, AVG(temperature) FROM climate_data GROUP BY month;
What is the total quantity of sustainable materials used in production in the last year?
CREATE TABLE ProductionMaterials (material_type VARCHAR(20),quantity INT,production_date DATE);
SELECT SUM(quantity) FROM ProductionMaterials WHERE material_type IN ('organic cotton','recycled polyester','sustainable silk') AND production_date BETWEEN DATE_SUB(NOW(), INTERVAL 1 YEAR) AND NOW();
Which countries have hotels with annual revenues over 5 million?
CREATE TABLE hotel_revenues (hotel_id INT,name TEXT,country TEXT,annual_revenue INT); INSERT INTO hotel_revenues (hotel_id,name,country,annual_revenue) VALUES (1,'Ritz Paris','France',6000000);
SELECT DISTINCT country FROM hotel_revenues WHERE annual_revenue > 5000000;
Identify the top 5 oil producing countries in Africa in 2020.
CREATE TABLE oil_production(country VARCHAR(255),year INT,production INT);INSERT INTO oil_production(country,year,production) VALUES('Nigeria',2020,1800000),('Angola',2020,1500000),('Algeria',2020,900000),('Libya',2020,700000),('Egypt',2020,600000),('South Sudan',2020,400000),('Republic of the Congo',2020,300000),('Gabon',2020,200000),('Equatorial Guinea',2020,150000),('Chad',2020,100000);
SELECT country, production FROM oil_production WHERE year = 2020 AND country IN ('Nigeria', 'Angola', 'Algeria', 'Libya', 'Egypt', 'South Sudan', 'Republic of the Congo', 'Gabon', 'Equatorial Guinea', 'Chad') ORDER BY production DESC LIMIT 5;
Find the percentage of visitors that engaged with online exhibitions from North America and Europe combined.
CREATE TABLE Online_Interaction (id INT,user_id INT,interaction_date DATE,country VARCHAR(50)); INSERT INTO Online_Interaction (id,user_id,interaction_date,country) VALUES (1,1,'2022-05-01','USA'),(2,3,'2022-05-15','Canada'),(3,5,'2022-04-20','France'),(4,7,'2022-03-25','UK');
SELECT (COUNT(DISTINCT CASE WHEN country IN ('USA', 'Canada', 'France', 'UK') THEN Online_Interaction.user_id END) * 100.0 / COUNT(DISTINCT Online_Interaction.user_id)) as percentage FROM Online_Interaction;
Insert a new record for 'DrugK' with R&D expenditure of $1,200,000 in Q1 2022.
CREATE TABLE drug_k_rd (quarter INTEGER,year INTEGER,amount INTEGER);
INSERT INTO drug_k_rd (quarter, year, amount) VALUES (1, 2022, 1200000);
Find the number of solar power plants in Spain and Italy that have a capacity greater than 50 MW.
CREATE TABLE solar_plants (id INT,country VARCHAR(255),name VARCHAR(255),capacity FLOAT); INSERT INTO solar_plants (id,country,name,capacity) VALUES (1,'Spain','Solarplant A',60.5); INSERT INTO solar_plants (id,country,name,capacity) VALUES (2,'Spain','Solarplant B',70.2); INSERT INTO solar_plants (id,country,name,capacity) VALUES (3,'Italy','Solarplant C',80.1); INSERT INTO solar_plants (id,country,name,capacity) VALUES (4,'Italy','Solarplant D',30.5);
SELECT COUNT(*) FROM solar_plants WHERE country IN ('Spain', 'Italy') AND capacity > 50;
What is the latest creation date in the 'Contemporary' period?
CREATE TABLE Artworks (artwork_name VARCHAR(255),creation_date DATE,movement VARCHAR(255)); INSERT INTO Artworks (artwork_name,creation_date,movement) VALUES ('The Night Watch','1642-02-01','Baroque'),('Girl with a Pearl Earring','1665-06-22','Dutch Golden Age'),('The Persistence of Memory','1931-08-01','Surrealism'),('The Birth of Venus','1485-01-01','Renaissance'),('The Scream','1893-05-22','Expressionism'),('Moon Landing','1969-07-20','Contemporary');
SELECT MAX(creation_date) FROM Artworks WHERE movement = 'Contemporary';
List the unique types of group fitness classes offered in LA and NYC
CREATE TABLE gym_classes (class_name VARCHAR(255),class_location VARCHAR(255));
SELECT DISTINCT class_location, class_name FROM gym_classes WHERE class_location IN ('LA', 'NYC');
Find the average number of tourists visiting Canada annually from 2017 to 2020
CREATE TABLE tourism_stats (destination VARCHAR(255),year INT,visitors INT); INSERT INTO tourism_stats (destination,year,visitors) VALUES ('Canada',2017,20000000),('Canada',2018,22000000),('Canada',2019,23000000),('Canada',2020,18000000);
SELECT AVG(visitors) FROM tourism_stats WHERE destination = 'Canada' AND year BETWEEN 2017 AND 2020;
What is the oldest artifact found at each excavation site?
CREATE TABLE excavation_sites (id INT,site_name VARCHAR(255)); CREATE TABLE artifacts (id INT,excavation_site_id INT,artifact_age INT);
SELECT e.site_name, MIN(a.artifact_age) AS oldest_artifact_age FROM artifacts a JOIN excavation_sites e ON a.excavation_site_id = e.id GROUP BY e.site_name;
What are the names of the vessels that docked in the Port of Oakland in June 2022 and have also docked in the Port of Los Angeles in July 2022?
CREATE TABLE port_of_oakland (vessel_name VARCHAR(255),dock_month INT); CREATE TABLE port_of_los_angeles (vessel_name VARCHAR(255),dock_month INT); INSERT INTO port_of_oakland (vessel_name,dock_month) VALUES ('Vessel XX',6),('Vessel YY',6),('Vessel ZZ',7); INSERT INTO port_of_los_angeles (vessel_name,dock_month) VALUES ('Vessel ZZ',7),('Vessel AA',8),('Vessel BB',8);
SELECT o.vessel_name FROM port_of_oakland o WHERE o.dock_month = 6 INTERSECT SELECT l.vessel_name FROM port_of_los_angeles l WHERE l.dock_month = 7;
What is the total revenue generated from eco-friendly hotels in Sweden?
CREATE TABLE eco_hotels (hotel_id INT,name TEXT,country TEXT,revenue FLOAT); INSERT INTO eco_hotels VALUES (1,'Eco Hotel Stockholm','Sweden',80000),(2,'Green Hotel Gothenburg','Sweden',90000);
SELECT SUM(revenue) FROM eco_hotels WHERE country = 'Sweden';
How many public libraries in the Libraries department have a budget over $500,000?
CREATE TABLE Libraries_Dept (ID INT,Library_Type VARCHAR(255),Budget FLOAT); INSERT INTO Libraries_Dept (ID,Library_Type,Budget) VALUES (1,'Public',700000),(2,'Public',600000),(3,'Academic',800000);
SELECT COUNT(*) FROM Libraries_Dept WHERE Library_Type = 'Public' AND Budget > 500000;