instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
Which female game designers have created RPG games with more than 10,000 players?
|
CREATE TABLE game_designers (designer_id INT,gender VARCHAR(10),genre VARCHAR(10),players INT);
|
SELECT COUNT(*) FROM game_designers WHERE gender = 'female' AND genre = 'RPG' AND players > 10000;
|
List REE environmental impact statistics for each year since 2017?
|
CREATE TABLE environmental_impact (year INT,impact_statistic VARCHAR(255)); INSERT INTO environmental_impact (year,impact_statistic) VALUES (2017,'Carbon emissions: 5000 tons'),(2018,'Water usage: 20000 cubic meters'),(2019,'Energy consumption: 15000 MWh'),(2020,'Waste generation: 8000 tons'),(2021,'Land degradation: 20 hectares');
|
SELECT year, impact_statistic FROM environmental_impact;
|
Count the number of posts that have more than 100 likes in the 'social_media' table.
|
CREATE TABLE social_media (user_id INT,post_id INT,post_date DATE,likes INT);
|
SELECT COUNT(*) FROM social_media WHERE likes > 100;
|
What is the total number of trips and average trip duration for public transportation in Paris?
|
CREATE TABLE public_transportation (id INT,trip_id INT,mode VARCHAR(255),start_time TIMESTAMP,end_time TIMESTAMP,city VARCHAR(255)); INSERT INTO public_transportation (id,trip_id,mode,start_time,end_time,city) VALUES (1,123,'Metro','2022-01-01 08:00:00','2022-01-01 08:15:00','Paris'); INSERT INTO public_transportation (id,trip_id,mode,start_time,end_time,city) VALUES (2,456,'Bus','2022-01-01 09:30:00','2022-01-01 10:00:00','Paris');
|
SELECT COUNT(DISTINCT trip_id) as total_trips, AVG(TIMESTAMPDIFF(MINUTE, start_time, end_time)) as avg_duration FROM public_transportation WHERE city = 'Paris';
|
How many water conservation initiatives were implemented in Australia for the year 2017 and 2018?
|
CREATE TABLE conservation_initiatives (id INT,country VARCHAR(50),year INT,initiatives INT); INSERT INTO conservation_initiatives (id,country,year,initiatives) VALUES (1,'Australia',2017,10),(2,'Australia',2018,15),(3,'Australia',2019,20),(4,'Canada',2017,12),(5,'Canada',2018,14),(6,'Canada',2019,16);
|
SELECT SUM(initiatives) FROM conservation_initiatives WHERE country = 'Australia' AND year IN (2017, 2018);
|
List the name and type of all armaments that have been supplied to peacekeeping operations by each country from the 'Armaments', 'Countries', and 'Supplies' tables
|
CREATE TABLE Armaments (name TEXT,type TEXT); CREATE TABLE Countries (country TEXT,peacekeeping_operation TEXT); CREATE TABLE Supplies (armament TEXT,country TEXT); INSERT INTO Armaments (name,type) VALUES ('AK-47','Assault Rifle'),('M16','Assault Rifle'),('Carl Gustaf','Recoilless Rifle'); INSERT INTO Countries (country,peacekeeping_operation) VALUES ('United States','MINUSMA'),('China','MONUSCO'),('Russia','UNMISS'); INSERT INTO Supplies (armament,country) VALUES ('AK-47','United States'),('Carl Gustaf','China'),('M16','Russia');
|
SELECT Armaments.name, Armaments.type, Countries.country FROM Armaments INNER JOIN (Supplies INNER JOIN Countries ON Supplies.country = Countries.country) ON Armaments.name = Supplies.armament;
|
What is the maximum depth of all deep-sea trenches in the Pacific Ocean?
|
CREATE TABLE deep_sea_trenches (name VARCHAR(255),region VARCHAR(255),depth FLOAT);INSERT INTO deep_sea_trenches (name,region,depth) VALUES ('Trench 1','Pacific Ocean',8000),('Trench 2','Atlantic Ocean',7000),('Trench 3','Pacific Ocean',10000);
|
SELECT MAX(depth) FROM deep_sea_trenches WHERE region = 'Pacific Ocean';
|
How many cases were resolved using restorative justice practices in the cases table in each year?
|
CREATE TABLE cases (id INT,year INT,restorative_justice BOOLEAN);
|
SELECT year, COUNT(*) FROM cases WHERE restorative_justice = TRUE GROUP BY year;
|
What is the total revenue generated by local tour operators in Germany for the year 2022?
|
CREATE TABLE LocalTourOperators (name VARCHAR(50),location VARCHAR(20),year INT,revenue DECIMAL(10,2));
|
SELECT SUM(revenue) FROM LocalTourOperators WHERE location = 'Germany' AND year = 2022;
|
List the top 2 cultural heritage sites in Paris by visitor count.
|
CREATE TABLE cultural_sites_paris (site_id INT,name TEXT,city TEXT,visitors INT); INSERT INTO cultural_sites_paris (site_id,name,city,visitors) VALUES (1,'Eiffel Tower','Paris',7000000),(2,'Notre Dame Cathedral','Paris',6000000),(3,'Louvre Museum','Paris',5000000);
|
SELECT name, visitors FROM cultural_sites_paris WHERE city = 'Paris' ORDER BY visitors DESC LIMIT 2;
|
What is the number of items produced in each country in 2021?
|
CREATE TABLE items_produced (product_id INT,country VARCHAR(255),year INT); INSERT INTO items_produced (product_id,country,year) VALUES (1,'USA',2021),(2,'Canada',2022),(3,'Mexico',2021),(4,'USA',2021);
|
SELECT country, COUNT(*) as items_produced FROM items_produced WHERE year = 2021 GROUP BY country;
|
What is the average number of successful cases handled by attorneys who identify as non-binary?
|
CREATE TABLE attorneys (attorney_id INT,gender VARCHAR(20),successful_cases INT); INSERT INTO attorneys (attorney_id,gender,successful_cases) VALUES (1,'Female',12),(2,'Male',8),(3,'Non-binary',7);
|
SELECT AVG(successful_cases) FROM attorneys WHERE gender = 'Non-binary';
|
Identify the cruelty-free certified products and their safety records.
|
CREATE TABLE SafetyRecord (ProductID INT,SafetyTestDate DATE,Result VARCHAR(255)); INSERT INTO SafetyRecord (ProductID,SafetyTestDate,Result) VALUES (8,'2022-06-01','Pass'),(8,'2022-07-01','Pass'),(9,'2022-06-05','Pass'); CREATE TABLE Product (ProductID INT,ProductName VARCHAR(255),Price DECIMAL(5,2)); INSERT INTO Product (ProductID,ProductName,Price) VALUES (8,'Foundation',29.99),(9,'Highlighter',24.99); CREATE TABLE CrueltyFree (ProductID INT,CertificationDate DATE); INSERT INTO CrueltyFree (ProductID,CertificationDate) VALUES (8,'2022-01-15'),(9,'2022-02-20');
|
SELECT P.ProductName, SR.Result FROM CrueltyFree CF INNER JOIN Product P ON CF.ProductID = P.ProductID INNER JOIN SafetyRecord SR ON P.ProductID = SR.ProductID;
|
What is the total number of members in the 'healthcare_union' table?
|
CREATE TABLE healthcare_union (member_id INT,union_name VARCHAR(20)); INSERT INTO healthcare_union (member_id,union_name) VALUES (1,'Healthcare Workers Union'),(2,'Nurses Union'),(3,'Doctors Union');
|
SELECT COUNT(*) FROM healthcare_union;
|
Show the energy efficiency (kWh/m2) of buildings in Sydney
|
CREATE TABLE building_efficiency (id INT,city VARCHAR(50),efficiency FLOAT); INSERT INTO building_efficiency (id,city,efficiency) VALUES (1,'Tokyo',120),(2,'Osaka',110),(3,'Sydney',140);
|
SELECT efficiency FROM building_efficiency WHERE city = 'Sydney';
|
List all suppliers from 'Down to Earth' that provide organic products.
|
CREATE TABLE Suppliers (name text,product text,is_organic boolean); INSERT INTO Suppliers (name,product,is_organic) VALUES ('Down to Earth','Quinoa',true),('Down to Earth','Rice',false),('Fresh Harvest','Carrots',true);
|
SELECT DISTINCT name FROM Suppliers WHERE is_organic = true AND name = 'Down to Earth';
|
How many students are enrolled in lifelong learning programs in each continent?
|
CREATE TABLE student_enrollment (student_id INT,continent VARCHAR(50),program VARCHAR(50)); INSERT INTO student_enrollment (student_id,continent,program) VALUES (1,'North America','Lifelong Learning 101'),(2,'Europe','Lifelong Learning 202'),(3,'Asia','Lifelong Learning 101');
|
SELECT continent, COUNT(DISTINCT student_id) as num_students FROM student_enrollment GROUP BY continent;
|
What is the average Gadolinium production by month for 2021 and 2022?
|
CREATE TABLE mines (id INT,name TEXT,location TEXT,gadolinium_production FLOAT,timestamp DATE); INSERT INTO mines (id,name,location,gadolinium_production,timestamp) VALUES (1,'Mine A','Canada',120.5,'2021-01-01'),(2,'Mine B','Canada',150.7,'2021-02-01'),(3,'Mine C','USA',200.3,'2021-03-01'),(4,'Mine D','Canada',250.3,'2022-01-01'),(5,'Mine E','USA',300.3,'2022-02-01');
|
SELECT MONTH(timestamp), AVG(gadolinium_production) FROM mines WHERE YEAR(timestamp) IN (2021, 2022) GROUP BY MONTH(timestamp);
|
What is the total number of transactions for each gender?
|
CREATE TABLE Transactions (transaction_id INT,user_id INT,gender VARCHAR(10),transaction_amount DECIMAL(10,2)); INSERT INTO Transactions (transaction_id,user_id,gender,transaction_amount) VALUES (1,101,'Male',50.00),(2,102,'Female',75.00),(3,103,'Non-binary',35.00),(4,104,'Male',60.00);
|
SELECT gender, SUM(transaction_amount) as total_amount FROM Transactions GROUP BY gender;
|
What is the number of startups founded by people who identify as LGBTQ+ in the education technology industry?
|
CREATE TABLE company (id INT,name TEXT,founder_lgbtq INT,industry TEXT); INSERT INTO company (id,name,founder_lgbtq,industry) VALUES (1,'EduTech',1,'Education Technology'); INSERT INTO company (id,name,founder_lgbtq,industry) VALUES (2,'LearningPlatforms',0,'Education Technology');
|
SELECT COUNT(*) FROM company WHERE founder_lgbtq = 1 AND industry = 'Education Technology';
|
What is the total number of animals in habitats larger than 100 square kilometers?
|
CREATE TABLE habitat (id INT,size FLOAT); CREATE TABLE animal_population (id INT,habitat_id INT,animal_count INT);
|
SELECT SUM(ap.animal_count) FROM animal_population ap INNER JOIN habitat h ON ap.habitat_id = h.id WHERE h.size > 100;
|
List all smart city technology adoptions in the North American cities with a population greater than 1 million.
|
CREATE TABLE smart_city_tech (tech_id INT,tech_name VARCHAR(30),city VARCHAR(20),population INT); INSERT INTO smart_city_tech (tech_id,tech_name,city,population) VALUES (1,'Smart Grids','New York',8500000),(2,'Smart Lighting','Los Angeles',4000000),(3,'Smart Traffic Management','Toronto',3000000);
|
SELECT tech_name, city FROM smart_city_tech WHERE population > 1000000 AND city IN ('New York', 'Los Angeles', 'Toronto');
|
List all green building materials and the number of each material used in a specific city, for projects in London.
|
CREATE TABLE GreenBuildingMaterials (MaterialID INT,MaterialName VARCHAR(50));CREATE TABLE GreenBuildingMaterialsUsage (UsageID INT,MaterialID INT,CityID INT,ProjectID INT);
|
SELECT GreenBuildingMaterials.MaterialName, COUNT(GreenBuildingMaterialsUsage.UsageID) FROM GreenBuildingMaterials INNER JOIN GreenBuildingMaterialsUsage ON GreenBuildingMaterials.MaterialID = GreenBuildingMaterialsUsage.MaterialID WHERE GreenBuildingMaterialsUsage.CityID = 2 GROUP BY GreenBuildingMaterials.MaterialName;
|
What is the average age of refugees supported by 'Red Crescent' in 'Europe'?
|
CREATE TABLE refugee (id INT,name VARCHAR(255),age INT,location VARCHAR(255),supported_by VARCHAR(255),support_date DATE); INSERT INTO refugee (id,name,age,location,supported_by,support_date) VALUES (1,'Jane Doe',35,'Europe','Red Crescent','2022-01-01');
|
SELECT AVG(age) FROM refugee WHERE location = 'Europe' AND supported_by = 'Red Crescent';
|
What is the total number of sustainable buildings in each city?
|
CREATE TABLE building_info (info_id INT,sq_footage INT,city TEXT,sustainable BOOLEAN); INSERT INTO building_info VALUES (1,50000,'Seattle',TRUE),(2,60000,'Houston',FALSE),(3,70000,'Seattle',TRUE),(4,40000,'New York',FALSE),(5,30000,'Denver',TRUE);
|
SELECT city, COUNT(*) FILTER (WHERE sustainable = TRUE) FROM building_info GROUP BY city;
|
What is the total revenue generated by suppliers with ethical labor practices?
|
CREATE TABLE sales (sale_id INT,supplier_id INT,product_id INT,quantity INT,price DECIMAL);
|
SELECT SUM(quantity * price) FROM sales JOIN suppliers ON sales.supplier_id = suppliers.supplier_id WHERE suppliers.labor_practice = 'Ethical';
|
What is the average number of heritage sites per country in Europe?
|
CREATE TABLE Countries (id INT,name TEXT,region TEXT); INSERT INTO Countries (id,name,region) VALUES (1,'France','Europe'),(2,'Germany','Europe'); CREATE TABLE HeritageSitesEurope (id INT,country_id INT,name TEXT); INSERT INTO HeritageSitesEurope (id,country_id,name) VALUES (1,1,'Eiffel Tower'),(2,1,'Louvre Museum'),(3,2,'Brandenburg Gate'),(4,2,'Berlin Wall');
|
SELECT AVG(site_count) FROM (SELECT COUNT(HeritageSitesEurope.id) AS site_count FROM HeritageSitesEurope GROUP BY HeritageSitesEurope.country_id) AS SiteCountPerCountry
|
What is the recidivism rate for offenders released on parole in Texas in 2018?
|
CREATE TABLE recidivism (offender_id INT,release_year INT,parole INT,state VARCHAR(20)); INSERT INTO recidivism (offender_id,release_year,parole,state) VALUES (1,2018,1,'Texas'),(2,2017,0,'Texas');
|
SELECT (SUM(parole = 1) / COUNT(*)) * 100 AS recidivism_rate FROM recidivism WHERE state = 'Texas' AND release_year = 2018;
|
Show menu items with higher prices than the least popular entrée.
|
CREATE TABLE popularity (menu_id INT,popularity INT); INSERT INTO popularity (menu_id,popularity) VALUES (1,10),(2,20),(3,30),(4,40),(5,50);
|
SELECT menu_name, price FROM menus WHERE menu_type = 'Entree' AND price > (SELECT MIN(price) FROM menus WHERE menu_type = 'Entree') AND menu_id NOT IN (SELECT menu_id FROM popularity WHERE popularity = (SELECT MIN(popularity) FROM popularity));
|
What is the total number of cases heard by each judge, ordered by total cases in descending order?
|
CREATE TABLE judges (judge_id INT,name VARCHAR(50),court_id INT); INSERT INTO judges (judge_id,name,court_id) VALUES (1,'John Doe',1001),(2,'Jane Smith',1002),(3,'Robert Johnson',1003); CREATE TABLE cases (case_id INT,judge_id INT,court_date DATE); INSERT INTO cases (case_id,judge_id,court_date) VALUES (101,1,'2021-01-01'),(102,1,'2021-02-01'),(103,2,'2021-03-01'),(104,3,'2021-04-01'),(105,3,'2021-05-01');
|
SELECT judge_id, COUNT(*) as total_cases FROM cases GROUP BY judge_id ORDER BY total_cases DESC;
|
How many tourists visited Canada for adventure tourism in Q3 of 2021 and Q1 of 2022?
|
CREATE TABLE visitor_data (id INT,country VARCHAR(255),visit_quarter INT,visit_year INT,visit_type VARCHAR(255)); INSERT INTO visitor_data (id,country,visit_quarter,visit_year,visit_type) VALUES (1,'Canada',3,2021,'adventure-tourism'),(2,'Canada',1,2022,'adventure-tourism');
|
SELECT SUM(id) FROM visitor_data WHERE country = 'Canada' AND visit_type = 'adventure-tourism' AND (visit_quarter = 3 AND visit_year = 2021 OR visit_quarter = 1 AND visit_year = 2022);
|
What is the average level achieved by users in "Quantum Shift" for each continent, excluding the lowest 5 levels?
|
CREATE TABLE PlayerProgress (PlayerID INT,GameName VARCHAR(20),Level INT,Completion BOOLEAN,PlayerContinent VARCHAR(30)); INSERT INTO PlayerProgress (PlayerID,GameName,Level,Completion,PlayerContinent) VALUES (1,'Quantum Shift',10,true,'North America'),(2,'Quantum Shift',15,true,'Europe'),(3,'Quantum Shift',5,false,'North America'),(4,'Quantum Shift',20,true,'South America'),(5,'Quantum Shift',7,false,'Europe'),(6,'Quantum Shift',18,true,'Asia'),(7,'Quantum Shift',12,false,'Asia'),(8,'Quantum Shift',14,true,'Africa');
|
SELECT PlayerContinent, AVG(Level) AS avg_level FROM (SELECT PlayerContinent, Level FROM PlayerProgress WHERE GameName = 'Quantum Shift' GROUP BY PlayerContinent, Level HAVING COUNT(*) > 4) AS filtered_data GROUP BY PlayerContinent;
|
What is the total revenue for concerts and streams in Australia, grouped by year and quarter.
|
CREATE TABLE Concerts (id INT,date DATE,revenue FLOAT); CREATE TABLE Streams (song_id INT,date DATE,revenue FLOAT);
|
SELECT YEAR(date) AS year, QUARTER(date) AS quarter, SUM(Concerts.revenue) + SUM(Streams.revenue) FROM Concerts INNER JOIN Streams ON YEAR(Concerts.date) = YEAR(Streams.date) AND QUARTER(Concerts.date) = QUARTER(Streams.date) WHERE Concerts.country = 'Australia' GROUP BY year, quarter;
|
How many heritage sites are in Mexico and Brazil?
|
CREATE TABLE heritage_sites (id INT,country TEXT,site_name TEXT); INSERT INTO heritage_sites (id,country,site_name) VALUES (1,'Mexico','Palace of Fine Arts'),(2,'Mexico','Historic Centre of Mexico City and Xochimilco'),(3,'Brazil','Historic Centre of Salvador de Bahia'),(4,'Brazil','Iguaçu National Park');
|
SELECT country, COUNT(*) FROM heritage_sites GROUP BY country HAVING country IN ('Mexico', 'Brazil');
|
Which dispensaries in California have a license but haven't made any sales?
|
CREATE TABLE dispensaries (id INT,name TEXT,state TEXT); INSERT INTO dispensaries (id,name,state) VALUES (1,'Dispensary A','California'),(2,'Dispensary B','California'); CREATE TABLE licenses (id INT,dispensary_id INT,status TEXT); INSERT INTO licenses (id,dispensary_id,status) VALUES (1,1,'active'),(2,2,'active'); CREATE TABLE sales (id INT,dispensary_id INT,quantity INT);
|
SELECT d.name FROM dispensaries d JOIN licenses l ON d.id = l.dispensary_id LEFT JOIN sales s ON d.id = s.dispensary_id WHERE d.state = 'California' AND s.id IS NULL;
|
How many graduate students have not enrolled in any courses in the Spring semester?
|
CREATE TABLE GraduateStudents (StudentID int,Name varchar(50),Department varchar(50)); CREATE TABLE Enrollment (StudentID int,Course varchar(50),Semester varchar(50)); INSERT INTO GraduateStudents (StudentID,Name,Department) VALUES (1,'Alice Johnson','Computer Science'); INSERT INTO GraduateStudents (StudentID,Name,Department) VALUES (2,'Bob Brown','Computer Science'); INSERT INTO Enrollment (StudentID,Course,Semester) VALUES (1,'Database Systems','Fall'); INSERT INTO Enrollment (StudentID,Course,Semester) VALUES (1,'Artificial Intelligence','Spring'); INSERT INTO Enrollment (StudentID,Course,Semester) VALUES (2,'Database Systems','Fall'); INSERT INTO Enrollment (StudentID,Course,Semester) VALUES (3,'Operating Systems','Fall');
|
SELECT COUNT(*) FROM GraduateStudents WHERE StudentID NOT IN (SELECT StudentID FROM Enrollment WHERE Semester = 'Spring');
|
List the exhibition titles and the number of artworks in each exhibit from the galleries 'Impressionism' and 'Surrealism'.
|
CREATE TABLE Exhibits (ExhibitID int,Gallery varchar(50),ArtworkID int); CREATE TABLE ExhibitionTitles (ExhibitID int,Title varchar(50)); INSERT INTO Exhibits (ExhibitID,Gallery,ArtworkID) VALUES (1,'Impressionism',101),(2,'Impressionism',102),(3,'Surrealism',201); INSERT INTO ExhibitionTitles (ExhibitID,Title) VALUES (1,'Impressionist Masterpieces'),(2,'Post-Impressionism'),(3,'Surrealist Dreams');
|
SELECT e.Gallery, et.Title, COUNT(e.ArtworkID) AS ArtworkCount FROM Exhibits e INNER JOIN ExhibitionTitles et ON e.ExhibitID = et.ExhibitID WHERE e.Gallery IN ('Impressionism', 'Surrealism') GROUP BY e.Gallery, et.Title;
|
How many climate mitigation projects were completed in the Asia-Pacific region?
|
CREATE TABLE climate_projects (region VARCHAR(255),status VARCHAR(255),type VARCHAR(255));
|
SELECT COUNT(*) FROM climate_projects WHERE region = 'Asia-Pacific' AND type = 'climate mitigation' AND status = 'completed';
|
Insert records of new providers in Texas offering primary care, mental health, and dental services.
|
CREATE TABLE providers (id INT,name TEXT,service TEXT,location TEXT);
|
INSERT INTO providers (id, name, service, location) VALUES (1, 'Lone Star Care', 'Primary Care', 'Texas'); INSERT INTO providers (id, name, service, location) VALUES (2, 'Rio Grande Care', 'Mental Health', 'Texas'); INSERT INTO providers (id, name, service, location) VALUES (3, 'Star of Texas Dental', 'Dental', 'Texas')
|
What is the average time to resolve critical vulnerabilities in the healthcare sector in the last 6 months?
|
CREATE TABLE vulnerabilities (vulnerability_id INT,vulnerability_severity VARCHAR(255),sector VARCHAR(255),resolution_time INT); INSERT INTO vulnerabilities (vulnerability_id,vulnerability_severity,sector,resolution_time) VALUES (1,'Critical','Financial',7),(2,'High','Financial',12),(3,'Medium','Healthcare',23),(4,'Low','Retail',34),(5,'Critical','Healthcare',45),(6,'High','Healthcare',56),(7,'Medium','Financial',67);
|
SELECT AVG(resolution_time) as avg_resolution_time FROM vulnerabilities WHERE sector = 'Healthcare' AND vulnerability_severity = 'Critical' AND resolution_time > 0 AND resolution_time IS NOT NULL AND resolution_time < 1000 AND vulnerability_date >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH);
|
What is the sales ratio of ethical material types in the UK to those in Australia?
|
CREATE TABLE materials (id INT,country VARCHAR(255),type VARCHAR(255),sales FLOAT,profits FLOAT); INSERT INTO materials (id,country,type,sales,profits) VALUES (1,'UK','Organic Cotton',500,250),(2,'Australia','Hemp',600,360),(3,'UK','Recycled Polyester',700,350),(4,'Australia','Organic Cotton',800,400);
|
SELECT a.type, a.sales / b.sales as sales_ratio FROM materials a JOIN materials b ON a.type = b.type WHERE a.country = 'UK' AND b.country = 'Australia';
|
Show all tables related to algorithmic fairness.
|
CREATE TABLE algorithmic_fairness (table_name VARCHAR(255)); INSERT INTO algorithmic_fairness (table_name) VALUES ('disparate_impact'),('equal_opportunity'),('demographic_parity');
|
SELECT table_name FROM algorithmic_fairness
|
List the name and category of cybersecurity strategies with a risk rating above 3.
|
CREATE SCHEMA IF NOT EXISTS cybersecurity_strategies; CREATE TABLE IF NOT EXISTS strategy_risk (id INT PRIMARY KEY,name TEXT,category TEXT,risk_rating INT); INSERT INTO strategy_risk (id,name,category,risk_rating) VALUES (1,'Firewalls','Network Security',2),(2,'Penetration Testing','Vulnerability Management',5),(3,'Intrusion Detection Systems','Network Security',3);
|
SELECT name, category FROM cybersecurity_strategies.strategy_risk WHERE risk_rating > 3;
|
What is the average amount of waste generated per month for the silver mines?
|
CREATE TABLE WasteGenerated (WasteID INT,MineID INT,WasteDate DATE,WasteAmount INT);
|
SELECT AVG(WasteAmount) FROM WasteGenerated WHERE (SELECT MineType FROM Mines WHERE Mines.MineID = WasteGenerated.MineID) = 'Silver' GROUP BY MONTH(WasteDate), YEAR(WasteDate);
|
Which sustainable building practices were implemented in New York?
|
CREATE TABLE sustainable_practices (practice_id INT,building_id INT,city VARCHAR(20)); INSERT INTO sustainable_practices (practice_id,building_id,city) VALUES (1,101,'New York'),(2,101,'New York'),(3,102,'Los Angeles'),(5,103,'New York');
|
SELECT DISTINCT city, building_type FROM sustainable_practices SP JOIN (SELECT building_id, 'Solar Panels' as building_type FROM sustainable_practices WHERE practice_id = 1 UNION ALL SELECT building_id, 'Green Roofs' as building_type FROM sustainable_practices WHERE practice_id = 2) AS subquery ON SP.building_id = subquery.building_id WHERE city = 'New York';
|
What are the products made by BIPOC-owned suppliers?
|
CREATE TABLE suppliers (id INT PRIMARY KEY,name TEXT,race TEXT,sustainable_practices BOOLEAN); CREATE TABLE products (id INT PRIMARY KEY,name TEXT,supplier_id INT,FOREIGN KEY (supplier_id) REFERENCES suppliers(id));
|
SELECT products.name, suppliers.name AS supplier_name FROM products INNER JOIN suppliers ON products.supplier_id = suppliers.id WHERE suppliers.race = 'BIPOC';
|
How many subscribers are there in each region?
|
CREATE TABLE subscribers (subscriber_id INT,name VARCHAR(50),region VARCHAR(50),subscribed_date DATE); INSERT INTO subscribers VALUES (1,'John Doe','RegionA','2022-01-01'); INSERT INTO subscribers VALUES (2,'Jane Smith','RegionB','2022-02-15'); INSERT INTO subscribers VALUES (3,'Mike Johnson','RegionA','2022-03-05');
|
SELECT region, COUNT(*) as num_subscribers FROM subscribers GROUP BY region;
|
List all marine species in the 'marine_species' table, ordered alphabetically
|
CREATE TABLE marine_species (id INT PRIMARY KEY,species_name VARCHAR(255),conservation_status VARCHAR(255)); INSERT INTO marine_species (id,species_name,conservation_status) VALUES (1001,'Oceanic Whitetip Shark','Vulnerable'),(1002,'Green Sea Turtle','Threatened'),(1003,'Leatherback Sea Turtle','Vulnerable'),(1004,'Hawksbill Sea Turtle','Endangered');
|
SELECT species_name FROM marine_species ORDER BY species_name ASC;
|
Who were the top 3 employers of construction laborers in Texas in 2020?
|
CREATE TABLE ConstructionEmployers (id INT,name TEXT,state TEXT,year INT,numEmployees INT);
|
SELECT name FROM ConstructionEmployers WHERE state = 'Texas' AND year = 2020 ORDER BY numEmployees DESC LIMIT 3;
|
List all shark species in the Indian Ocean.
|
CREATE TABLE sharks (name TEXT,region TEXT); INSERT INTO sharks (name,region) VALUES ('Tiger Shark','Indian'),('Great White','Atlantic'),('Hammerhead','Pacific');
|
SELECT name FROM sharks WHERE region = 'Indian';
|
How many faculty members from each department identify as LGBTQ+?
|
CREATE TABLE faculty (id INT,name VARCHAR(50),department VARCHAR(50),community VARCHAR(50));
|
SELECT department, COUNT(*) FROM faculty WHERE community = 'LGBTQ+' GROUP BY department;
|
How many 'Exhibitions' and 'Theater' events did not happen in 'New York' or 'Los Angeles'?
|
CREATE TABLE Events (event_id INT,event_location VARCHAR(20),event_type VARCHAR(20),num_attendees INT); INSERT INTO Events (event_id,event_location,event_type,num_attendees) VALUES (1,'New York','Concert',500),(2,'Los Angeles','Theater',300),(3,'Chicago','Exhibition',400),(4,'San Francisco','Theater',200),(5,'Seattle','Exhibition',150);
|
SELECT event_type, COUNT(*) FROM Events WHERE event_location NOT IN ('New York', 'Los Angeles') AND event_type IN ('Exhibition', 'Theater') GROUP BY event_type;
|
What is the average financial wellbeing score of individuals in Canada with a financial education level of "high"?
|
CREATE TABLE financial_education (individual_id TEXT,financial_education TEXT,wellbeing_score NUMERIC); INSERT INTO financial_education (individual_id,financial_education,wellbeing_score) VALUES ('12345','high',78); INSERT INTO financial_education (individual_id,financial_education,wellbeing_score) VALUES ('67890','high',82);
|
SELECT AVG(wellbeing_score) FROM financial_education WHERE financial_education = 'high' AND country = 'Canada';
|
Add Tofu Stir Fry as a new menu item with a price of $12.50 and a sustainability_rating of 4 in the menu_items table
|
CREATE TABLE menu_items (menu_item_id INT,name VARCHAR(255),description TEXT,price DECIMAL(5,2),category VARCHAR(255),sustainability_rating INT);
|
INSERT INTO menu_items (name, price, sustainability_rating) VALUES ('Tofu Stir Fry', 12.50, 4);
|
Which artists have never performed at music festivals?
|
CREATE TABLE Artists (ArtistID INT,ArtistName VARCHAR(100),Age INT,Genre VARCHAR(50)); INSERT INTO Artists VALUES (1,'Artist1',35,'Rock'); INSERT INTO Artists VALUES (2,'Artist2',45,'Rock'); CREATE TABLE Festivals (FestivalID INT,FestivalName VARCHAR(100),ArtistID INT); INSERT INTO Festivals VALUES (1,'Festival1',1); INSERT INTO Festivals VALUES (2,'Festival2',2);
|
SELECT A.ArtistName FROM Artists A LEFT JOIN Festivals F ON A.ArtistID = F.ArtistID WHERE F.ArtistID IS NULL;
|
How many people have died from COVID-19 in each state in the United States?
|
CREATE TABLE covid_deaths (id INT,state TEXT,num_deaths INT); INSERT INTO covid_deaths (id,state,num_deaths) VALUES (1,'California',50000),(2,'Texas',45000),(3,'Florida',40000),(4,'New York',55000),(5,'Pennsylvania',25000),(6,'Illinois',20000),(7,'Ohio',15000),(8,'Georgia',12000),(9,'Michigan',18000),(10,'North Carolina',10000);
|
SELECT state, SUM(num_deaths) FROM covid_deaths GROUP BY state;
|
What is the total sales of organic cosmetic products per region?
|
CREATE TABLE products (product_id INT,product_name VARCHAR(255),region VARCHAR(50),sales FLOAT,organic BOOLEAN); INSERT INTO products (product_id,product_name,region,sales,organic) VALUES (1,'Lipstick A','Europe',5000,true),(2,'Foundation B','Asia',7000,false),(3,'Mascara C','Europe',6000,false),(4,'Eye-shadow D','America',8000,true),(5,'Blush E','Europe',4000,true);
|
SELECT region, SUM(sales) AS total_sales FROM products WHERE organic = true GROUP BY region;
|
What is the maximum number of followers for users from Canada who have posted about #tech in the last month?
|
CREATE TABLE users (id INT,country VARCHAR(255),followers INT); CREATE TABLE posts (id INT,user_id INT,hashtags VARCHAR(255),post_date DATE);
|
SELECT MAX(users.followers) FROM users INNER JOIN posts ON users.id = posts.user_id WHERE users.country = 'Canada' AND hashtags LIKE '%#tech%' AND post_date >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH);
|
How many FIFA World Cup goals has Miroslav Klose scored?
|
CREATE TABLE fifa_world_cup_goals (player_id INT,name VARCHAR(50),country VARCHAR(50),goals INT); INSERT INTO fifa_world_cup_goals (player_id,name,country,goals) VALUES (1,'Miroslav Klose','Germany',16);
|
SELECT goals FROM fifa_world_cup_goals WHERE name = 'Miroslav Klose';
|
What is the total funding received by organizations that have implemented digital divide initiatives and are based in either Africa or Latin America, broken down by the type of funding (government or private)?
|
CREATE TABLE funding (funding_id INT,org_id INT,amount INT,funding_type VARCHAR(50),region VARCHAR(50)); INSERT INTO funding (funding_id,org_id,amount,funding_type,region) VALUES (1,1,100000,'government','Africa'),(2,1,200000,'private','Africa'),(3,2,150000,'private','Asia'),(4,3,50000,'government','Latin America'); CREATE TABLE organizations (org_id INT,name VARCHAR(50),implemented_digital_divide BOOLEAN); INSERT INTO organizations (org_id,name,implemented_digital_divide) VALUES (1,'Digital Divide Africa Inc.',TRUE),(2,'Asian Tech Inc.',FALSE),(3,'Latin America Tech',TRUE),(4,'Non-profit Tech',FALSE);
|
SELECT implemented_digital_divide, funding_type, region, SUM(amount) FROM funding INNER JOIN organizations ON funding.org_id = organizations.org_id WHERE implemented_digital_divide = TRUE AND (region = 'Africa' OR region = 'Latin America') GROUP BY implemented_digital_divide, funding_type, region;
|
What is the average salary for each department, along with the number of employees in that department?
|
CREATE TABLE Employees (EmployeeID INT,FirstName VARCHAR(50),LastName VARCHAR(50),Department VARCHAR(50),Salary DECIMAL(10,2)); INSERT INTO Employees (EmployeeID,FirstName,LastName,Department,Salary) VALUES (1,'John','Doe','Mining',75000.00); INSERT INTO Employees (EmployeeID,FirstName,LastName,Department,Salary) VALUES (2,'Jane','Doe','Environment',70000.00); INSERT INTO Employees (EmployeeID,FirstName,LastName,Department,Salary) VALUES (3,'Mike','Smith','Mining',80000.00);
|
SELECT Department, AVG(Salary) as 'AvgSalary', COUNT(*) as 'EmployeeCount' FROM Employees GROUP BY Department;
|
What is the number of female graduate students in each department?
|
CREATE TABLE GraduateStudents(StudentID INT,Name VARCHAR(50),Department VARCHAR(50),Gender VARCHAR(10)); INSERT INTO GraduateStudents(StudentID,Name,Department,Gender) VALUES (1,'Alice Johnson','Computer Science','Female'),(2,'Bob Brown','Physics','Male'),(3,'Charlie Davis','Mathematics','Female');
|
SELECT Department, COUNT(*) FROM GraduateStudents WHERE Gender = 'Female' GROUP BY Department
|
What is the maximum defense diplomacy event budget for each region in the 'defense_diplomacy' table?
|
CREATE TABLE defense_diplomacy (id INT,region VARCHAR(50),budget INT);
|
SELECT region, MAX(budget) FROM defense_diplomacy GROUP BY region;
|
What is the total number of likes on posts in a given time period?
|
CREATE TABLE posts (id INT,timestamp TIMESTAMP); INSERT INTO posts (id,timestamp) VALUES (1,'2022-01-01 10:00:00'),(2,'2022-01-02 12:00:00'),(3,'2022-01-03 14:00:00'); CREATE TABLE likes (post_id INT,likes INT); INSERT INTO likes (post_id,likes) VALUES (1,100),(2,200),(3,50);
|
SELECT SUM(likes) FROM posts JOIN likes ON posts.id = likes.post_id WHERE posts.timestamp BETWEEN '2022-01-01' AND '2022-01-05';
|
select max(Donation_Amount) as Highest_Donation from Donors where Country in ('India', 'Brazil')
|
CREATE TABLE Donors (Donor_ID int,Name varchar(50),Donation_Amount int,Country varchar(50)); INSERT INTO Donors (Donor_ID,Name,Donation_Amount,Country) VALUES (1,'John Doe',7000,'USA'),(2,'Jane Smith',3000,'Canada'),(3,'Mike Johnson',4000,'USA'),(4,'Emma Wilson',8000,'Canada'),(5,'Raj Patel',9000,'India'),(6,'Ana Sousa',10000,'Brazil');
|
SELECT MAX(Donation_Amount) AS Highest_Donation FROM Donors WHERE Country IN ('India', 'Brazil');
|
Who holds the record for most home runs in a single MLB season?
|
CREATE TABLE mlb_players (player_id INT,name VARCHAR(50),team VARCHAR(50),position VARCHAR(20),home_runs INT); INSERT INTO mlb_players (player_id,name,team,position,home_runs) VALUES (1,'Barry Bonds','San Francisco Giants','Left Field',73);
|
SELECT name FROM mlb_players WHERE home_runs = (SELECT MAX(home_runs) FROM mlb_players);
|
What is the average rating of hotels in each category?
|
CREATE TABLE hotels (hotel_id INT,name VARCHAR(50),category VARCHAR(20),rating DECIMAL(2,1)); INSERT INTO hotels (hotel_id,name,category,rating) VALUES (1,'The Urban Chic','boutique',4.5),(2,'The Artistic Boutique','boutique',4.7),(3,'The Cozy Inn','budget',4.2),(4,'The Grand Palace','luxury',4.8),(5,'The Majestic','luxury',4.6),(6,'The Beach Resort','resort',4.4);
|
SELECT category, AVG(rating) FROM hotels GROUP BY category;
|
What is the average amount donated by organizations in Asia in Q3 2022?
|
CREATE TABLE Donors (DonorID int,DonorType varchar(50),Country varchar(50),AmountDonated numeric(18,2),DonationDate date); INSERT INTO Donors (DonorID,DonorType,Country,AmountDonated,DonationDate) VALUES (1,'Organization','China',12000,'2022-07-01'),(2,'Individual','Japan',5000,'2022-08-01'),(3,'Organization','India',15000,'2022-09-01');
|
SELECT AVG(AmountDonated) FROM Donors WHERE DonorType = 'Organization' AND Country LIKE 'Asia%' AND QUARTER(DonationDate) = 3 AND YEAR(DonationDate) = 2022;
|
Calculate the moving average of the price of a digital asset with ID 2 over the last 7 days.
|
CREATE TABLE digital_asset_prices (id INT,digital_asset_id INT,price DECIMAL,price_date DATE); INSERT INTO digital_asset_prices (id,digital_asset_id,price,price_date) VALUES (1,1,100,'2022-01-01'),(2,1,105,'2022-01-02'),(3,1,110,'2022-01-03'),(4,1,115,'2022-01-04'),(5,1,120,'2022-01-05'),(6,2,50,'2022-01-01'),(7,2,52,'2022-01-02'),(8,2,54,'2022-01-03'),(9,2,56,'2022-01-04'),(10,2,58,'2022-01-05');
|
SELECT digital_asset_id, AVG(price) OVER (PARTITION BY digital_asset_id ORDER BY price_date ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) as moving_average FROM digital_asset_prices WHERE digital_asset_id = 2;
|
What is the average safety rating for cosmetics products from each country?
|
CREATE TABLE products (product_id INT,brand_id INT,product_name VARCHAR(50),safety_rating INT); INSERT INTO products (product_id,brand_id,product_name,safety_rating) VALUES (1,1,'Soap',5),(2,1,'Lotion',4),(3,2,'Shower Gel',5),(4,2,'Body Butter',5),(5,3,'Foundation',3),(6,4,'Lipstick',4),(7,4,'Mascara',4),(8,5,'Eyeshadow',5); CREATE TABLE brands (brand_id INT,brand_name VARCHAR(50),country VARCHAR(50),cruelty_free BOOLEAN); INSERT INTO brands (brand_id,brand_name,country,cruelty_free) VALUES (1,'Lush','United Kingdom',true),(2,'The Body Shop','United Kingdom',true),(3,'Bare Minerals','United States',true),(4,'MAC','Canada',false),(5,'Chanel','France',false);
|
SELECT b.country, AVG(p.safety_rating) as avg_safety_rating FROM products p JOIN brands b ON p.brand_id = b.brand_id GROUP BY b.country;
|
List all deep-sea species in the Pacific Ocean and their maximum depths.
|
CREATE TABLE deep_sea_species (name VARCHAR(255),habitat VARCHAR(255),max_depth FLOAT); INSERT INTO deep_sea_species (name,habitat,max_depth) VALUES ('Anglerfish','Pacific Ocean',3000),('Giant Squid','Pacific Ocean',3300);
|
SELECT name, max_depth FROM deep_sea_species WHERE habitat = 'Pacific Ocean';
|
How many confirmed cases of tuberculosis are there in each province of Canada?
|
CREATE TABLE Provinces (Province VARCHAR(50),TBCases INT); INSERT INTO Provinces (Province,TBCases) VALUES ('Ontario',500),('Quebec',700),('British Columbia',300),('Alberta',400);
|
SELECT Province, TBCases FROM Provinces;
|
What is the total budget allocated to parks and recreation in the city of Oakland for the year 2022?
|
CREATE TABLE city_budget (city VARCHAR(255),year INT,department VARCHAR(255),allocated_budget FLOAT); INSERT INTO city_budget (city,year,department,allocated_budget) VALUES ('Oakland',2022,'Parks and Recreation',2500000.00);
|
SELECT SUM(allocated_budget) AS total_budget FROM city_budget WHERE city = 'Oakland' AND year = 2022 AND department = 'Parks and Recreation';
|
What is the trend of professional development course completions by teachers over time by gender?
|
CREATE TABLE teacher_trainings (training_id INT,teacher_id INT,training_date DATE,course_completed INT); INSERT INTO teacher_trainings (training_id,teacher_id,training_date,course_completed) VALUES (1,1,'2022-01-01',1),(2,1,'2022-02-01',2),(3,2,'2022-01-01',3),(4,2,'2022-02-01',1); CREATE TABLE teachers (teacher_id INT,teacher_name VARCHAR(50),gender VARCHAR(10)); INSERT INTO teachers (teacher_id,teacher_name,gender) VALUES (1,'Ms. Lopez','Female'),(2,'Mr. Johnson','Male');
|
SELECT gender, EXTRACT(MONTH FROM training_date) AS month, SUM(course_completed) FROM teacher_trainings JOIN teachers ON teacher_trainings.teacher_id = teachers.teacher_id GROUP BY gender, month;
|
How many clinical trials were conducted for each drug in 2019?
|
CREATE TABLE clinical_trials (drug varchar(255),year int,trials int); INSERT INTO clinical_trials (drug,year,trials) VALUES ('DrugA',2019,2),('DrugB',2019,3);
|
SELECT drug, AVG(trials) FROM clinical_trials WHERE year = 2019 GROUP BY drug;
|
What is the maximum salary of non-union workers in the finance industry?
|
CREATE TABLE finance (id INT,union_member BOOLEAN,salary FLOAT); INSERT INTO finance (id,union_member,salary) VALUES (1,FALSE,90000),(2,TRUE,100000),(3,FALSE,95000);
|
SELECT MAX(salary) FROM finance WHERE union_member = FALSE;
|
Which media outlets published the most articles about 'climate_change' in the 'media_publications' table?
|
CREATE TABLE media_publications (id INT,media_outlet VARCHAR(255),title VARCHAR(255),published_date DATE,topic VARCHAR(255));
|
SELECT media_outlet, COUNT(*) as articles_about_climate_change FROM media_publications WHERE topic = 'climate_change' GROUP BY media_outlet ORDER BY articles_about_climate_change DESC;
|
What is the total cost of all projects in 'Water_Infrastructure' table?
|
CREATE TABLE Water_Infrastructure (id INT,project_name VARCHAR(50),location VARCHAR(50),cost INT);
|
SELECT SUM(cost) FROM Water_Infrastructure;
|
What is the average media literacy score for users in South America who watched more than 5 hours of video content in the last week?
|
CREATE TABLE user_video_views (user_id INT,user_name TEXT,country TEXT,watch_time INT,media_literacy_score INT); INSERT INTO user_video_views (user_id,user_name,country,watch_time,media_literacy_score) VALUES (1,'User 1','Brazil',8,6); INSERT INTO user_video_views (user_id,user_name,country,watch_time,media_literacy_score) VALUES (2,'User 2','Argentina',6,7);
|
SELECT AVG(media_literacy_score) FROM user_video_views WHERE country = 'South America' AND watch_time > 5 AND watch_time <= 5 + 1 AND watch_time >= 5 - 1;
|
What is the preservation status of heritage sites established before 1900 in Europe?
|
CREATE TABLE HeritageSites (Site VARCHAR(50),YearEstablished INT,PreservationStatus VARCHAR(50)); INSERT INTO HeritageSites (Site,YearEstablished,PreservationStatus) VALUES ('Site1',1890,'Preserved'),('Site2',1920,'Under Threat');
|
SELECT PreservationStatus FROM HeritageSites WHERE YearEstablished < 1900 AND Region = 'Europe';
|
What is the average salary of employees who have changed jobs more than twice?
|
CREATE TABLE EmployeeSalary (EmployeeID INT,Salary DECIMAL(10,2),JobChanges INT); INSERT INTO EmployeeSalary (EmployeeID,Salary,JobChanges) VALUES (1,70000.00,3); INSERT INTO EmployeeSalary (EmployeeID,Salary,JobChanges) VALUES (2,75000.00,1);
|
SELECT AVG(Salary) FROM EmployeeSalary WHERE JobChanges > 2;
|
What is the average market price of Neodymium produced in Australia for the last 5 years?
|
CREATE TABLE Neodymium_Production (year INT,country TEXT,price FLOAT); INSERT INTO Neodymium_Production (year,country,price) VALUES (2017,'Australia',120); INSERT INTO Neodymium_Production (year,country,price) VALUES (2018,'Australia',110); INSERT INTO Neodymium_Production (year,country,price) VALUES (2019,'Australia',130); INSERT INTO Neodymium_Production (year,country,price) VALUES (2020,'Australia',150); INSERT INTO Neodymium_Production (year,country,price) VALUES (2021,'Australia',170);
|
SELECT AVG(price) FROM Neodymium_Production WHERE country = 'Australia' AND year BETWEEN 2017 AND 2021;
|
What is the most expensive item on the menu for each restaurant?
|
CREATE TABLE MenuItems (id INT,restaurant_id INT,name VARCHAR,price DECIMAL); INSERT INTO MenuItems (id,restaurant_id,name,price) VALUES (1,1,'Quiche',12.99); INSERT INTO MenuItems (id,restaurant_id,name,price) VALUES (2,2,'Pizza',14.99); INSERT INTO MenuItems (id,restaurant_id,name,price) VALUES (3,1,'Steak',29.99);
|
SELECT m.name, m.price, r.name FROM MenuItems m JOIN Restaurants r ON m.restaurant_id = r.id WHERE m.price = (SELECT MAX(price) FROM MenuItems WHERE restaurant_id = m.restaurant_id);
|
Update the email of a donor with ID 10 in the "donors" table.
|
CREATE TABLE donors (id INT,name VARCHAR(50),last_donation_year INT,email VARCHAR(50));
|
UPDATE donors SET email = '[email protected]' WHERE id = 10;
|
What is the total donation amount by donors located in Southeast Asia in 2022, broken down by donor type?
|
CREATE TABLE Donors (DonorID int,DonorType varchar(50),Country varchar(50),AmountDonated numeric(18,2),DonationDate date); INSERT INTO Donors (DonorID,DonorType,Country,AmountDonated,DonationDate) VALUES (1,'Organization','Indonesia',12000,'2022-01-01'),(2,'Individual','Malaysia',5000,'2022-02-01'),(3,'Organization','Philippines',15000,'2022-03-01'),(4,'Individual','Thailand',8000,'2022-04-01');
|
SELECT DonorType, SUM(AmountDonated) as TotalDonated FROM Donors WHERE Country LIKE 'Southeast Asia%' AND YEAR(DonationDate) = 2022 GROUP BY DonorType;
|
How many vessels visited port 'Los Angeles' in the last week?
|
CREATE TABLE port_visits (id INT,port VARCHAR(50),visit_date DATE); INSERT INTO port_visits (id,port,visit_date) VALUES (1,'Los Angeles','2022-04-10'),(2,'Los Angeles','2022-04-14');
|
SELECT COUNT(DISTINCT id) FROM port_visits WHERE port = 'Los Angeles' AND visit_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY) AND CURRENT_DATE;
|
What is the total cost of all agricultural innovation projects in the Philippines?
|
CREATE TABLE agricultural_projects (id INT,country VARCHAR(20),project_name VARCHAR(50),project_cost FLOAT); INSERT INTO agricultural_projects (id,country,project_name,project_cost) VALUES (1,'Philippines','Irrigation System Upgrade',50000.00),(2,'Indonesia','Precision Farming',75000.00);
|
SELECT SUM(project_cost) FROM agricultural_projects WHERE country = 'Philippines';
|
Calculate the total quantity of recycled materials used in industry 4.0 processes for each factory in Q2 2021.
|
CREATE TABLE industry_4_0 (id INT,factory_id INT,material VARCHAR(50),quantity INT,date DATE); INSERT INTO industry_4_0 (id,factory_id,material,quantity,date) VALUES (1,1,'Plastic',100,'2021-04-01'),(2,2,'Glass',200,'2021-05-01'),(3,1,'Metal',150,'2021-06-01');
|
SELECT factory_id, SUM(quantity) as total_quantity FROM industry_4_0 WHERE DATE_FORMAT(date, '%Y-%m') BETWEEN '2021-04-01' AND '2021-06-30' GROUP BY factory_id;
|
What is the maximum daily water usage for residential customers in New York City in 2020?
|
CREATE TABLE water_usage(customer_type VARCHAR(50),city VARCHAR(50),year INT,day DATE,usage FLOAT); INSERT INTO water_usage(customer_type,city,year,day,usage) VALUES ('Residential','New York City',2020,'2020-07-04',12345.6),('Residential','New York City',2020,'2020-07-05',15000);
|
SELECT day, MAX(usage) FROM water_usage WHERE customer_type = 'Residential' AND city = 'New York City' AND year = 2020;
|
Find the number of professional development courses taken by teachers in the past year from the 'teacher_trainings' table.
|
CREATE TABLE teacher_trainings (teacher_id INT,course_id INT,training_date DATE);
|
SELECT COUNT(*) FROM teacher_trainings WHERE training_date >= DATE(NOW()) - INTERVAL 1 YEAR;
|
What is the average production cost for chemical C?
|
CREATE TABLE costs (id INT,product VARCHAR(255),cost FLOAT); INSERT INTO costs (id,product,cost) VALUES (1,'Chemical A',200.3),(2,'Chemical B',150.9),(3,'Chemical C',250.7); CREATE VIEW avg_cost AS SELECT product,AVG(cost) as avg_cost FROM costs GROUP BY product;
|
SELECT avg_cost FROM avg_cost WHERE product = 'Chemical C'
|
What is the total number of eco-tourists who visited Southeast Asian countries in 2022?
|
CREATE TABLE eco_tourism (country VARCHAR(20),tourists INT,year INT); INSERT INTO eco_tourism (country,tourists,year) VALUES ('Indonesia',500000,2022),('Thailand',600000,2022),('Vietnam',400000,2022);
|
SELECT SUM(tourists) as total_eco_tourists FROM eco_tourism WHERE country IN ('Indonesia', 'Thailand', 'Vietnam') AND year = 2022;
|
What is the total number of medals won by each country in the Commonwealth Games?
|
CREATE TABLE countries (country_id INT,country_name VARCHAR(100)); CREATE TABLE medals (medal_id INT,country_id INT,medal_type VARCHAR(10),game_name VARCHAR(100));
|
SELECT countries.country_name, COUNT(medals.medal_id) as total_medals FROM countries INNER JOIN medals ON countries.country_id = medals.country_id WHERE medals.game_name = 'Commonwealth Games' GROUP BY countries.country_name;
|
Update the 'description' for a record in the 'student_clubs' table
|
CREATE TABLE student_clubs (club_id INT PRIMARY KEY,name VARCHAR(50),description TEXT,advisor VARCHAR(50));
|
UPDATE student_clubs SET description = 'A club for students interested in social justice.' WHERE name = 'Social Justice Warriors';
|
What are the total CO2 emissions for each forest?
|
CREATE TABLE Forests (id INT PRIMARY KEY,name VARCHAR(255),hectares DECIMAL(5,2),country VARCHAR(255)); INSERT INTO Forests (id,name,hectares,country) VALUES (1,'Greenwood',520.00,'Canada'); CREATE TABLE Co2Emissions (id INT PRIMARY KEY,forest_id INT,year INT,value DECIMAL(5,2),FOREIGN KEY (forest_id) REFERENCES Forests(id)); INSERT INTO Co2Emissions (id,forest_id,year,value) VALUES (1,1,2010,120.50);
|
SELECT Forests.name, SUM(Co2Emissions.value) as total_co2_emissions FROM Forests INNER JOIN Co2Emissions ON Forests.id = Co2Emissions.forest_id GROUP BY Forests.name;
|
What is the total profit for each product line in the 'finance' schema?
|
CREATE TABLE finance.profit (product_line VARCHAR(50),month INT,year INT,profit DECIMAL(10,2)); INSERT INTO finance.profit (product_line,month,year,profit) VALUES ('Product Line A',1,2022,2000.00),('Product Line A',2,2022,4000.00),('Product Line B',1,2022,3000.00),('Product Line B',2,2022,5000.00);
|
SELECT product_line, SUM(profit) as total_profit FROM finance.profit GROUP BY product_line;
|
What is the average area (in hectares) of farmland per farmer in the 'conventional_farms' table?
|
CREATE TABLE conventional_farms (farmer_id INT,farm_name VARCHAR(50),location VARCHAR(50),area_ha FLOAT); INSERT INTO conventional_farms (farmer_id,farm_name,location,area_ha) VALUES (1,'Farm 2','Location 2',12.3),(2,'Farm 3','Location 3',18.5),(3,'Farm 4','Location 4',21.7);
|
SELECT AVG(area_ha) FROM conventional_farms;
|
How many hospitals are there in the rural southeast region with a patient satisfaction score greater than 85?
|
CREATE TABLE hospitals (name TEXT,region TEXT,patient_satisfaction_score INT); INSERT INTO hospitals (name,region,patient_satisfaction_score) VALUES ('Hospital A','Rural Southeast',88),('Hospital B','Rural Southeast',75),('Hospital C','Rural Northeast',90);
|
SELECT COUNT(*) FROM hospitals WHERE region = 'Rural Southeast' AND patient_satisfaction_score > 85;
|
Add new researchers to the arctic_researchers table
|
CREATE SCHEMA IF NOT EXISTS arctic_db; CREATE TABLE IF NOT EXISTS arctic_researchers (id INT PRIMARY KEY,researcher_name TEXT,expertise TEXT);
|
INSERT INTO arctic_researchers (id, researcher_name, expertise) VALUES (1, 'Alice Johnson', 'climate change'), (2, 'Bob Smith', 'biodiversity');
|
What is the total amount donated to each organization in the Southeast region?
|
CREATE TABLE donations (id INT,org_id INT,donation DECIMAL(10,2)); CREATE TABLE organizations (id INT,name TEXT,region TEXT); INSERT INTO donations (id,org_id,donation) VALUES (1,1,50.00),(2,1,75.00),(3,2,100.00),(4,2,125.00),(5,3,25.00),(6,3,50.00); INSERT INTO organizations (id,name,region) VALUES (1,'Habitat for Humanity','Southeast'),(2,'Red Cross','Southeast'),(3,'UNICEF','Northeast');
|
SELECT o.name, SUM(d.donation) AS total_donations FROM donations d JOIN organizations o ON d.org_id = o.id WHERE o.region = 'Southeast' GROUP BY o.name;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.