instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
How many satellites have been launched by ISRO before 2015?
|
CREATE TABLE SatelliteLaunchesByISRO (id INT,satellite_name VARCHAR(100),launch_year INT,company VARCHAR(100)); INSERT INTO SatelliteLaunchesByISRO (id,satellite_name,launch_year,company) VALUES (1,'GSAT-12',2009,'ISRO'); INSERT INTO SatelliteLaunchesByISRO (id,satellite_name,launch_year,company) VALUES (2,'INSAT-4A',2005,'ISRO');
|
SELECT COUNT(*) FROM SatelliteLaunchesByISRO WHERE launch_year < 2015;
|
How many whale sightings are there in total?
|
CREATE TABLE whale_sightings (sighting_date DATE,ocean TEXT); INSERT INTO whale_sightings (sighting_date,ocean) VALUES ('2021-01-01','Arctic Ocean'),('2021-02-01','Antarctic Ocean');
|
SELECT COUNT(*) FROM whale_sightings;
|
Show the number of unique donors who have donated to organizations with 'Animal' in their name, excluding donors who have donated less than $50 in their lifetime.
|
CREATE TABLE donors (id INT,name TEXT,state TEXT,total_donated DECIMAL(10,2)); INSERT INTO donors (id,name,state,total_donated) VALUES (1,'Sarah Lee','Texas',75.00); CREATE TABLE donations (id INT,donor_id INT,org_id INT,donation_amount DECIMAL(10,2)); INSERT INTO donations (id,donor_id,org_id,donation_amount) VALUES (1,1,1,50.00);
|
SELECT COUNT(DISTINCT donor_id) FROM donations JOIN organizations ON donations.org_id = organizations.id WHERE organizations.name LIKE '%Animal%' AND donor_id IN (SELECT donor_id FROM donations JOIN donors ON donations.donor_id = donors.id GROUP BY donor_id HAVING SUM(donation_amount) >= 50.00);
|
List all genetic research projects, their respective lead researchers, and their start dates.
|
CREATE TABLE projects(id INT,name VARCHAR(50),lead_researcher VARCHAR(50),start_date DATE);INSERT INTO projects (id,name,lead_researcher,start_date) VALUES (1,'ProjectX','Dr. Jane Smith','2021-01-01');INSERT INTO projects (id,name,lead_researcher,start_date) VALUES (2,'ProjectY','Dr. John Doe','2020-06-15');
|
SELECT name, lead_researcher, start_date FROM projects;
|
What is the maximum salary of players in the 'MLB' league who play the 'Pitcher' position?
|
CREATE TABLE players (player_id INT,name VARCHAR(50),position VARCHAR(50),height FLOAT,weight INT,team_id INT,league VARCHAR(50),salary INT); INSERT INTO players (player_id,name,position,height,weight,team_id,league,salary) VALUES (2,'Bob','Pitcher',1.9,95,201,'MLB',10000000);
|
SELECT MAX(salary) FROM players WHERE position = 'Pitcher' AND league = 'MLB';
|
Drop the 'ticket_sales' column
|
CREATE TABLE team_performance (team_id INT PRIMARY KEY,team_name VARCHAR(50),wins INT,losses INT); CREATE TABLE ticket_sales (sale_id INT PRIMARY KEY,team_id INT,sale_date DATE,quantity INT); ALTER TABLE athlete_wellbeing ADD COLUMN ticket_sales INT;
|
ALTER TABLE athlete_wellbeing DROP COLUMN ticket_sales;
|
What is the standard deviation of restorative justice cases per district in 2019?
|
CREATE TABLE district_stats (district_id INT,year INT,cases INT); INSERT INTO district_stats (district_id,year,cases) VALUES (1,2019,12),(2,2019,18),(3,2019,9),(4,2019,15),(5,2019,10),(6,2019,14);
|
SELECT d.district_id, STDEV(d.cases) AS std_dev_cases FROM district_stats d WHERE d.year = 2019 GROUP BY d.district_id;
|
Insert a new community development initiative in 'Amazonas' region with ID 3, name 'Cultural Center', and status 'planning' into the 'community_development' table.
|
CREATE TABLE community_development(id INT,region TEXT,initiative_name TEXT,status TEXT);
|
INSERT INTO community_development (id, region, initiative_name, status) VALUES (3, 'Amazonas', 'Cultural Center', 'planning');
|
Insert new records of local art exhibitions in Canada and the United States into the 'local_exhibitions' table.
|
CREATE TABLE local_exhibitions (exhibit_id INT,exhibit_name TEXT,location TEXT);
|
INSERT INTO local_exhibitions (exhibit_id, exhibit_name, location) VALUES (1, 'Canadian Art Showcase', 'Canada'), (2, 'American Art Experience', 'United States');
|
Insert a new record into the "ethical_ai_principles" table with the name "Fairness", "description" as "AI should be fair and impartial"
|
CREATE TABLE ethical_ai_principles (id INT PRIMARY KEY,principle_name VARCHAR(50),description TEXT);
|
INSERT INTO ethical_ai_principles (principle_name, description) VALUES ('Fairness', 'AI should be fair and impartial');
|
List the names of all tables and views related to media literacy programs, along with their creation dates.
|
CREATE TABLE programs (name VARCHAR(255),category VARCHAR(255),created_date DATE); INSERT INTO programs (name,category,created_date) VALUES ('Media Literacy 101','Media Literacy','2021-05-01'),('Critical Thinking','Media Literacy','2020-08-15');
|
SELECT name, created_date FROM programs WHERE category = 'Media Literacy';
|
Update the sustainability rating of Atlantic Cod to 70
|
CREATE TABLE Sustainable_Seafood (Species_ID INT,Species_Name VARCHAR(100),Sustainability_Rating INT); INSERT INTO Sustainable_Seafood (Species_ID,Species_Name,Sustainability_Rating) VALUES (1,'Atlantic Cod',60),(2,'Pacific Salmon',80);
|
UPDATE Sustainable_Seafood SET Sustainability_Rating = 70 WHERE Species_Name = 'Atlantic Cod';
|
What is the total investment in climate change communication campaigns for Latin America?
|
CREATE TABLE ClimateChangeCommunication (ID INT,CampaignName VARCHAR(255),Region VARCHAR(255),Investment DECIMAL(10,2)); INSERT INTO ClimateChangeCommunication (ID,CampaignName,Region,Investment) VALUES (1,'Campaign 1','Latin America',50000),(2,'Campaign 2','Asia',60000),(3,'Campaign 3','Europe',45000),(4,'Campaign 4','Africa',70000),(5,'Campaign 5','Latin America',75000);
|
SELECT SUM(Investment) FROM ClimateChangeCommunication WHERE Region = 'Latin America';
|
What is the total quantity of items stored in each warehouse for a specific product category?
|
CREATE TABLE warehouse (id INT,name VARCHAR(50),location VARCHAR(50)); INSERT INTO warehouse (id,name,location) VALUES (1,'Warehouse A','City A'),(2,'Warehouse B','City B'); CREATE TABLE inventory (id INT,warehouse_id INT,product VARCHAR(50),quantity INT); INSERT INTO inventory (id,warehouse_id,product,quantity) VALUES (1,1,'Product X',300),(2,1,'Product Y',400),(3,2,'Product X',500),(4,2,'Product Z',200); CREATE TABLE product (id INT,name VARCHAR(50),category VARCHAR(50)); INSERT INTO product (id,name,category) VALUES (1,'Product X','Category A'),(2,'Product Y','Category B'),(3,'Product Z','Category C');
|
SELECT w.name, p.category, SUM(i.quantity) as total_quantity FROM inventory i JOIN warehouse w ON i.warehouse_id = w.id JOIN product p ON i.product = p.name GROUP BY w.name, p.category;
|
How many hospitals are there in each province of China?
|
CREATE TABLE china_provinces (id INT,province VARCHAR(50)); CREATE TABLE hospitals (id INT,name VARCHAR(50),province_id INT); INSERT INTO china_provinces (id,province) VALUES (1,'Anhui'),(2,'Beijing'),(3,'Chongqing'); INSERT INTO hospitals (id,name,province_id) VALUES (1,'Anqing Hospital',1),(2,'Beijing Hospital',2),(3,'Chongqing Central Hospital',3);
|
SELECT p.province, COUNT(h.id) AS total_hospitals FROM hospitals h JOIN china_provinces p ON h.province_id = p.id GROUP BY p.province;
|
Update the sighting frequency of 'Dolphin' in the 'Atlantic Ocean' to 220.
|
CREATE TABLE Sightings (Species VARCHAR(25),Ocean VARCHAR(25),Sightings INT); INSERT INTO Sightings (Species,Ocean,Sightings) VALUES ('Dolphin','Atlantic Ocean',200),('Turtle','Pacific Ocean',350),('Shark','Indian Ocean',150),('Whale','Pacific Ocean',400);
|
UPDATE Sightings SET Sightings = 220 WHERE Species = 'Dolphin' AND Ocean = 'Atlantic Ocean';
|
What is the average points scored by the Chicago Bulls in their home games?
|
CREATE TABLE teams (id INT,name TEXT,city TEXT); INSERT INTO teams (id,name,city) VALUES (1,'Chicago Bulls','Chicago'); CREATE TABLE games (id INT,home_team_id INT,away_team_id INT,points_home INT,points_away INT);
|
SELECT AVG(points_home) FROM games WHERE home_team_id = (SELECT id FROM teams WHERE name = 'Chicago Bulls' AND city = 'Chicago');
|
How many drought-affected areas were reported in Australia between 2017 and 2020?
|
CREATE TABLE australia_droughts (year INT,affected_areas INT); INSERT INTO australia_droughts (year,affected_areas) VALUES (2017,50),(2018,75),(2019,100),(2020,125);
|
SELECT SUM(australia_droughts.affected_areas) as total_drought_affected_areas FROM australia_droughts WHERE australia_droughts.year BETWEEN 2017 AND 2020;
|
What are the total sales and average sales per transaction for beauty products that are certified organic in Australia?
|
CREATE TABLE beauty_products_australia (certified_organic BOOLEAN,sale_date DATE,sales_quantity INT,unit_price DECIMAL(5,2)); INSERT INTO beauty_products_australia (certified_organic,sale_date,sales_quantity,unit_price) VALUES (TRUE,'2022-01-01',130,26.99),(FALSE,'2022-01-01',170,22.99);
|
SELECT SUM(sales_quantity * unit_price) AS total_sales, AVG(sales_quantity) AS avg_sales_per_transaction FROM beauty_products_australia WHERE certified_organic = TRUE AND sale_date BETWEEN '2022-01-01' AND '2022-12-31';
|
What is the minimum number of flights for space exploration missions led by Roscosmos?
|
CREATE TABLE SpaceExploration (id INT,agency VARCHAR(255),country VARCHAR(255),cost FLOAT,flights INT,year INT); INSERT INTO SpaceExploration VALUES (1,'NASA','USA',22000000000,500,2010),(2,'ESA','Europe',18000000000,300,2015),(3,'Roscosmos','Russia',15000000000,450,2012),(4,'ISRO','India',7000000000,100,2005),(5,'Roscosmos','Russia',20000000000,400,2020);
|
SELECT MIN(flights) FROM SpaceExploration WHERE agency = 'Roscosmos';
|
Which sustainable hotels in Canada have the highest guest satisfaction scores?
|
CREATE TABLE hotel_satisfaction(hotel_id INT,hotel_name TEXT,country TEXT,is_sustainable BOOLEAN,guest_satisfaction INT); INSERT INTO hotel_satisfaction (hotel_id,hotel_name,country,is_sustainable,guest_satisfaction) VALUES (1,'Eco Lodge','Canada',true,9),(2,'Grand Hotel','Canada',false,8),(3,'Green Hotel','Canada',true,10);
|
SELECT hotel_name, guest_satisfaction FROM hotel_satisfaction WHERE country = 'Canada' AND is_sustainable = true ORDER BY guest_satisfaction DESC;
|
How many different crops were grown in 'farm_activities' table per region?
|
CREATE TABLE farm_activities (region VARCHAR(50),crop VARCHAR(50),planting_date DATE); INSERT INTO farm_activities VALUES ('West Coast','Wheat','2022-04-01'); INSERT INTO farm_activities VALUES ('West Coast','Corn','2022-05-01'); INSERT INTO farm_activities VALUES ('East Coast','Rice','2022-06-01');
|
SELECT region, COUNT(DISTINCT crop) AS num_crops FROM farm_activities GROUP BY region;
|
What is the average rating of movies produced in Spain and Italy?
|
CREATE TABLE movies (id INT,title VARCHAR(255),rating DECIMAL(3,2),production_country VARCHAR(64)); INSERT INTO movies (id,title,rating,production_country) VALUES (1,'MovieA',7.5,'Spain'),(2,'MovieB',8.2,'Italy'),(3,'MovieC',6.8,'France');
|
SELECT AVG(rating) FROM movies WHERE production_country IN ('Spain', 'Italy');
|
What is the percentage of sustainable material orders in each country?
|
CREATE TABLE Deliveries (order_id INT,delivery_date DATE,material_sustainable BOOLEAN); CREATE TABLE Orders (order_id INT,order_date DATE,country VARCHAR(50));
|
SELECT O.country, (COUNT(D.order_id) * 100.0 / (SELECT COUNT(*) FROM Orders) ) as percentage FROM Deliveries D INNER JOIN Orders O ON D.order_id = O.order_id WHERE D.material_sustainable = TRUE GROUP BY O.country;
|
What is the total value of artworks by female artists?
|
CREATE TABLE artwork_data (id INT,art_name VARCHAR(50),artist_name VARCHAR(50),value DECIMAL(10,2));
|
SELECT SUM(value) as total_value FROM artwork_data WHERE artist_name LIKE '%female%';
|
What is the total fare collected from each route on the first day of each month?
|
CREATE TABLE route (route_id INT,route_name VARCHAR(50)); INSERT INTO route (route_id,route_name) VALUES (1,'Red Line'),(2,'Green Line'),(3,'Blue Line'),(4,'Yellow Line'); CREATE TABLE fare (fare_id INT,route_id INT,fare_amount DECIMAL(5,2),collection_date DATE); INSERT INTO fare (fare_id,route_id,fare_amount,collection_date) VALUES (1,1,3.50,'2022-06-01'),(2,1,3.25,'2022-06-03'),(3,2,3.50,'2022-06-05'),(4,2,3.25,'2022-06-07'),(5,3,3.50,'2022-06-09'),(6,3,3.25,'2022-06-11'),(7,4,4.00,'2022-07-01'),(8,4,4.25,'2022-07-02'),(9,4,4.50,'2022-07-03'),(10,4,4.25,'2022-07-04');
|
SELECT route_name, SUM(fare_amount) FROM route JOIN fare ON route.route_id = fare.route_id WHERE DAY(collection_date) = 1 GROUP BY route_name;
|
Update the status of all orders in the Orders table to 'Shipped' where the order date is older than 7 days.
|
CREATE TABLE Orders (OrderID int,OrderDate date,OrderStatus varchar(50)); INSERT INTO Orders VALUES (1,'2022-01-01','Pending'),(2,'2022-01-02','Shipped'),(3,'2022-01-03','Pending'),(4,'2022-01-04','Shipped');
|
UPDATE Orders SET OrderStatus = 'Shipped' WHERE DATEDIFF(day, OrderDate, GETDATE()) > 7 AND OrderStatus = 'Pending';
|
How many research grants were awarded to graduate students from historically underrepresented communities in the past year?
|
CREATE TABLE graduate_students (id INT,name VARCHAR(50),community VARCHAR(50),grant_received INT,grant_year INT);
|
SELECT COUNT(grant_received) FROM graduate_students WHERE community IN ('African American', 'Hispanic', 'Native American') AND grant_year = YEAR(CURRENT_DATE) - 1;
|
What are the names of all intelligence agencies in the Middle East?
|
CREATE TABLE Agency (Name VARCHAR(50),Region VARCHAR(50)); INSERT INTO Agency (Name,Region) VALUES ('Mossad','Middle East'),('CIA','North America'),('MI6','Europe'),('ASIO','Australia'),('MSS','China');
|
SELECT Name FROM Agency WHERE Region = 'Middle East';
|
Display the number of players who earned an achievement on '2022-01-01' or '2022-01-02' in 'player_achievements' table
|
CREATE TABLE player_achievements (player_id INT,achievement_name VARCHAR(255),date_earned DATE);
|
SELECT COUNT(DISTINCT player_id) FROM player_achievements WHERE date_earned IN ('2022-01-01', '2022-01-02');
|
Remove users who have not streamed any songs in the past month.
|
CREATE TABLE user_activity (user_id INT,song_id INT,stream_date DATE); INSERT INTO user_activity (user_id,song_id,stream_date) VALUES (1,1,'2022-01-01'); INSERT INTO user_activity (user_id,song_id,stream_date) VALUES (2,2,'2022-01-15');
|
DELETE FROM user_activity WHERE stream_date < DATE_SUB(CURDATE(), INTERVAL 1 MONTH);
|
What is the percentage of tourists visiting historical sites in Asia that use public transportation?
|
CREATE TABLE countries (country_code CHAR(3),country_name VARCHAR(100),continent VARCHAR(50));CREATE TABLE destinations (destination_id INT,destination_name VARCHAR(100),is_historical BOOLEAN,continent VARCHAR(50));CREATE TABLE bookings (booking_id INT,guest_id INT,destination_id INT,country_code CHAR(3));CREATE TABLE transportation (transportation_id INT,booking_id INT,type VARCHAR(50));INSERT INTO countries (country_code,country_name,continent) VALUES ('CHN','China','Asia'),('JPN','Japan','Asia'),('KOR','South Korea','Asia'),('IDN','Indonesia','Asia'),('VNM','Vietnam','Asia');
|
SELECT 100.0 * COUNT(DISTINCT b.guest_id) / (SELECT COUNT(DISTINCT b.guest_id) FROM bookings b JOIN destinations d ON b.destination_id = d.destination_id JOIN countries c ON b.country_code = c.country_code WHERE d.is_historical = TRUE AND c.continent = 'Asia') AS percentage FROM transportation t JOIN bookings b ON t.booking_id = b.booking_id JOIN destinations d ON b.destination_id = d.destination_id JOIN countries c ON b.country_code = c.country_code WHERE t.type = 'Public Transportation' AND d.is_historical = TRUE AND c.continent = 'Asia';
|
What is the total number of hospital beds and the number of beds per hospital per state?
|
CREATE TABLE hospitals (state varchar(2),hospital_name varchar(25),num_beds int); INSERT INTO hospitals (state,hospital_name,num_beds) VALUES ('NY','NY Presbyterian',2001),('CA','UCLA Medical',1012),('TX','MD Anderson',1543),('FL','Mayo Clinic FL',1209);
|
SELECT state, AVG(num_beds) as avg_beds_per_hospital FROM hospitals GROUP BY state;
|
What is the total water consumption in each region for the last 12 months?
|
CREATE TABLE regional_water_usage (region TEXT,date DATE,water_consumption FLOAT); INSERT INTO regional_water_usage (region,date,water_consumption) VALUES ('Northeast','2020-01-01',1000000),('Northeast','2020-02-01',1200000),('Southeast','2020-01-01',1500000),('Southeast','2020-02-01',1800000);
|
SELECT region, SUM(water_consumption) FROM regional_water_usage WHERE date >= (CURRENT_DATE - INTERVAL '12 month') GROUP BY region;
|
What is the total value of agricultural crops produced by smallholder farmers in each state of Nigeria, and what percentage do they contribute to the total agricultural production?
|
CREATE TABLE states (id INT,name VARCHAR(50),country VARCHAR(50)); INSERT INTO states (id,name,country) VALUES (1,'Abia','Nigeria'); CREATE TABLE smallholder_farmers (id INT,crop_value FLOAT,state_id INT); INSERT INTO smallholder_farmers (id,crop_value,state_id) VALUES (1,10000.0,1); CREATE TABLE total_agricultural_production (state_id INT,total_production FLOAT); INSERT INTO total_agricultural_production (state_id,total_production) VALUES (1,50000.0);
|
SELECT s.name, SUM(sf.crop_value) as total_value, (SUM(sf.crop_value) / tap.total_production) * 100 as percentage FROM smallholder_farmers sf INNER JOIN states s ON sf.state_id = s.id INNER JOIN total_agricultural_production tap ON sf.state_id = tap.state_id GROUP BY s.name;
|
List AI companies in Latin America or Europe with less than 20 employees that have published at least 1 paper on explainable AI in the last 3 years?
|
CREATE TABLE ai_companies (id INT,name VARCHAR(100),employees INT,location VARCHAR(100)); CREATE TABLE explainable_papers (id INT,company_id INT,title VARCHAR(100),year INT);
|
SELECT name FROM ai_companies WHERE employees < 20 AND (location = 'Latin America' OR location = 'Europe') AND id IN (SELECT company_id FROM explainable_papers WHERE year BETWEEN YEAR(CURRENT_DATE) - 3 AND YEAR(CURRENT_DATE));
|
What is the total revenue for movies in Australia in 2021?
|
CREATE TABLE Movies (region VARCHAR(20),year INT,revenue DECIMAL(5,2)); INSERT INTO Movies (region,year,revenue) VALUES ('Australia',2021,500000.00),('Australia',2021,750000.00),('US',2021,800000.00);
|
SELECT SUM(revenue) FROM Movies WHERE region = 'Australia' AND year = 2021;
|
What is the maximum creative AI application novelty score in Europe and South America?
|
CREATE TABLE ai_app_novelty (id INT,app_name VARCHAR(50),country VARCHAR(50),novelty_score FLOAT); INSERT INTO ai_app_novelty VALUES (1,'InnovateArt','France',0.94),(2,'CreativeCodeX','Brazil',0.87),(3,'ArtGenius','Spain',0.91);
|
SELECT MAX(novelty_score) FROM ai_app_novelty WHERE country IN ('France', 'Brazil', 'Spain');
|
What is the average age of male fans from Sydney?
|
CREATE TABLE fans (id INT,name VARCHAR(50),city VARCHAR(50),age INT,gender VARCHAR(10),sport VARCHAR(50)); INSERT INTO fans (id,name,city,age,gender,sport) VALUES (1,'Alice','Sydney',25,'Male','Rugby'); INSERT INTO fans (id,name,city,age,gender,sport) VALUES (2,'Bob','Tokyo',30,'Male','Baseball');
|
SELECT AVG(age) FROM fans WHERE city = 'Sydney' AND gender = 'Male';
|
Update the 'creative_ai' table, changing 'tool' to 'DreamBooth' for records where 'id' is 3
|
CREATE TABLE creative_ai (id INT,tool VARCHAR(20),application VARCHAR(50),country VARCHAR(20)); INSERT INTO creative_ai (id,tool,application,country) VALUES (1,'GAN','Art Generation','Canada'),(2,'DALL-E','Text-to-Image','USA'),(3,'Diffusion Models','Image Generation','China');
|
UPDATE creative_ai SET tool = 'DreamBooth' WHERE id = 3;
|
What is the maximum health equity metric score for community health workers in Florida?
|
CREATE TABLE community_health_workers (worker_id INT,name VARCHAR(50),state VARCHAR(25),health_equity_metric_score INT); INSERT INTO community_health_workers (worker_id,name,state,health_equity_metric_score) VALUES (1,'Alex Johnson','Florida',95); INSERT INTO community_health_workers (worker_id,name,state,health_equity_metric_score) VALUES (2,'Marie Taylor','Texas',88); INSERT INTO community_health_workers (worker_id,name,state,health_equity_metric_score) VALUES (3,'Pierre Martinez','California',92);
|
SELECT MAX(health_equity_metric_score) FROM community_health_workers WHERE state = 'Florida';
|
What is the total quantity of sustainable and non-sustainable products sold for each store, and filters the results to only show stores with more than 400 units sold for either category?
|
CREATE TABLE store (id INT PRIMARY KEY,name VARCHAR(100),location VARCHAR(50),sustainable BOOLEAN); CREATE TABLE sales (id INT PRIMARY KEY,store_id INT,product_id INT,quantity INT,date DATE); CREATE TABLE product (id INT PRIMARY KEY,name VARCHAR(100),manufacturer_id INT,price DECIMAL(5,2),sustainable BOOLEAN); CREATE TABLE manufacturer (id INT PRIMARY KEY,name VARCHAR(100),country VARCHAR(50),sustainable BOOLEAN);
|
SELECT store.name as store_name, SUM(sales.quantity) as total_sold FROM sales INNER JOIN store ON sales.store_id = store.id INNER JOIN product ON sales.product_id = product.id GROUP BY store.name HAVING total_sold > 400;
|
What is the maximum package weight for each warehouse?
|
CREATE TABLE package_weights (package_id INT,warehouse_id VARCHAR(5),weight DECIMAL(5,2)); INSERT INTO package_weights (package_id,warehouse_id,weight) VALUES (1,'LA',3.0),(2,'LA',2.5),(3,'NY',2.0),(4,'CH',1.5),(5,'MI',4.0),(6,'MI',3.5),(7,'AT',5.0);
|
SELECT warehouse_id, MAX(weight) FROM package_weights GROUP BY warehouse_id;
|
What is the minimum pH value recorded in each monitoring station?
|
CREATE TABLE MonitoringStations (StationID INT,StationName VARCHAR(50),pH DECIMAL(3,2)); INSERT INTO MonitoringStations VALUES (1,'Station A',7.8),(2,'Station B',7.5),(3,'Station C',8.0);
|
SELECT StationName, MIN(pH) FROM MonitoringStations GROUP BY StationName;
|
What is the average lifelong learning score of students in each country?
|
CREATE TABLE student_lifelong_learning_scores (student_id INT,country TEXT,lifelong_learning_score INT); INSERT INTO student_lifelong_learning_scores (student_id,country,lifelong_learning_score) VALUES (1,'USA',80),(2,'Canada',85),(3,'Mexico',90),(4,'Brazil',75),(5,'Argentina',95);
|
SELECT country, AVG(lifelong_learning_score) as avg_score FROM student_lifelong_learning_scores GROUP BY country;
|
What is the total number of tickets sold for each event type (concert, exhibition, workshop) across all cultural centers?
|
CREATE TABLE events (id INT,title VARCHAR(50),event_type VARCHAR(50),tickets_sold INT); INSERT INTO events (id,title,event_type,tickets_sold) VALUES (1,'Classical Music Concert','concert',1200); INSERT INTO events (id,title,event_type,tickets_sold) VALUES (2,'Modern Art Exhibition','exhibition',1500); INSERT INTO events (id,title,event_type,tickets_sold) VALUES (3,'Photography Workshop','workshop',800);
|
SELECT event_type, SUM(tickets_sold) FROM events GROUP BY event_type;
|
What is the earliest date a female member started a workout?
|
CREATE TABLE members (member_id INT,age INT,gender VARCHAR(10)); CREATE TABLE workouts (workout_id INT,member_id INT,date DATE); INSERT INTO members VALUES (1,25,'Female'),(2,35,'Male'),(3,28,'Female'),(4,45,'Female'); INSERT INTO workouts VALUES (1,1,'2022-01-01'),(2,1,'2022-01-02'),(3,2,'2022-01-03'),(4,3,'2022-01-04'),(5,3,'2022-01-05'),(6,4,'2022-01-06'),(7,4,'2022-01-07');
|
SELECT MIN(date) FROM workouts JOIN members ON workouts.member_id = members.member_id WHERE members.gender = 'Female';
|
What is the total donation amount for each month in 'donations' table?
|
CREATE TABLE donations (id INT,donor_id INT,amount DECIMAL(10,2),donation_date DATE);
|
SELECT EXTRACT(MONTH FROM donation_date) as month, SUM(amount) as total_donations FROM donations GROUP BY month;
|
Find the average sea level rise in the 'Arctic' over the past 10 years.
|
CREATE TABLE sea_level_data (id INTEGER,location TEXT,value FLOAT,date DATE);
|
SELECT AVG(value) FROM sea_level_data WHERE location = 'Arctic' AND date >= DATEADD(year, -10, CURRENT_DATE);
|
Update the total_donations value for the 'Kakuma' refugee camp by adding 10% to its current value.
|
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);
|
UPDATE refugee_camps SET total_donations = total_donations * 1.10 WHERE camp_name = 'Kakuma';
|
What is the total donation amount for the 'Green Earth' program in Q2 2022?
|
CREATE TABLE Donations (id INT,donation_amount DECIMAL(10,2),donation_date DATE,donor_program VARCHAR(50));
|
SELECT SUM(Donations.donation_amount) FROM Donations WHERE Donations.donation_date BETWEEN '2022-04-01' AND '2022-06-30' AND Donations.donor_program = 'Green Earth';
|
Update the 'safety_rating' in the 'chemicals' table to 95 for any chemical with an ID present in the 'storage' table and a safety rating below 90.
|
CREATE TABLE storage (chemical_id INT); CREATE TABLE chemicals (id INT,chemical_name VARCHAR(255),safety_rating INT); INSERT INTO storage (chemical_id) VALUES (1),(3),(5); INSERT INTO chemicals (id,chemical_name,safety_rating) VALUES (1,'H2O',85),(2,'CO2',70),(3,'N2',60),(4,'O2',95),(5,'F2',80);
|
UPDATE chemicals SET safety_rating = 95 WHERE id IN (SELECT chemical_id FROM storage) AND safety_rating < 90;
|
How many new users registered on the music platform per week?
|
CREATE TABLE UserRegistrations (reg_id INT,reg_date DATE,user_id INT,user_info VARCHAR(255)); INSERT INTO UserRegistrations (reg_id,reg_date,user_id,user_info) VALUES (1,'2020-01-01',1,'John Doe'),(2,'2020-01-07',2,'Jane Doe'),(3,'2020-01-05',3,'Mike Johnson');
|
SELECT DATE_FORMAT(reg_date, '%Y-%u') as registration_week, COUNT(DISTINCT user_id) as new_users_per_week FROM UserRegistrations GROUP BY registration_week;
|
What is the total revenue generated from the 'Adventure' genre in the last month?
|
CREATE TABLE Purchases (PurchaseID INT,PlayerID INT,GameID INT,PurchaseDate DATE,Price DECIMAL(5,2)); INSERT INTO Purchases (PurchaseID,PlayerID,GameID,PurchaseDate,Price) VALUES (1,1,1,'2021-01-15',29.99),(2,2,2,'2021-02-03',19.99),(3,3,3,'2021-03-10',39.99),(4,1,4,'2021-03-15',49.99),(5,2,5,'2021-04-01',59.99),(6,3,1,'2021-04-05',29.99); CREATE TABLE GameGenres (GameID INT,Genre VARCHAR(20)); INSERT INTO GameGenres (GameID,Genre) VALUES (1,'Role-playing'),(2,'Action'),(3,'Strategy'),(4,'Adventure'),(5,'Simulation'),(6,'Virtual Reality');
|
SELECT SUM(Price) FROM Purchases INNER JOIN GameGenres ON Purchases.GameID = GameGenres.GameID WHERE PurchaseDate >= DATEADD(month, -1, GETDATE()) AND GameGenres.Genre = 'Adventure';
|
What is the total revenue per sustainable sourcing category in February 2022?
|
CREATE TABLE revenue (restaurant_id INT,date DATE,revenue INT,sourcing_category VARCHAR(50)); INSERT INTO revenue (restaurant_id,date,revenue,sourcing_category) VALUES (1,'2022-02-01',5000,'Organic'),(1,'2022-02-02',6000,'Local'),(2,'2022-02-01',4000,'Fair Trade'),(2,'2022-02-02',7000,'Organic');
|
SELECT sourcing_category, SUM(revenue) as total_revenue FROM revenue WHERE MONTH(date) = 2 GROUP BY sourcing_category;
|
What is the average waste percentage for each dish and how many calories are there in each dish?
|
CREATE TABLE dish (dish_id INT,dish_name TEXT,waste_percentage DECIMAL(5,2),calories INT); INSERT INTO dish (dish_id,dish_name,waste_percentage,calories) VALUES (1,'Pizza Margherita',0.12,800),(2,'Veggie Burger',0.18,600);
|
SELECT dish_name, AVG(waste_percentage) as avg_waste_percentage, AVG(calories) as avg_calories FROM dish GROUP BY dish_name;
|
What's the combined list of astronauts who have flown on both the Space Shuttle and Soyuz spacecraft?
|
CREATE TABLE SpaceShuttleAstronauts (AstronautName TEXT,Missions INTEGER);CREATE TABLE SoyuzAstronauts (AstronautName TEXT,Missions INTEGER);
|
SELECT AstronautName FROM SpaceShuttleAstronauts WHERE Missions > 1 INTERSECT SELECT AstronautName FROM SoyuzAstronauts WHERE Missions > 1;
|
Find the number of menu items offered by each restaurant, and rank them in order of highest to lowest number of menu items.
|
CREATE TABLE Restaurants (RestaurantID int,Name varchar(50)); INSERT INTO Restaurants (RestaurantID,Name) VALUES (1,'Paleteria Y Neveria'),(2,'Thai Spice'),(3,'Bombay Kitchen'),(4,'Sushi Bar'); CREATE TABLE MenuItems (MenuItemID int,RestaurantID int,Name varchar(50),Revenue decimal(5,2)); INSERT INTO MenuItems (MenuItemID,RestaurantID,Name,Revenue) VALUES (1,1,'Mango Paleta',3.00),(2,1,'Pineapple Paleta',3.00),(3,2,'Pad Thai',12.00),(4,2,'Tom Yum Soup',6.00),(5,3,'Chicken Tikka Masala',15.00),(6,3,'Naan Bread',3.00),(7,4,'Spicy Tuna Roll',8.00),(8,4,'Philadelphia Roll',7.00);
|
SELECT R.Name, COUNT(MI.MenuItemID) AS NumMenuItems, ROW_NUMBER() OVER (ORDER BY COUNT(MI.MenuItemID) DESC) AS Rank FROM Restaurants R LEFT JOIN MenuItems MI ON R.RestaurantID = MI.RestaurantID GROUP BY R.Name ORDER BY Rank;
|
What was the total amount donated by individual donors from the US in Q1 2021?
|
CREATE TABLE donors (id INT,name TEXT,country TEXT,donation FLOAT); INSERT INTO donors (id,name,country,donation) VALUES (1,'John Doe','USA',500.00),(2,'Jane Smith','Canada',300.00);
|
SELECT SUM(donation) FROM donors WHERE country = 'USA' AND donation_date BETWEEN '2021-01-01' AND '2021-03-31';
|
What is the average water consumption per garment type in South America for 2021?
|
CREATE TABLE garment_water_data (garment_id INT,garment_type VARCHAR(255),production_location VARCHAR(255),water_consumption INT,year INT);
|
SELECT garment_type, AVG(water_consumption) AS avg_water_consumption FROM garment_water_data WHERE production_location LIKE 'South America%' AND year = 2021 GROUP BY garment_type;
|
Identify the number of mitigation projects per year between 2017 and 2022, and display the total budget for each year.
|
CREATE TABLE climate_mitigation_projects (year INT,project VARCHAR(20),budget FLOAT); INSERT INTO climate_mitigation_projects (year,project,budget) VALUES (2017,'Project1',6000000),(2018,'Project2',8000000),(2019,'Project3',1000000),(2020,'Project4',1200000),(2021,'Project5',1400000),(2022,'Project6',1600000);
|
SELECT year, COUNT(DISTINCT project) AS num_projects, SUM(budget) AS total_budget FROM climate_mitigation_projects WHERE year BETWEEN 2017 AND 2022 GROUP BY year;
|
What is the maximum number of employees in factories located in a specific region?
|
CREATE TABLE factories (factory_id INT,name VARCHAR(100),location VARCHAR(100),num_employees INT); CREATE TABLE employees (employee_id INT,factory_id INT,name VARCHAR(100),position VARCHAR(100)); INSERT INTO factories (factory_id,name,location,num_employees) VALUES (1,'ABC Factory','North',50),(2,'XYZ Factory','South',75),(3,'LMN Factory','East',100),(4,'PQR Factory','West',80); INSERT INTO employees (employee_id,factory_id,name,position) VALUES (1,1,'John Doe','Engineer'),(2,1,'Jane Smith','Manager'),(3,2,'Mike Johnson','Operator'),(4,3,'Sara Brown','Engineer'),(5,3,'David Williams','Manager'),(6,4,'Emily Davis','Engineer');
|
SELECT MAX(factories.num_employees) FROM factories WHERE factories.location = 'East';
|
What is the latest astrobiology discovery?
|
CREATE TABLE AstrobiologyDiscoveries (id INT PRIMARY KEY,name VARCHAR(255),discovery_date DATE);
|
SELECT name FROM AstrobiologyDiscoveries ORDER BY discovery_date DESC LIMIT 1;
|
Find the number of endangered marine species in the Atlantic Ocean.
|
CREATE TABLE marine_species (species_name TEXT,endangered BOOLEAN,ocean TEXT); INSERT INTO marine_species (species_name,endangered,ocean) VALUES ('Greenland Shark',FALSE,'Atlantic'),('Blue Whale',TRUE,'Atlantic');
|
SELECT COUNT(*) FROM marine_species WHERE endangered = TRUE AND ocean = 'Atlantic';
|
Which public transportation systems have the highest and lowest ridership in 'transportation' table for the year 2022?
|
CREATE TABLE transportation (id INT,system_type VARCHAR(20),ridership INT,year INT); INSERT INTO transportation (id,system_type,ridership,year) VALUES (1,'Subway',5000000,2022),(2,'Bus',3000000,2022),(3,'Light Rail',1000000,2022),(4,'Ferry',500000,2022);
|
SELECT system_type, ridership FROM (SELECT system_type, ridership, ROW_NUMBER() OVER (ORDER BY ridership DESC) AS rank FROM transportation WHERE system_type LIKE '%public%' AND year = 2022) AS subquery WHERE rank = 1 OR rank = 4;
|
What is the maximum depth of the Mariana Trench?
|
CREATE TABLE OceanFloorTrenches (id INT,ocean_id INT,trench VARCHAR(50),depth INT); INSERT INTO OceanFloorTrenches (id,ocean_id,trench,depth) VALUES (1,1,'Mariana Trench',10994),(2,2,'Tonga Trench',10820),(3,3,'Sunda Trench',8045);
|
SELECT MAX(OceanFloorTrenches.depth) FROM OceanFloorTrenches WHERE OceanFloorTrenches.trench = 'Mariana Trench';
|
What are the unique game genres played on each continent?
|
CREATE TABLE GameContinents (GameID INT,GameName VARCHAR(20),Continent VARCHAR(20),Genre VARCHAR(20)); INSERT INTO GameContinents (GameID,GameName,Continent,Genre) VALUES (1,'GameE','Asia','Adventure'),(2,'GameF','Europe','Simulation'),(3,'GameG','North America','Strategy'),(4,'GameH','Australia','Adventure');
|
SELECT DISTINCT Continent, Genre FROM GameContinents WHERE Genre IS NOT NULL;
|
How many hospitals are there in Quebec, and what is the total number of beds in their intensive care units?
|
CREATE TABLE hospitals (name VARCHAR(255),province VARCHAR(255),icu_beds INT); INSERT INTO hospitals (name,province,icu_beds) VALUES ('Montreal General Hospital','Quebec',50),('Saint-Justine Hospital','Quebec',75),('McGill University Health Center','Quebec',100);
|
SELECT COUNT(*) AS total_hospitals, SUM(icu_beds) AS total_icu_beds FROM hospitals WHERE province = 'Quebec';
|
Identify permit costs in Q2 2021 with a lead of the following quarter's costs.
|
CREATE TABLE permit (permit_id INT,quarter VARCHAR(10),cost FLOAT); INSERT INTO permit VALUES (1,'Q2',5000); INSERT INTO permit VALUES (2,'Q3',6000);
|
SELECT permit_id, quarter, cost, LEAD(cost) OVER (ORDER BY quarter) as next_quarter_cost FROM permit WHERE quarter IN ('Q2', 'Q3');
|
What is the total energy consumption of green buildings in the Southern region?
|
CREATE TABLE consumption (id INT,region VARCHAR(20),type VARCHAR(20),consumption INT); INSERT INTO consumption (id,region,type,consumption) VALUES (1,'Southern','Green',1000); INSERT INTO consumption (id,region,type,consumption) VALUES (2,'Northern','Regular',2000);
|
SELECT SUM(consumption) FROM consumption WHERE region = 'Southern' AND type = 'Green';
|
Which public works projects in 'New York' have a budget greater than $1,000,000?
|
CREATE TABLE PublicWorks(id INT,city VARCHAR(20),project VARCHAR(30),budget DECIMAL(10,2)); INSERT INTO PublicWorks(id,city,project,budget) VALUES (1,'New York','Subway Expansion',1500000.00),(2,'Los Angeles','Highway Construction',800000.00);
|
SELECT city, project, budget FROM PublicWorks WHERE budget > 1000000.00 AND city = 'New York';
|
What is the total number of algorithmic fairness assessments conducted in Africa in 2022?
|
CREATE TABLE fairness_assessments (assessment_id INT,assessment_date DATE,continent TEXT); INSERT INTO fairness_assessments (assessment_id,assessment_date,continent) VALUES (1,'2022-01-02','Africa'),(2,'2022-02-15','Africa'),(3,'2022-03-27','Africa');
|
SELECT COUNT(*) as num_assessments FROM fairness_assessments WHERE continent = 'Africa' AND assessment_date BETWEEN '2022-01-01' AND '2022-12-31';
|
What is the average time spent in port by vessels that have transported containers to Canada in the year 2021?
|
CREATE TABLE Voyage (id INT,vessel VARCHAR(255),time_in_port INT,country VARCHAR(255),time DATETIME); INSERT INTO Voyage (id,vessel,time_in_port,country,time) VALUES (1,'Arctic Explorer',12,'Canada','2021-01-01 10:00:00'),(2,'Sea Titan',10,'USA','2021-02-15 15:30:00');
|
SELECT AVG(time_in_port) FROM Voyage V WHERE country = 'Canada';
|
What is the maximum digital divide index for each income level?
|
CREATE TABLE IncomeLevel (IncomeLevelID INT PRIMARY KEY,IncomeLevel VARCHAR(50),DigitalDivideIndex DECIMAL(5,2)); INSERT INTO IncomeLevel (IncomeLevelID,IncomeLevel,DigitalDivideIndex) VALUES (1,'Low Income',0.65),(2,'Middle Income',0.45),(3,'High Income',0.25);
|
SELECT IncomeLevel, MAX(DigitalDivideIndex) as MaxDigitalDivideIndex FROM IncomeLevel GROUP BY IncomeLevel;
|
Delete all shipments from January 2021
|
CREATE TABLE shipments(id INT,load_date DATE,unloaded_date DATE); INSERT INTO shipments VALUES(1,'2021-01-01','2021-01-05');
|
DELETE FROM shipments WHERE load_date >= '2021-01-01' AND load_date < '2021-02-01';
|
Who are the top 3 artists with the most works in the 'Painting' medium?
|
CREATE TABLE artists (id INT,name TEXT,country TEXT,medium TEXT,works_count INT); INSERT INTO artists (id,name,country,medium,works_count) VALUES (1,'John Doe','Nigeria','Sculpture',12),(2,'Jane Smith','Kenya','Painting',25),(3,'Mohamed Ahmed','Egypt','Sculpture',8),(4,'Aisha Mohamed','Senegal','Painting',30),(5,'Pedro Gonzales','South Africa','Drawing',18);
|
SELECT name, medium, SUM(works_count) AS total_works FROM artists WHERE medium = 'Painting' GROUP BY name, medium ORDER BY total_works DESC LIMIT 3;
|
List all network towers in the state of California that have a investment date on or after 2018-01-01.
|
CREATE TABLE network_towers (tower_id INT,state VARCHAR(20),investment_date DATE); INSERT INTO network_towers (tower_id,state,investment_date) VALUES (1,'California','2017-12-31'),(2,'California','2018-01-02'),(3,'Texas','2018-01-01');
|
SELECT tower_id, state, investment_date FROM network_towers WHERE state = 'California' AND investment_date >= '2018-01-01';
|
What is the maximum revenue generated by virtual tours in France?
|
CREATE TABLE virtual_tours_france (tour_id INT,tour_name TEXT,country TEXT,revenue FLOAT); INSERT INTO virtual_tours_france (tour_id,tour_name,country,revenue) VALUES (1,'Eiffel Tower Virtual Tour','France',30000),(2,'Louvre Virtual Tour','France',35000);
|
SELECT MAX(revenue) FROM virtual_tours_france WHERE country = 'France';
|
What are the average hours of flight time per month for each pilot in the air force?
|
CREATE TABLE pilot_flight_time (pilot_name VARCHAR(20),flight_time INT,month VARCHAR(10)); INSERT INTO pilot_flight_time (pilot_name,flight_time,month) VALUES ('John',50,'January'),('John',45,'February'),('John',55,'March'),('Jane',60,'January'),('Jane',65,'February'),('Jane',70,'March');
|
SELECT pilot_name, AVG(flight_time) FROM pilot_flight_time GROUP BY pilot_name;
|
Add a new record to the 'carbon_offsets' table with id 5001, program_name 'Renewable Forests', country 'Canada', and tons_offset 50000
|
CREATE TABLE carbon_offsets (id INT PRIMARY KEY,program_name VARCHAR(100),country VARCHAR(50),tons_offset INT);
|
INSERT INTO carbon_offsets (id, program_name, country, tons_offset) VALUES (5001, 'Renewable Forests', 'Canada', 50000);
|
Which whale species has the largest median length?
|
CREATE TABLE whale_species (id INT,species VARCHAR(255),median_length FLOAT); INSERT INTO whale_species (id,species,median_length) VALUES (1,'Blue Whale',25);
|
SELECT species, MAX(median_length) FROM whale_species GROUP BY species ORDER BY MAX(median_length) DESC LIMIT 1
|
How many shared bikes are available in Beijing as of 2022-03-15?
|
CREATE TABLE shared_bikes (bike_id int,city varchar(20),registration_date date); INSERT INTO shared_bikes (bike_id,city,registration_date) VALUES (1,'Beijing','2021-08-12'),(2,'Beijing','2022-02-24'),(3,'Beijing','2022-03-10');
|
SELECT COUNT(*) FROM shared_bikes WHERE city = 'Beijing' AND registration_date <= '2022-03-15';
|
How many community engagement events were held in each region?
|
CREATE TABLE CommunityEvents (event_id INT,region VARCHAR(50),event_type VARCHAR(50)); INSERT INTO CommunityEvents (event_id,region,event_type) VALUES (1,'North','Workshop'),(2,'South','Concert'),(3,'East','Lecture'),(4,'West','Festival');
|
SELECT region, COUNT(*) as event_count FROM CommunityEvents GROUP BY region;
|
What is the total budget allocated to parks in each borough?
|
CREATE TABLE budget_allocations (allocation_id INT,borough TEXT,category TEXT,budget INT); INSERT INTO budget_allocations (allocation_id,borough,category,budget) VALUES (1,'Manhattan','Parks',5000000),(2,'Brooklyn','Libraries',3000000),(3,'Bronx','Parks',2000000);
|
SELECT borough, SUM(budget) FROM budget_allocations WHERE category = 'Parks' GROUP BY borough;
|
Find companies founded by individuals who identify as Black or African American that have raised funds.
|
CREATE TABLE company (id INT,name TEXT,founder_race TEXT); INSERT INTO company (id,name,founder_race) VALUES (1,'Acme Inc','Black'),(2,'Beta Corp','White'),(3,'Gamma PLC','Asian'); CREATE TABLE investment (investor_id INT,company_id INT); INSERT INTO investment (investor_id,company_id) VALUES (1,1),(2,3);
|
SELECT * FROM company WHERE founder_race = 'Black' AND id IN (SELECT company_id FROM investment)
|
Show customer usage patterns for mobile and broadband subscribers in 'urban' regions.
|
CREATE TABLE customer_usage (id INT,subscriber_id INT,service VARCHAR(20),usage INT); INSERT INTO customer_usage (id,subscriber_id,service,usage) VALUES (1,1001,'mobile',500);
|
SELECT subscriber_id, service, usage FROM customer_usage WHERE service IN ('mobile', 'broadband') AND (SELECT region FROM mobile_subscribers WHERE id = subscriber_id) = 'urban';
|
Delete records of Blue Harvest vendor from the sustainable_vendors table
|
CREATE TABLE sustainable_vendors (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255));
|
DELETE FROM sustainable_vendors WHERE name = 'Blue Harvest';
|
Identify AI companies with more than 50 employees that have not published any explainable AI research papers in the last 2 years?
|
CREATE TABLE ai_companies (id INT,name VARCHAR(100),employees INT,last_paper_year INT); CREATE TABLE explainable_papers (id INT,company_id INT,title VARCHAR(100),year INT);
|
SELECT name FROM ai_companies WHERE employees > 50 AND last_paper_year < YEAR(CURRENT_DATE) - 2 AND id NOT IN (SELECT company_id FROM explainable_papers WHERE year BETWEEN YEAR(CURRENT_DATE) - 2 AND YEAR(CURRENT_DATE));
|
What is the average number of accommodations provided per student with intellectual disabilities in each school?
|
CREATE TABLE Accommodations (Student VARCHAR(255),School VARCHAR(255),Accommodation VARCHAR(255)); INSERT INTO Accommodations (Student,School,Accommodation) VALUES ('Student1','SchoolA','Visual Aids'),('Student2','SchoolA','Modified Curriculum'),('Student3','SchoolB','Visual Aids');
|
SELECT School, AVG(CountOfAccommodations) as AverageAccommodationsPerStudent FROM (SELECT School, Student, COUNT(*) as CountOfAccommodations FROM Accommodations WHERE Accommodation LIKE '%Intellectual Disability%' GROUP BY School, Student) as Subquery GROUP BY School;
|
What is the average sea level rise, grouped by year?
|
CREATE TABLE sea_level_rise (id INT,year INT,rise FLOAT); INSERT INTO sea_level_rise (id,year,rise) VALUES (1,2000,1.5); INSERT INTO sea_level_rise (id,year,rise) VALUES (2,2005,1.8); INSERT INTO sea_level_rise (id,year,rise) VALUES (3,2010,2.1);
|
SELECT year, AVG(rise) FROM sea_level_rise GROUP BY year;
|
How many diversion programs exist in Native American communities in the US compared to those in Canada?
|
CREATE TABLE us_diversion_programs (id INT,community VARCHAR(255),num_programs INT); INSERT INTO us_diversion_programs (id,community,num_programs) VALUES (1,'Navajo Nation',10),(2,'Cherokee Nation',15),(3,'Sioux Nation',8);CREATE TABLE canada_diversion_programs (id INT,community VARCHAR(255),num_programs INT); INSERT INTO canada_diversion_programs (id,community,num_programs) VALUES (1,'First Nations',12),(2,'Inuit',6),(3,'Métis',9);
|
SELECT 'USA' AS country, community, SUM(num_programs) AS total_programs FROM us_diversion_programs GROUP BY community UNION ALL SELECT 'Canada' AS country, community, SUM(num_programs) AS total_programs FROM canada_diversion_programs GROUP BY community;
|
Show safety testing scores for vehicles manufactured in Japan
|
CREATE TABLE safety_scores (id INT,vehicle VARCHAR(50),make VARCHAR(50),country VARCHAR(50),score INT); INSERT INTO safety_scores VALUES (1,'Model S','Tesla','USA',92); INSERT INTO safety_scores VALUES (2,'Prius','Toyota','Japan',89);
|
SELECT * FROM safety_scores WHERE country = 'Japan';
|
List the names of customers who have a savings balance greater than $7000.
|
CREATE TABLE customers (id INT,name TEXT,region TEXT,savings REAL);
|
SELECT customers.name FROM customers WHERE savings > 7000;
|
How many species of mammals are present in the 'Arctic_Mammals' table, but not in the 'Endangered_Species' table?
|
CREATE TABLE Arctic_Mammals (ID INT,Name VARCHAR(50),Population INT,Status VARCHAR(50)); INSERT INTO Arctic_Mammals VALUES (1,'Polar Bear',1000,'Least Concern'); INSERT INTO Arctic_Mammals VALUES (2,'Walrus',2000,'Least Concern'); INSERT INTO Arctic_Mammals VALUES (3,'Arctic Fox',1500,'Vulnerable'); CREATE TABLE Endangered_Species (ID INT,Name VARCHAR(50),Population INT,Status VARCHAR(50)); INSERT INTO Endangered_Species VALUES (1,'Polar Bear',1000,'Vulnerable'); INSERT INTO Endangered_Species VALUES (2,'Walrus',2000,'Near Threatened');
|
SELECT COUNT(*) FROM Arctic_Mammals EXCEPT SELECT * FROM Endangered_Species;
|
What is the average mental health score of students per age group?
|
CREATE TABLE student_demographics (student_id INT,age INT,mental_health_score INT);
|
SELECT age, AVG(mental_health_score) FROM student_demographics GROUP BY age;
|
What is the total quantity of vegetarian menu items sold in the month of January 2022?
|
CREATE TABLE menu (menu_id INT,menu_name VARCHAR(255),is_vegetarian BOOLEAN,quantity_sold INT); INSERT INTO menu (menu_id,menu_name,is_vegetarian,quantity_sold) VALUES (1,'Quinoa Salad',TRUE,25),(2,'Margherita Pizza',FALSE,30),(3,'Vegetable Curry',TRUE,40);
|
SELECT SUM(quantity_sold) FROM menu WHERE is_vegetarian = TRUE AND MONTH(order_date) = 1;
|
What is the earliest year in which a high level threat occurred in each region?
|
CREATE TABLE national_security (id INT PRIMARY KEY,threat VARCHAR(50),level VARCHAR(50),region VARCHAR(50),year INT); INSERT INTO national_security (id,threat,level,region,year) VALUES (5,'Cyber Warfare','High','North America',2012); INSERT INTO national_security (id,threat,level,region,year) VALUES (6,'Cyber Theft','Medium','Asia',2017);
|
SELECT region, MIN(year) as first_threat_year FROM national_security WHERE level = 'High' GROUP BY region;
|
How many times has a specific IP address appeared in the IDS logs in the last month?
|
CREATE TABLE ids_logs (id INT,timestamp TIMESTAMP,ip_address VARCHAR(255)); INSERT INTO ids_logs (id,timestamp,ip_address) VALUES (1,'2022-01-01 12:00:00','172.16.0.1'),(2,'2022-01-02 10:30:00','192.168.0.1');
|
SELECT COUNT(*) as num_occurrences FROM ids_logs WHERE ip_address = '192.168.0.1' AND timestamp >= NOW() - INTERVAL 1 MONTH;
|
What is the percentage of female workers at each mine site?
|
CREATE TABLE workforce_diversity (site_id INT,site_name TEXT,worker_id INT,worker_role TEXT,gender TEXT,age INT); INSERT INTO workforce_diversity (site_id,site_name,worker_id,worker_role,gender,age) VALUES (1,'ABC Mine',1001,'Mining Engineer','Female',28),(2,'DEF Mine',2001,'Miner','Male',45),(3,'GHI Mine',3001,'Safety Manager','Male',50),(1,'ABC Mine',1002,'Geologist','Female',32),(2,'DEF Mine',2002,'Miner','Female',38);
|
SELECT site_name, (COUNT(*) FILTER (WHERE gender = 'Female')) * 100.0 / COUNT(*) as percentage_female FROM workforce_diversity GROUP BY site_name;
|
Calculate the total waste generated in 'Tokyo' and 'Osaka'
|
CREATE TABLE waste_generation (id INT,city VARCHAR(20),amount INT); INSERT INTO waste_generation (id,city,amount) VALUES (1,'Tokyo',5000),(2,'Osaka',3000);
|
SELECT SUM(amount) FROM waste_generation WHERE city IN ('Tokyo', 'Osaka');
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.