instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the maximum number of creative AI applications developed in a single country?
CREATE TABLE ai_applications (app_id INT,name TEXT,country TEXT,category TEXT); INSERT INTO ai_applications (app_id,name,country,category) VALUES (1,'ArtBot','Nigeria','Creative'),(2,'MusicGen','South Africa','Creative'),(3,'DataViz','US','Analytical'),(4,'ChatAssist','Canada','Assistive'),(5,'AIArt','Japan','Creative'),(6,'AIWriter','Germany','Creative');
SELECT MAX(count_per_country) FROM (SELECT COUNT(*) AS count_per_country FROM ai_applications GROUP BY country);
Find the number of public parks in cities with a population over 1 million.
CREATE TABLE City (Name VARCHAR(20),Population INT); CREATE TABLE Park (City VARCHAR(20),Type VARCHAR(10)); INSERT INTO City (Name,Population) VALUES ('CityA',1500000),('CityB',800000),('CityC',1200000); INSERT INTO Park (City,Type) VALUES ('CityA','Public'),('CityA','Private'),('CityB','Public'),('CityC','Public');
SELECT COUNT(*) FROM City INNER JOIN Park ON City.Name = Park.City WHERE Population > 1000000 AND Type = 'Public';
How many marine protected areas are there in each country?
CREATE TABLE countries (id INT,name TEXT); CREATE TABLE marine_protected_areas (id INT,country_id INT,name TEXT); INSERT INTO countries VALUES (1,'Peru'),(2,'Chile'),(3,'Ecuador'); INSERT INTO marine_protected_areas VALUES (1,1,'Galapagos Islands'),(2,2,'Easter Island'),(3,3,'Cocos Island');
SELECT c.name, COUNT(mpa.id) as num_marine_protected_areas FROM countries c INNER JOIN marine_protected_areas mpa ON c.id = mpa.country_id GROUP BY c.name;
What is the average number of safety violations per year for non-union companies in the 'Transportation' industry?
CREATE TABLE SafetyViolations (id INT,CompanyType TEXT,Industry TEXT,Year INT,Violations INT);
SELECT AVG(Violations) FROM SafetyViolations WHERE CompanyType != 'Union' AND Industry = 'Transportation' GROUP BY Industry, Year;
What is the maximum revenue generated by eco-friendly hotels in India?
CREATE TABLE eco_hotels (hotel_id INT,hotel_name TEXT,country TEXT,revenue FLOAT); INSERT INTO eco_hotels (hotel_id,hotel_name,country,revenue) VALUES (1,'Green Hotel','India',8000),(2,'Eco Lodge','India',9000);
SELECT MAX(revenue) FROM eco_hotels WHERE country = 'India';
What are the names and descriptions of all vulnerabilities with a medium severity rating?
CREATE TABLE vulnerabilities (id INT,name VARCHAR(255),description TEXT,severity INT); INSERT INTO vulnerabilities (id,name,description,severity) VALUES (1,'Heartbleed','...',8),(3,'SQL Injection','...',6);
SELECT name, description FROM vulnerabilities WHERE severity = 6;
What is the average weight of satellites launched by the US?
CREATE TABLE Satellites (SatelliteID INT,Name VARCHAR(50),Country VARCHAR(50),LaunchDate DATE,Weight DECIMAL(10,2),Status VARCHAR(50)); INSERT INTO Satellites (SatelliteID,Name,Country,LaunchDate,Weight,Status) VALUES (1,'Sentinel-1A','France','2012-04-03',2315.00,'Active'),(2,'Sentinel-1B','Germany','2016-04-25',2315.00,'Active'),(3,'Sentinel-2A','Italy','2015-06-23',1180.00,'Active'),(4,'Sentinel-2B','Spain','2017-03-07',1180.00,'Active'),(5,'USA-1','USA','2006-01-14',2600.00,'Inactive'),(6,'USA-2','USA','2007-03-14',3000.00,'Active');
SELECT AVG(Weight) FROM Satellites WHERE Country = 'USA';
How many intelligence operations were conducted by each agency in the last 2 years?
CREATE TABLE intelligence_agency (id INT,name VARCHAR(255)); INSERT INTO intelligence_agency (id,name) VALUES (1,'CIA'),(2,'FBI'),(3,'NSA'),(4,'MI6'),(5,'ASIO'); CREATE TABLE intelligence_operations (id INT,agency_id INT,year INT,operation VARCHAR(255)); INSERT INTO intelligence_operations (id,agency_id,year,operation) VALUES (1,1,2020,'Operation Red Sparrow'),(2,1,2021,'Operation Blue Harvest'),(3,2,2020,'Operation Silver Shield'),(4,2,2021,'Operation Golden Eagle'),(5,3,2020,'Operation Black Swan'),(6,3,2021,'Operation White Hawk'),(7,4,2020,'Operation Scarlet Widow'),(8,4,2021,'Operation Crimson Tide'),(9,5,2020,'Operation Phoenix'),(10,5,2021,'Operation Griffin');
SELECT i.name, COUNT(io.id) as operation_count FROM intelligence_agency i INNER JOIN intelligence_operations io ON i.id = io.agency_id WHERE io.year BETWEEN 2020 AND 2021 GROUP BY i.name;
Which communities have the highest engagement levels in language preservation in South Asia?
CREATE TABLE Communities (community_id INT PRIMARY KEY,community_name VARCHAR(255),region VARCHAR(255),engagement_level INT); INSERT INTO Communities (community_id,community_name,region,engagement_level) VALUES (2,'Siddi','South Asia',5);
SELECT c.community_name, c.region, l.language, l.script, l.speakers, c.engagement_level FROM Communities c INNER JOIN Languages l ON c.region = l.region WHERE c.engagement_level = (SELECT MAX(engagement_level) FROM Communities WHERE region = 'South Asia');
How many users have interacted with any post on Pinterest in the last month?
CREATE TABLE interaction_data (user_id INT,post_id INT,platform VARCHAR(20),date DATE); INSERT INTO interaction_data (user_id,post_id,platform,date) VALUES (1,1,'Pinterest','2022-01-01'),(2,2,'Pinterest','2022-01-02'),(3,1,'Pinterest','2022-01-03');
SELECT COUNT(DISTINCT user_id) FROM interaction_data WHERE platform = 'Pinterest' AND date >= DATEADD(month, -1, GETDATE());
What was the total revenue for each product category in New York in the first half of 2021?
CREATE TABLE sales (id INT,category VARCHAR(50),revenue DECIMAL(10,2),month INT,year INT);
SELECT category, SUM(revenue) FROM sales WHERE state = 'New York' AND (month = 1 OR month = 2 OR month = 3 OR month = 4 OR month = 5 OR month = 6) AND year = 2021 GROUP BY category;
Who is the most prolific female journalist in "The New York Times" in 2019?
CREATE TABLE journalists (id INT,name TEXT,gender TEXT,newspaper TEXT); CREATE TABLE articles (id INT,journalist_id INT,title TEXT,content TEXT,publication_date DATE);
SELECT j.name FROM journalists j INNER JOIN articles a ON j.id = a.journalist_id WHERE j.gender = 'Female' AND j.newspaper = 'The New York Times' GROUP BY j.id ORDER BY COUNT(a.id) DESC LIMIT 1;
What are the top 3 countries with the most flight accidents in the 'flight_safety_records' table?
CREATE TABLE flight_safety_records (country VARCHAR(50),accidents INT);
SELECT country, accidents FROM flight_safety_records ORDER BY accidents DESC LIMIT 3;
Find the number of wells drilled in each country, sorted by the most drilled.
CREATE TABLE wells (well_id INT,country VARCHAR(50)); INSERT INTO wells (well_id,country) VALUES (1,'USA'),(2,'Canada'),(3,'Mexico');
SELECT country, COUNT(*) as num_wells FROM wells GROUP BY country ORDER BY num_wells DESC;
Find the top 10 donors who have donated the most to the Education sector?
CREATE TABLE Donors (DonorID INT,DonorName TEXT,TotalDonation DECIMAL); CREATE TABLE Donations (DonationID INT,DonorID INT,DonationAmount DECIMAL,Sector TEXT);
SELECT DonorName, SUM(DonationAmount) OVER (PARTITION BY DonorID ORDER BY SUM(DonationAmount) DESC) AS TotalDonation FROM Donors JOIN Donations ON Donors.DonorID = Donations.DonorID WHERE Sector = 'Education' GROUP BY DonorID ORDER BY TotalDonation DESC LIMIT 10;
List the maritime law compliance records for vessels in the Arctic Ocean.
CREATE TABLE maritime_law_compliance (compliance_id INT,vessel_name TEXT,compliance_status TEXT,region TEXT); INSERT INTO maritime_law_compliance (compliance_id,vessel_name,compliance_status,region) VALUES (1,'Vessel A','Compliant','Arctic Ocean'),(2,'Vessel B','Non-Compliant','Antarctic Ocean'),(3,'Vessel C','Compliant','Arctic Ocean');
SELECT * FROM maritime_law_compliance WHERE region = 'Arctic Ocean';
What is the maximum number of workers involved in a construction project in New York city in 2020?
CREATE TABLE Worker_Count (ProjectID INT,City VARCHAR(50),Year INT,WorkerCount INT);
SELECT MAX(WorkerCount) FROM Worker_Count WHERE City = 'New York' AND Year = 2020;
What is the minimum donation amount in the 'Donations' table?
CREATE TABLE Donations (id INT,department VARCHAR(20),amount FLOAT); INSERT INTO Donations (id,department,amount) VALUES (1,'Animals',500.00),(2,'Education',300.00);
SELECT MIN(amount) FROM Donations
What is the minimum time taken to resolve restorative justice programs in Oregon?
CREATE TABLE restorative_justice_programs (program_id INT,state VARCHAR(2),duration INT); INSERT INTO restorative_justice_programs (program_id,state,duration) VALUES (1,'OR',25),(2,'OR',50);
SELECT MIN(duration) FROM restorative_justice_programs WHERE state = 'OR';
Show the number of mobile plans that were created each month of the last year?
CREATE TABLE mobile_plans (id INT,name VARCHAR(255),price DECIMAL(10,2),created_at TIMESTAMP);
SELECT DATE_FORMAT(created_at, '%Y-%m') as month, COUNT(*) as total_plans FROM mobile_plans WHERE created_at >= DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 YEAR) GROUP BY month;
What is the average severity of vulnerabilities found in the last month for each product in the APAC region?
CREATE TABLE vulnerabilities (id INT,timestamp TIMESTAMP,product VARCHAR(255),region VARCHAR(255),vulnerability_severity VARCHAR(255)); INSERT INTO vulnerabilities (id,timestamp,product,region,vulnerability_severity) VALUES (1,'2022-01-01 12:00:00','Product A','APAC','High'),(2,'2022-01-02 10:30:00','Product B','EMEA','Medium');
SELECT product, region, AVG(case when vulnerability_severity = 'High' then 3 when vulnerability_severity = 'Medium' then 2 when vulnerability_severity = 'Low' then 1 else 0 end) as avg_severity FROM vulnerabilities WHERE timestamp >= NOW() - INTERVAL 1 MONTH AND region = 'APAC' GROUP BY product, region;
Update the language_status of endangered languages in the Languages table based on the data in the LanguageStatus table.
CREATE TABLE Languages (language_id INT,language_name VARCHAR(20),language_family VARCHAR(20),language_status VARCHAR(10)); CREATE TABLE LanguageStatus (language_id INT,status_name VARCHAR(20),status_date DATE);
UPDATE Languages l SET l.language_status = (SELECT status_name FROM LanguageStatus WHERE l.language_id = LanguageStatus.language_id AND status_date = (SELECT MAX(status_date) FROM LanguageStatus WHERE language_id = LanguageStatus.language_id)) WHERE EXISTS (SELECT 1 FROM LanguageStatus WHERE Languages.language_id = LanguageStatus.language_id);
What is the maximum water consumption in California for the years 2017 and 2018?
CREATE TABLE water_consumption (id INT,state VARCHAR(20),year INT,consumption FLOAT); INSERT INTO water_consumption (id,state,year,consumption) VALUES (1,'California',2017,120.5),(2,'California',2018,130.3),(3,'California',2019,140.0),(4,'New York',2017,115.3),(5,'New York',2018,120.0),(6,'New York',2019,125.5);
SELECT MAX(consumption) FROM water_consumption WHERE state = 'California' AND year IN (2017, 2018);
What is the total quantity of sustainable fabrics sourced from Africa?
CREATE TABLE TextileSourcing (id INT,location VARCHAR(50),fabric_type VARCHAR(50),quantity INT); INSERT INTO TextileSourcing (id,location,fabric_type,quantity) VALUES (1,'Egypt','Organic Cotton',700),(2,'Morocco','Tencel',450),(3,'South Africa','Recycled Polyester',600);
SELECT SUM(quantity) FROM TextileSourcing WHERE location IN ('Egypt', 'Morocco', 'South Africa') AND fabric_type IN ('Organic Cotton', 'Tencel', 'Recycled Polyester');
What's the total watch time of videos in the 'Entertainment' category?
CREATE TABLE videos (id INT,title TEXT,category TEXT,watch_time INT); INSERT INTO videos (id,title,category,watch_time) VALUES (1,'Video1','Entertainment',120),(2,'Video2','Sports',90);
SELECT SUM(watch_time) FROM videos WHERE category = 'Entertainment';
What is the percentage of teachers who have completed at least one professional development course in the last year?
CREATE TABLE teacher_pd (teacher_id INT,course_id INT,completion_date DATE); INSERT INTO teacher_pd (teacher_id,course_id,completion_date) VALUES (1,1001,'2021-01-01'),(1,1002,'2020-06-01'),(2,1001,'2019-12-31'),(3,1003,'2021-03-15'),(3,1004,'2019-09-01');
SELECT 100.0 * SUM(CASE WHEN completion_date >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR) THEN 1 ELSE 0 END) / COUNT(DISTINCT teacher_id) FROM teacher_pd;
What is the total budget for each department in Q1 of 2021?
CREATE TABLE Departments (DepartmentID INT,DepartmentName VARCHAR(255)); CREATE TABLE Budget (BudgetID INT,DepartmentID INT,Amount DECIMAL(10,2),BudgetDate DATE);
SELECT Departments.DepartmentID, Departments.DepartmentName, SUM(Budget.Amount) as TotalBudget FROM Budget INNER JOIN Departments ON Budget.DepartmentID = Departments.DepartmentID WHERE QUARTER(Budget.BudgetDate) = 1 AND YEAR(Budget.BudgetDate) = 2021 GROUP BY Departments.DepartmentID, Departments.DepartmentName;
Identify safety incidents involving chemical D in the past year.
CREATE TABLE safety_incidents (chemical VARCHAR(20),incident_date DATE); INSERT INTO safety_incidents VALUES ('chemical D','2022-01-15'); INSERT INTO safety_incidents VALUES ('chemical E','2022-02-01');
SELECT * FROM safety_incidents WHERE chemical = 'chemical D' AND incident_date BETWEEN DATEADD(year, -1, GETDATE()) AND GETDATE();
List the customers who made a transaction on the 1st of any month in the year 2022, including their names, account numbers, and transaction types?
CREATE TABLE customers (customer_id INT,customer_name VARCHAR(50),account_number VARCHAR(20),primary_contact VARCHAR(50)); CREATE TABLE transactions (transaction_id INT,customer_id INT,transaction_type VARCHAR(20),transaction_amount DECIMAL(10,2),transaction_date DATE);
SELECT c.customer_name, c.account_number, t.transaction_type FROM customers c JOIN transactions t ON c.customer_id = t.customer_id WHERE DAY(transaction_date) = 1 AND YEAR(transaction_date) = 2022;
How many community development projects were completed in Asia by each organization?
CREATE TABLE community_development (project_id INT,org_name VARCHAR(50),country VARCHAR(50),project_status VARCHAR(20)); INSERT INTO community_development (project_id,org_name,country,project_status) VALUES (1,'World Vision','China','completed'),(2,'Save the Children','India','in progress');
SELECT org_name, COUNT(*) FROM community_development WHERE country LIKE 'Asia%' AND project_status = 'completed' GROUP BY org_name;
What is the maximum budget for any AI application in the field of explainable AI?
CREATE TABLE ExplainableAIs (id INT,name VARCHAR(255),budget DECIMAL(10,2));
SELECT MAX(budget) FROM ExplainableAIs;
List all the organizations in 'org_details' table located in 'Los Angeles'?
CREATE TABLE org_details (org_name VARCHAR(50),location VARCHAR(50)); INSERT INTO org_details (org_name,location) VALUES ('LMN Foundation','Los Angeles');
SELECT org_name FROM org_details WHERE location = 'Los Angeles';
Which programs had the most attendees for each type of program, excluding any programs with less than 10 attendees?
CREATE TABLE Programs (program VARCHAR(50),attendees INT); INSERT INTO Programs (program,attendees) VALUES ('Art',120),('Music',15),('Dance',180),('Art',5),('Music',150),('Dance',20);
SELECT program, MAX(attendees) FROM Programs WHERE attendees >= 10 GROUP BY program;
Which regions have a higher revenue than the average revenue?
CREATE TABLE sales_3 (sale_id INT,region VARCHAR(20),revenue DECIMAL(10,2)); INSERT INTO sales_3 (sale_id,region,revenue) VALUES (1,'North',5000.00),(2,'South',3000.00),(3,'East',7000.00);
SELECT region FROM sales_3 WHERE revenue > (SELECT AVG(revenue) FROM sales_3);
What is the minimum production cost for items made of linen?
CREATE TABLE products (id INT,name TEXT,material TEXT,production_cost FLOAT); INSERT INTO products (id,name,material,production_cost) VALUES (1,'Dress','Linen',40.0),(2,'Skirt','Linen',30.0);
SELECT MIN(production_cost) FROM products WHERE material = 'Linen';
What is the total amount of foreign aid received by indigenous communities in rural Mexico for community development projects in the last 3 years?
CREATE TABLE aid (aid_id INT,country TEXT,community TEXT,year INT,amount FLOAT); INSERT INTO aid (aid_id,country,community,year,amount) VALUES (1,'Mexico','Mayan',2019,150000),(2,'Mexico','Zapotec',2020,200000),(3,'Mexico','Mixtec',2021,180000);
SELECT SUM(amount) as total_aid FROM aid WHERE country = 'Mexico' AND community IS NOT NULL AND year BETWEEN (SELECT EXTRACT(YEAR FROM CURRENT_DATE) - 3) AND (SELECT EXTRACT(YEAR FROM CURRENT_DATE));
Provide the number of cybersecurity incidents reported in 2020 and 2021.
CREATE TABLE CybersecurityIncidents(id INT PRIMARY KEY,year INT,incidents INT);INSERT INTO CybersecurityIncidents(id,year,incidents) VALUES (1,2020,150),(2,2021,200);
SELECT year, incidents FROM CybersecurityIncidents WHERE year IN (2020, 2021);
How many intelligence operations were conducted by country X in the years 2019 and 2020?
CREATE TABLE intelligence_operations (id INT,country TEXT,operation TEXT,year INT);INSERT INTO intelligence_operations (id,country,operation,year) VALUES (1,'Country X','Operation Red Fox',2019),(2,'Country X','Operation Black Hawk',2020);
SELECT country, COUNT(*) as total_operations FROM intelligence_operations WHERE country = 'Country X' AND year IN (2019, 2020) GROUP BY country;
How many digital assets were issued in 2021, by companies based in Canada?
CREATE TABLE digital_assets (id INT,issue_date DATE,company TEXT,country TEXT); INSERT INTO digital_assets (id,issue_date,company,country) VALUES (1,'2021-01-01','ExampleCompany1','Canada');
SELECT COUNT(*) FROM digital_assets WHERE YEAR(issue_date) = 2021 AND country = 'Canada';
What is the total wastewater treatment capacity for each province in Canada in 2017?'
CREATE TABLE wastewater_treatment (province VARCHAR(255),location VARCHAR(255),capacity INT); INSERT INTO wastewater_treatment (province,location,capacity) VALUES ('Ontario','Toronto',5000000);
SELECT province, SUM(capacity) FROM wastewater_treatment WHERE province IN ('Alberta', 'British Columbia', 'Manitoba', 'New Brunswick', 'Newfoundland and Labrador', 'Northwest Territories', 'Nova Scotia', 'Nunavut', 'Ontario', 'Prince Edward Island', ' Quebec', 'Saskatchewan') GROUP BY province;
What is the most expensive artwork created by a 'Female European' artist?
CREATE TABLE Artists (id INT,artist_name VARCHAR(255),gender VARCHAR(10),ethnicity VARCHAR(255)); CREATE TABLE Artworks (id INT,artist_id INT,artwork_name VARCHAR(255),year_created INT,price FLOAT); INSERT INTO Artists (id,artist_name,gender,ethnicity) VALUES (1,'Frida Kahlo','Female','European'); INSERT INTO Artworks (id,artist_id,artwork_name,year_created,price) VALUES (1,1,'Roots',1943,8000000); INSERT INTO Artworks (id,artist_id,artwork_name,year_created,price) VALUES (2,1,'The Wounded Table',1940,5000000); INSERT INTO Artists (id,artist_name,gender,ethnicity) VALUES (2,'Marina Abramović','Female','European'); INSERT INTO Artworks (id,artist_id,artwork_name,year_created,price) VALUES (3,2,'The Artist is Present',2010,1000000);
SELECT A.artist_name, B.artwork_name, B.price FROM Artists A INNER JOIN Artworks B ON A.id = B.artist_id WHERE A.gender = 'Female' AND A.ethnicity = 'European' ORDER BY B.price DESC LIMIT 1;
Identify the drugs that were approved by the FDA in 2018 and also had sales greater than $1 billion in the same year.
CREATE TABLE drug_approval (drug_name VARCHAR(50),approval_year INT); CREATE TABLE drug_sales (drug_name VARCHAR(50),sales FLOAT,year INT); INSERT INTO drug_approval (drug_name,approval_year) VALUES ('DrugA',2018),('DrugB',2018),('DrugC',2018),('DrugD',2017); INSERT INTO drug_sales (drug_name,sales,year) VALUES ('DrugA',1200,2018),('DrugB',1500,2018),('DrugC',800,2018),('DrugD',1800,2018),('DrugA',1100,2017),('DrugB',1400,2017),('DrugC',700,2017),('DrugD',1700,2017);
SELECT a.drug_name FROM drug_approval a INNER JOIN drug_sales b ON a.drug_name = b.drug_name WHERE a.approval_year = 2018 AND b.sales > 1000 AND b.year = 2018;
Find the number of GMO-free cereals produced in the USA in 2019.
CREATE TABLE GMOFreeCereals (id INT,country VARCHAR(50),year INT,quantity INT); INSERT INTO GMOFreeCereals (id,country,year,quantity) VALUES (1,'USA',2018,300),(2,'USA',2019,400),(3,'Canada',2018,250),(4,'Canada',2019,275);
SELECT COUNT(*) FROM GMOFreeCereals WHERE country = 'USA' AND year = 2019;
List the cultural competency training topics for Community Health Workers and their respective completion dates.
CREATE TABLE Community_Health_Workers (Worker_ID INT,Name VARCHAR(255),Training_Topic VARCHAR(255),Completion_Date DATE); INSERT INTO Community_Health_Workers (Worker_ID,Name,Training_Topic,Completion_Date) VALUES (1,'Jamila','Cultural Competency 101','2022-06-01'),(2,'Luis','Cultural Competency 101','2022-05-15');
SELECT Training_Topic, Completion_Date FROM Community_Health_Workers WHERE Training_Topic LIKE '%Cultural Competency%';
What were the average socially responsible loan amounts issued by microfinance institutions in South Asia, grouped by institution and year, for loans issued between 2017 and 2021?
CREATE TABLE MicrofinanceLoans (institution_name VARCHAR(50),loan_year INT,loan_amount DECIMAL(10,2),region VARCHAR(50));
SELECT institution_name, AVG(loan_amount) as avg_loan_amount, loan_year FROM MicrofinanceLoans WHERE region = 'South Asia' AND loan_year BETWEEN 2017 AND 2021 GROUP BY institution_name, loan_year;
What is the average calorie count for dishes served in 'FineDining' restaurants?
CREATE TABLE Restaurants (id INT,name VARCHAR(255),type VARCHAR(255)); INSERT INTO Restaurants (id,name,type) VALUES (1,'FancyBistro','FineDining'),(2,'BudgetEats','CasualDining'); CREATE TABLE Menu (id INT,restaurant_id INT,dish VARCHAR(255),calories INT); INSERT INTO Menu (id,restaurant_id,dish,calories) VALUES (1,1,'Lobster Thermidor',750),(2,1,'Seasonal Vegetable Medley',200),(3,2,'Cheese Pizza',600),(4,2,'Side Salad',150);
SELECT AVG(calories) FROM Menu WHERE restaurant_id IN (SELECT id FROM Restaurants WHERE type = 'FineDining');
What is the total funding amount for startups founded by people from underrepresented racial or ethnic groups in the USA?
CREATE TABLE startups (id INT,name TEXT,location TEXT,founder_race TEXT,funding_amount INT); INSERT INTO startups (id,name,location,founder_race,funding_amount) VALUES (1,'Startup A','USA','African American',3000000); INSERT INTO startups (id,name,location,founder_race,funding_amount) VALUES (2,'Startup B','Canada','Caucasian',5000000); INSERT INTO startups (id,name,location,founder_race,funding_amount) VALUES (3,'Startup C','USA','Hispanic',4000000);
SELECT SUM(funding_amount) FROM startups WHERE location = 'USA' AND founder_race IN ('African American', 'Hispanic', 'Native American', 'Pacific Islander');
What was the average market price for Y and Er in Q2 2022?
CREATE TABLE market_trends (element VARCHAR(2),quarter INT,year INT,price DECIMAL(5,2)); INSERT INTO market_trends VALUES ('Y',2,2022,30.5),('Er',2,2022,55.3),('Y',2,2022,31.2);
SELECT AVG(price) as avg_price FROM market_trends WHERE element IN ('Y', 'Er') AND quarter = 2 AND year = 2022;
Show the name and total calories of the dishes that have more than 700 calories
CREATE TABLE dishes (dish_id INT,dish_name TEXT,calories INT); INSERT INTO dishes (dish_id,dish_name,calories) VALUES (1,'Pizza',1200),(2,'Spaghetti',1000),(3,'Salad',500),(4,'Sushi',800),(5,'Burger',750);
SELECT dish_name, SUM(calories) FROM dishes GROUP BY dish_name HAVING SUM(calories) > 700;
Which countries have the most stores with circular supply chains?
CREATE TABLE stores (store_id INT,country VARCHAR(50),supply_chain VARCHAR(20)); INSERT INTO stores (store_id,country,supply_chain) VALUES (1,'USA','circular'),(2,'Canada','linear'),(3,'Mexico','circular'),(4,'Brazil','circular');
SELECT country, COUNT(*) as store_count FROM stores WHERE supply_chain = 'circular' GROUP BY country ORDER BY store_count DESC;
What was the total revenue for beauty products made in the US in Q2 2021?
CREATE TABLE beauty_products (manufacturing_country VARCHAR(20),sale_date DATE,revenue DECIMAL(10,2)); INSERT INTO beauty_products (manufacturing_country,sale_date,revenue) VALUES ('US','2021-04-01',200.00),('Canada','2021-04-01',150.00);
SELECT SUM(revenue) FROM beauty_products WHERE manufacturing_country = 'US' AND sale_date BETWEEN '2021-04-01' AND '2021-06-30';
What is the total quantity of dishes sold in each region in 2022?
CREATE TABLE Orders (order_id INT PRIMARY KEY,customer_id INT,menu_id INT,order_date DATETIME,quantity INT); CREATE TABLE Menu (menu_id INT PRIMARY KEY,menu_item VARCHAR(255),category VARCHAR(255),price DECIMAL(5,2),region VARCHAR(255));
SELECT Menu.region, SUM(Orders.quantity) as total_quantity FROM Orders INNER JOIN Menu ON Orders.menu_id = Menu.menu_id WHERE EXTRACT(YEAR FROM Orders.order_date) = 2022 GROUP BY Menu.region;
Who is the youngest employee in the Sales department?
CREATE TABLE Employees (Employee_ID INT,First_Name VARCHAR(20),Last_Name VARCHAR(20),Department VARCHAR(20),Salary DECIMAL(10,2),Date_Hired DATE); CREATE VIEW Youngest_Employee AS SELECT Employee_ID,First_Name,Last_Name,Department,Salary,Date_Hired FROM Employees WHERE Date_Hired = (SELECT MIN(Date_Hired) FROM Employees); CREATE VIEW Youngest_Sales_Employee AS SELECT * FROM Youngest_Employee WHERE Department = 'Sales';
SELECT * FROM Youngest_Sales_Employee;
Which countries have solar farms with a capacity greater than 150 MW?
CREATE TABLE solar_farms (name TEXT,capacity INTEGER,country TEXT); INSERT INTO solar_farms (name,capacity,country) VALUES ('Solar Farm 1',200,'Germany'),('Solar Farm 2',100,'France'),('Solar Farm 3',300,'Spain');
SELECT DISTINCT country FROM solar_farms WHERE capacity > 150
What is the percentage of unvaccinated children in rural areas?
CREATE TABLE vaccinations (id INT,rural BOOLEAN,vaccinated BOOLEAN); INSERT INTO vaccinations (id,rural,vaccinated) VALUES (1,true,true),(2,false,false),(3,true,false);
SELECT COUNT(*) * 100.0 / (SELECT COUNT(*) FROM vaccinations WHERE rural = true) FROM vaccinations WHERE rural = true AND vaccinated = false;
List all sustainable seafood certifications and their respective organization names.
CREATE TABLE certifications (id INT,name TEXT,organization TEXT); INSERT INTO certifications (id,name,organization) VALUES (1,'MSC','Marine Stewardship Council'),(2,'ASC','Aquaculture Stewardship Council'),(3,'BAP','Best Aquaculture Practices');
SELECT name, organization FROM certifications;
Show the number of skincare products that are both organic and halal certified
CREATE TABLE products (product_id INT,product_name VARCHAR(50),product_type VARCHAR(20),halal_certified BOOLEAN); INSERT INTO products (product_id,product_name,product_type,halal_certified) VALUES (1,'moisturizer','skincare',true),(2,'cleanser','skincare',false),(3,'sunscreen','skincare',true),(4,'toner','skincare',false); INSERT INTO products (product_id,product_name,product_type,halal_certified) VALUES (5,'organic moisturizer','skincare',true),(6,'organic cleanser','skincare',false),(7,'organic sunscreen','skincare',true),(8,'organic toner','skincare',false);
SELECT COUNT(*) FROM products WHERE product_type = 'skincare' AND halal_certified = true AND product_name LIKE 'organic%';
What is the landfill capacity for 'India' in 2023?
CREATE TABLE country_landfill_capacity (country VARCHAR(20),year INT,capacity INT); INSERT INTO country_landfill_capacity (country,year,capacity) VALUES ('India',2023,500000),('China',2023,750000),('USA',2023,1000000);
SELECT country, capacity FROM country_landfill_capacity WHERE country = 'India' AND year = 2023;
Which state has the lowest average salary for workers in the 'service' industry?
CREATE TABLE service_workers (id INT,name VARCHAR(255),state VARCHAR(255),industry VARCHAR(255),salary DECIMAL(10,2)); INSERT INTO service_workers (id,name,state,industry,salary) VALUES (1,'James White','Texas','service',30000.00),(2,'Emily Green','Florida','service',32000.00);
SELECT state, AVG(salary) FROM service_workers WHERE industry = 'service' GROUP BY state ORDER BY AVG(salary) ASC LIMIT 1;
How many cases were resolved using restorative justice practices in the cases table in 2021?
CREATE TABLE cases (id INT,year INT,restorative_justice BOOLEAN);
SELECT COUNT(*) FROM cases WHERE restorative_justice = TRUE AND year = 2021;
What is the total cargo weight transported by Vessel6 in May 2021?
CREATE TABLE CargoTransport(TransportID INT,VesselID INT,CargoWeight INT,TransportDate DATETIME); INSERT INTO CargoTransport(TransportID,VesselID,CargoWeight,TransportDate) VALUES (4,6,12000,'2021-05-05 14:30:00'),(5,6,18000,'2021-05-20 11:00:00');
SELECT SUM(CargoWeight) FROM CargoTransport WHERE VesselID = 6 AND TransportDate BETWEEN '2021-05-01' AND '2021-05-31';
What is the average energy efficiency rating for electric vehicles (EVs) sold in Norway?
CREATE TABLE EVs (Type VARCHAR(20),Country VARCHAR(20),Rating INT); INSERT INTO EVs VALUES ('Tesla Model 3','Norway',140),('Nissan Leaf','Norway',120),('Audi e-Tron','Norway',130),('Volvo XC40 Recharge','Norway',145);
SELECT Type, AVG(Rating) AS Avg_Rating FROM EVs WHERE Country = 'Norway' GROUP BY Type;
What is the total playtime for each player, pivoted by day of the week?
CREATE TABLE PlayerGamePlay (PlayerID int,PlayerName varchar(50),Day varchar(15),Playtime int); INSERT INTO PlayerGamePlay (PlayerID,PlayerName,Day,Playtime) VALUES (1,'Player1','Monday',120),(2,'Player2','Tuesday',150),(3,'Player3','Wednesday',180),(4,'Player4','Thursday',100),(5,'Player5','Friday',160),(6,'Player1','Saturday',200),(7,'Player2','Sunday',140);
SELECT PlayerName, SUM(Monday) as MondayPlaytime, SUM(Tuesday) as TuesdayPlaytime, SUM(Wednesday) as WednesdayPlaytime, SUM(Thursday) as ThursdayPlaytime, SUM(Friday) as FridayPlaytime, SUM(Saturday) as SaturdayPlaytime, SUM(Sunday) as SundayPlaytime FROM (SELECT PlayerName, CASE Day WHEN 'Monday' THEN Playtime ELSE 0 END as Monday, CASE Day WHEN 'Tuesday' THEN Playtime ELSE 0 END as Tuesday, CASE Day WHEN 'Wednesday' THEN Playtime ELSE 0 END as Wednesday, CASE Day WHEN 'Thursday' THEN Playtime ELSE 0 END as Thursday, CASE Day WHEN 'Friday' THEN Playtime ELSE 0 END as Friday, CASE Day WHEN 'Saturday' THEN Playtime ELSE 0 END as Saturday, CASE Day WHEN 'Sunday' THEN Playtime ELSE 0 END as Sunday FROM PlayerGamePlay) as PivotTable GROUP BY PlayerName;
Which communities have held the most education programs about tiger conservation?
CREATE TABLE communities (name VARCHAR(255),education_programs INT); INSERT INTO communities (name,education_programs) VALUES ('village_1',3); INSERT INTO communities (name,education_programs) VALUES ('village_2',5);
SELECT name FROM communities ORDER BY education_programs DESC LIMIT 1;
Average annual rainfall in forests of the Amazon Basin.
CREATE TABLE forests (id INT,name VARCHAR(255),region VARCHAR(255),avg_annual_rainfall FLOAT);
SELECT AVG(avg_annual_rainfall) FROM forests WHERE region = 'Amazon Basin';
Which safety protocols were implemented in the first quarter of 2022 by each facility?
CREATE TABLE Facility(Id INT,Name VARCHAR(50),Location VARCHAR(50)); CREATE TABLE SafetyProtocol(Id INT,Name VARCHAR(50),FacilityId INT,ImplementationDate DATE);
SELECT f.Name, QUARTER(s.ImplementationDate) AS Quarter, YEAR(s.ImplementationDate) AS Year, s.Name AS ProtocolName FROM SafetyProtocol s JOIN Facility f ON s.FacilityId = f.Id WHERE YEAR(s.ImplementationDate) = 2022 AND QUARTER(s.ImplementationDate) = 1;
What is the maximum waste generation per site for South African mining operations in 2019?
CREATE TABLE EnvironmentalImpact (Site VARCHAR(255),CO2Emissions INT,WaterUsage INT,WasteGeneration INT,ReportDate DATE,Country VARCHAR(255));
SELECT Site, MAX(WasteGeneration) as MaxWasteGeneration FROM EnvironmentalImpact WHERE ReportDate BETWEEN '2019-01-01' AND '2019-12-31' AND Country = 'South Africa' GROUP BY Site;
How many community health workers have not received mental health parity training?
CREATE TABLE CommunityHealthWorkers (WorkerID INT,Name VARCHAR(50),Specialty VARCHAR(50),MentalHealthParity BOOLEAN); INSERT INTO CommunityHealthWorkers (WorkerID,Name,Specialty,MentalHealthParity) VALUES (1,'John Doe','Mental Health',TRUE); INSERT INTO CommunityHealthWorkers (WorkerID,Name,Specialty,MentalHealthParity) VALUES (2,'Jane Smith','Physical Health',FALSE);
SELECT COUNT(*) FROM CommunityHealthWorkers WHERE MentalHealthParity = FALSE;
What is the total number of eSports events in the 'Puzzle' category that took place in 2020 or 2021?
CREATE TABLE EventCategories (event VARCHAR(100),category VARCHAR(50),year INT);
SELECT COUNT(*) FROM EventCategories WHERE category = 'Puzzle' AND year IN (2020, 2021);
Insert a new record into 'rural_healthcare' table with name 'Rural Mental Health Clinic', type 'Clinic', and location 'Desert Region'
CREATE TABLE rural_healthcare (name VARCHAR(255),type VARCHAR(255),location VARCHAR(255));
INSERT INTO rural_healthcare (name, type, location) VALUES ('Rural Mental Health Clinic', 'Clinic', 'Desert Region');
Which facilities handle chemicals with an environmental impact score higher than 80?
CREATE TABLE Facilities (name VARCHAR(255),chemical VARCHAR(255),environmental_impact_score INT); INSERT INTO Facilities (name,chemical,environmental_impact_score) VALUES ('Facility A','Acetone',60),('Facility B','Ammonia',90),('Facility C','Chloroform',75),('Facility D','Ethanol',50);
SELECT name FROM Facilities WHERE environmental_impact_score > 80;
What is the total revenue for each game genre in the last quarter?
CREATE TABLE games (id INT,genre VARCHAR(255),revenue DECIMAL(5,2));
SELECT genre, SUM(revenue) FROM games WHERE revenue IS NOT NULL AND purchase_date >= DATE_SUB(CURDATE(), INTERVAL 3 MONTH) GROUP BY genre;
What is the number of financially capable individuals in each country?
CREATE TABLE if not exists individuals (id INT,country VARCHAR(50),is_financially_capable BOOLEAN,age INT,gender VARCHAR(10));
SELECT country, COUNT(*) FROM individuals WHERE is_financially_capable = TRUE GROUP BY country;
How many accidents occurred in the aviation industry per year?
CREATE TABLE Accidents (id INT,year INT,accident_type VARCHAR(50)); CREATE VIEW AviationAccidents AS SELECT * FROM Accidents WHERE accident_type = 'aviation';
SELECT AviationAccidents.year, COUNT(*) as num_accidents FROM AviationAccidents GROUP BY AviationAccidents.year ORDER BY AviationAccidents.year;
List all the unique threat actors involved in incidents that occurred in the last 6 months, sorted by the number of incidents each actor was involved in.
CREATE TABLE threat_actors (actor VARCHAR(50),incident_count INT,incident_date DATE); INSERT INTO threat_actors (actor,incident_count,incident_date) VALUES ('Actor A',20,'2023-01-01'),('Actor B',15,'2023-01-02'),('Actor C',12,'2023-01-03'),('Actor A',18,'2023-01-04'),('Actor B',10,'2023-01-05');
SELECT actor, incident_count FROM threat_actors WHERE incident_date >= DATEADD(month, -6, GETDATE()) GROUP BY actor ORDER BY SUM(incident_count) DESC;
Delete the record of an attendee with ID 4 from the event_attendance table.
CREATE TABLE attendee_demographics (attendee_id INT,attendee_name VARCHAR(50),attendee_age INT); INSERT INTO attendee_demographics (attendee_id,attendee_name,attendee_age) VALUES (1,'Jane Smith',25),(2,'Michael Johnson',17),(3,'Sophia Rodriguez',16),(4,'David Kim',22); CREATE TABLE event_attendance (attendee_id INT,event_name VARCHAR(50)); INSERT INTO event_attendance (attendee_id,event_name) VALUES (1,'Art Exhibit'),(2,'Art Workshop'),(3,'Art Exhibit'),(4,'Art Workshop');
DELETE FROM event_attendance WHERE attendee_id = 4;
What are the latest intelligence gathering operations in the 'IntelligenceGatheringOperations' table?
CREATE TABLE IntelligenceGatheringOperations (operation_name VARCHAR(100),operation_type VARCHAR(50),location VARCHAR(50),start_date DATE,end_date DATE); INSERT INTO IntelligenceGatheringOperations (operation_name,operation_type,location,start_date,end_date) VALUES ('Operation Red Tiger','Surveillance','Asia','2022-03-01','2022-06-30'); INSERT INTO IntelligenceGatheringOperations (operation_name,operation_type,location,start_date,end_date) VALUES ('Operation Blue Lynx','Counterintelligence','Europe','2022-04-15','2022-07-31');
SELECT operation_name, operation_type, location, start_date, end_date FROM IntelligenceGatheringOperations ORDER BY start_date DESC LIMIT 1;
What is the number of items in warehouse 'DEL'?
CREATE TABLE inventory (item_code varchar(5),warehouse_id varchar(5),quantity int); INSERT INTO inventory (item_code,warehouse_id,quantity) VALUES ('E01','DEL',1000),('E02','DEL',1100);
SELECT COUNT(DISTINCT item_code) FROM inventory WHERE warehouse_id = 'DEL';
Who are the top 3 news organizations in Africa in terms of articles published in 2021?
CREATE TABLE news_organizations (id INT,name VARCHAR(50),country VARCHAR(50),articles_published INT); INSERT INTO news_organizations (id,name,country,articles_published) VALUES (1,'Org1','Africa',1000),(2,'Org2','Europe',1500),(3,'Org3','Asia',2000);
SELECT name, country, articles_published FROM news_organizations WHERE country = 'Africa' ORDER BY articles_published DESC LIMIT 3;
What is the number of job applicants by job category, for the last 12 months?
CREATE TABLE JobApplications (ApplicationID INT,ApplicantID INT,JobCategory VARCHAR(50),ApplicationDate DATE);
SELECT JobCategory, COUNT(DISTINCT ApplicantID) FROM JobApplications WHERE ApplicationDate >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH) GROUP BY JobCategory;
What is the total value of all successful transactions for customers with a "Premium" status?
CREATE TABLE customer_status (customer_id INT,status VARCHAR(10)); INSERT INTO customer_status (customer_id,status) VALUES (1,'Basic'),(2,'Premium'),(3,'Basic'),(4,'Premium'); CREATE TABLE transactions_4 (transaction_id INT,customer_id INT,amount DECIMAL(10,2),success BOOLEAN); INSERT INTO transactions_4 (transaction_id,customer_id,amount,success) VALUES (1,1,500.00,true),(2,1,750.00,false),(3,2,300.00,true),(4,4,9000.00,true);
SELECT SUM(amount) FROM transactions_4 t JOIN customer_status cs ON t.customer_id = cs.customer_id WHERE cs.status = 'Premium' AND t.success = true;
What is the total number of accessible taxi rides in Moscow in 2022?
CREATE TABLE TaxiRides (id INT,city VARCHAR(255),ride_type VARCHAR(255),ride_date DATE); CREATE TABLE TaxiServices (id INT,city VARCHAR(255),service_type VARCHAR(255),revenue DECIMAL(10,2));
SELECT COUNT(*) FROM TaxiRides TR INNER JOIN TaxiServices TS ON TR.city = TS.city WHERE TR.city = 'Moscow' AND TR.ride_type = 'Accessible' AND YEAR(ride_date) = 2022;
List the names and GPAs of all students in the "students" table.
CREATE TABLE students (student_id INT,name VARCHAR(255),major VARCHAR(255),gpa DECIMAL(3,2));
SELECT name, gpa FROM students;
Update the 'acres' column for mining sites located in 'MT' in the 'sites' table.
CREATE TABLE sites (site_id INT,state VARCHAR(2),num_workers INT,acres FLOAT);
UPDATE sites SET acres = acres * 1.2 WHERE state = 'MT';
Find the number of bicycles available in each station of the 'bike_share' system
CREATE SCHEMA IF NOT EXISTS public_transport;CREATE TABLE IF NOT EXISTS public_transport.bike_share (station_name TEXT,num_bikes_available INTEGER);INSERT INTO public_transport.bike_share (station_name,num_bikes_available) VALUES ('Station A',15),('Station B',8),('Station C',23);
SELECT station_name, num_bikes_available FROM public_transport.bike_share;
What is the average population of marine life research data entries for species with the word 'Whale' in their name?
CREATE TABLE marine_life_research(id INT,species VARCHAR(50),population INT); INSERT INTO marine_life_research(id,species,population) VALUES (1,'Beluga Whale',250),(2,'Whale Shark',300),(3,'Dolphin',600);
SELECT AVG(population) FROM marine_life_research WHERE species LIKE '%Whale%';
What is the percentage of global cobalt production by the Democratic Republic of Congo?
CREATE TABLE annual_cobalt_production (id INT,country VARCHAR(255),year INT,quantity INT); INSERT INTO annual_cobalt_production (id,country,year,quantity) VALUES (1,'Democratic Republic of Congo',2020,90000),(2,'China',2020,8000),(3,'Russia',2020,7000),(4,'Australia',2020,6000),(5,'Canada',2020,5000);
SELECT 100.0 * SUM(CASE WHEN country = 'Democratic Republic of Congo' THEN quantity ELSE 0 END) / SUM(quantity) as percentage_of_global_cobalt_production FROM annual_cobalt_production WHERE year = 2020;
What is the total number of primary care physicians in 'RuralHealthFacilities' table for each state?
CREATE TABLE RuralHealthFacilities (facility_id INT,facility_name VARCHAR(50),state VARCHAR(20),physician_type VARCHAR(20)); INSERT INTO RuralHealthFacilities (facility_id,facility_name,state,physician_type) VALUES (1,'RuralClinicAK','Alaska','Primary Care'),(2,'RuralHospitalHI','Hawaii','Primary Care'),(3,'RuralClinicTX','Texas','Primary Care'),(4,'RuralHospitalFL','Florida','Primary Care');
SELECT state, COUNT(*) FROM RuralHealthFacilities WHERE physician_type = 'Primary Care' GROUP BY state;
Which teachers need professional development based on their years of experience?
CREATE TABLE teachers (teacher_id INT,teacher_name VARCHAR(50),school_id INT,years_of_experience INT); INSERT INTO teachers (teacher_id,teacher_name,school_id,years_of_experience) VALUES (1,'Alice Brown',1001,12),(2,'David Lee',1001,2),(3,'Emily White',1002,8);
SELECT teacher_id, teacher_name, years_of_experience, NTILE(3) OVER (ORDER BY years_of_experience) as experience_group FROM teachers;
What is the number of unique donors and total donation amount per program category?
CREATE TABLE program_categories (program_category_id INT,program_category_name VARCHAR(50));CREATE TABLE donations (donation_id INT,donor_id INT,program_category_id INT,donation_amount DECIMAL(10,2)); INSERT INTO program_categories (program_category_id,program_category_name) VALUES (1,'Education'),(2,'Environment'),(3,'Health'); INSERT INTO donations (donation_id,donor_id,program_category_id,donation_amount) VALUES (1,1,1,500.00),(2,2,1,750.00),(3,3,2,300.00),(4,4,3,400.00),(5,5,3,600.00);
SELECT pc.program_category_name, COUNT(DISTINCT d.donor_id) as unique_donors, SUM(d.donation_amount) as total_donation_amount FROM program_categories pc JOIN donations d ON pc.program_category_id = d.program_category_id GROUP BY pc.program_category_name;
How many properties are there in each city in the database?
CREATE TABLE properties (property_id INT,city VARCHAR(50)); INSERT INTO properties (property_id,city) VALUES (1,'Portland'),(2,'Seattle'),(3,'Portland'),(4,'Oakland');
SELECT city, COUNT(*) FROM properties GROUP BY city;
What is the adoption rate of AI in 'Seoul' hotels for luxury hotels?
CREATE TABLE ai_adoption (hotel_id INT,city TEXT,adoption_rate INT); INSERT INTO ai_adoption (hotel_id,city,adoption_rate) VALUES (3,'Seoul',85),(4,'Seoul',90),(5,'Seoul',80),(6,'Tokyo',95); CREATE TABLE luxury_hotels (hotel_id INT,is_luxury INT); INSERT INTO luxury_hotels (hotel_id,is_luxury) VALUES (3,1),(4,1),(5,1),(6,1);
SELECT AVG(ai_adoption.adoption_rate) FROM ai_adoption JOIN luxury_hotels ON ai_adoption.hotel_id = luxury_hotels.hotel_id WHERE ai_adoption.city = 'Seoul' AND luxury_hotels.is_luxury = 1;
List the products that were part of a circular supply chain in 2022
CREATE TABLE product_supply_chain (product_id INT,partner_id INT,partner_type TEXT,supply_chain_year INT);
SELECT DISTINCT product_id FROM product_supply_chain WHERE partner_type = 'Circular' AND supply_chain_year = 2022;
Who is the most expensive artist in the 'Abstract Art' category?
CREATE TABLE ArtistPrices (id INT,artist VARCHAR(30),category VARCHAR(20),price DECIMAL(5,2)); INSERT INTO ArtistPrices (id,artist,category,price) VALUES (1,'Artist A','Abstract Art',6000.00),(2,'Artist B','Abstract Art',8000.00),(3,'Artist C','Contemporary Art',9000.00);
SELECT artist, MAX(price) FROM ArtistPrices WHERE category = 'Abstract Art' GROUP BY artist;
How many policies were issued in each state?
CREATE TABLE Policies (id INT,state VARCHAR(20),policy_number INT); INSERT INTO Policies (id,state,policy_number) VALUES (1,'California',100),(2,'Texas',120),(3,'New York',150),(4,'Florida',110);
SELECT state, COUNT(policy_number) as policy_count FROM Policies GROUP BY state;
What is the average number of hospital beds per hospital in each state?
CREATE TABLE hospitals (id INT,name TEXT,state TEXT,num_beds INT); INSERT INTO hospitals (id,name,state,num_beds) VALUES (1,'General Hospital','California',500),(2,'Rural Hospital','Texas',100);
SELECT state, AVG(num_beds) FROM hospitals GROUP BY state;
Insert a new record into the "hydro_plants" table for a plant with 100 MW capacity in Canada
CREATE TABLE hydro_plants (id INT,name VARCHAR(50),location VARCHAR(50),capacity FLOAT);
INSERT INTO hydro_plants (id, name, location, capacity) VALUES (1, 'HP1', 'Canada', 100);
What is the total number of security incidents and their respective categories for each region in the last quarter?
CREATE TABLE incident_region (id INT,incident_id INT,region VARCHAR(255),category VARCHAR(255),year INT,quarter INT); INSERT INTO incident_region (id,incident_id,region,category,year,quarter) VALUES (1,1,'North America','Malware',2022,1),(2,2,'Europe','Phishing',2022,1),(3,3,'Asia','SQL Injection',2022,1),(4,4,'South America','Cross-site Scripting',2022,1),(5,5,'Africa','DDOS',2022,1),(6,6,'Australia','Insider Threat',2022,1);
SELECT region, category, COUNT(*) as total, STRING_AGG(incident_id::text, ',') as incidents FROM incident_region WHERE year = 2022 AND quarter = 1 GROUP BY region, category ORDER BY total DESC;
Delete marine species records from 'Antarctica' before 2019.
CREATE TABLE Species_4 (id INT,name VARCHAR(255),region VARCHAR(255),year INT); INSERT INTO Species_4 (id,name,region,year) VALUES (1,'Penguin','Antarctica',2018); INSERT INTO Species_4 (id,name,region,year) VALUES (2,'Seal','Antarctica',2019); INSERT INTO Species_4 (id,name,region,year) VALUES (3,'Whale','Antarctica',2020);
DELETE FROM Species_4 WHERE region = 'Antarctica' AND year < 2019;
Delete project with id 1 from 'adaptation_projects' table
CREATE TABLE adaptation_projects (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),budget FLOAT,start_date DATE,end_date DATE); INSERT INTO adaptation_projects (id,name,location,budget,start_date,end_date) VALUES (1,'Seawall Construction','New York City,USA',2000000,'2022-01-01','2023-12-31'),(2,'Drought Resistant Crops','Cape Town,South Africa',800000,'2023-05-15','2024-04-30'),(3,'Flood Early Warning System','Dhaka,Bangladesh',1000000,'2023-07-01','2025-06-30');
DELETE FROM adaptation_projects WHERE id = 1;