instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Update the 'contract_amount' field in the 'defense_contracts' table for records where 'contracting_agency' is 'Department of the Navy' and 'contract_status' is 'active' by setting the 'contract_amount' to 'contract_amount' + 0.10 * 'contract_amount'
CREATE TABLE defense_contracts (contract_id INT PRIMARY KEY,contracting_agency VARCHAR(255),contract_status VARCHAR(255),contract_amount DECIMAL(10,2));
UPDATE defense_contracts SET contract_amount = contract_amount + 0.10 * contract_amount WHERE contracting_agency = 'Department of the Navy' AND contract_status = 'active';
What is the total number of size 8 and size 10 garments in stock?
CREATE TABLE GarmentInventory (garment_id INT,size INT,quantity INT); INSERT INTO GarmentInventory VALUES (1,8,200),(2,10,150),(3,12,300);
SELECT SUM(quantity) FROM GarmentInventory WHERE size IN (8, 10);
How many patients have been treated with meditation for PTSD in California?
CREATE TABLE patients (patient_id INT,patient_name TEXT,condition TEXT,therapist_id INT,treatment TEXT); INSERT INTO patients (patient_id,patient_name,condition,therapist_id,treatment) VALUES (1,'James Johnson','PTSD',1,'Meditation'); INSERT INTO patients (patient_id,patient_name,condition,therapist_id,treatment) VALUES (2,'Sophia Lee','PTSD',1,'Medication'); CREATE TABLE therapists (therapist_id INT,therapist_name TEXT,state TEXT); INSERT INTO therapists (therapist_id,therapist_name,state) VALUES (1,'Dr. Maria Rodriguez','California');
SELECT COUNT(*) FROM patients JOIN therapists ON patients.therapist_id = therapists.therapist_id WHERE patients.condition = 'PTSD' AND patients.treatment = 'Meditation' AND therapists.state = 'California';
What are the conservation efforts for endangered marine species in the Mediterranean Sea?
CREATE TABLE marine_species (species_id INT,species_name VARCHAR(255),conservation_status VARCHAR(50)); CREATE TABLE conservation_efforts (effort_id INT,species_id INT,ocean VARCHAR(50),effort_description VARCHAR(255)); INSERT INTO marine_species (species_id,species_name,conservation_status) VALUES (1,'Mediterranean Monk Seal','Endangered'),(2,'Basking Shark','Vulnerable'); INSERT INTO conservation_efforts (effort_id,species_id,ocean,effort_description) VALUES (1,1,'Mediterranean','Habitat Protection'),(2,2,'Atlantic','Research and Monitoring');
SELECT conservation_efforts.effort_description FROM marine_species INNER JOIN conservation_efforts ON marine_species.species_id = conservation_efforts.species_id WHERE marine_species.conservation_status = 'Endangered' AND conservation_efforts.ocean = 'Mediterranean';
Insert data into sustainable_fabric
CREATE TABLE sustainable_fabric (id INT PRIMARY KEY,fabric VARCHAR(25),country_of_origin VARCHAR(20)); INSERT INTO sustainable_fabric (id,fabric,country_of_origin) VALUES (1,'Organic Cotton','India'),(2,'Tencel','Austria'),(3,'Hemp','China'),(4,'Recycled Polyester','Japan');
INSERT INTO sustainable_fabric (id, fabric, country_of_origin) VALUES (1, 'Organic Cotton', 'India'), (2, 'Tencel', 'Austria'), (3, 'Hemp', 'China'), (4, 'Recycled Polyester', 'Japan');
What is the maximum fuel consumption rate for VESSEL011?
CREATE TABLE vessels (id VARCHAR(20),name VARCHAR(20)); INSERT INTO vessels (id,name) VALUES ('VES011','VESSEL011'),('VES012','VESSEL012'); CREATE TABLE fuel_consumption (vessel_id VARCHAR(20),consumption_rate DECIMAL(5,2)); INSERT INTO fuel_consumption (vessel_id,consumption_rate) VALUES ('VES011',4.5),('VES011',4.6),('VES011',4.4),('VES012',4.7),('VES012',4.8),('VES012',4.9);
SELECT MAX(consumption_rate) FROM fuel_consumption WHERE vessel_id = 'VES011';
List all cities with mobile subscribers who have not used any data in the last month.
CREATE TABLE subscribers(id INT,city VARCHAR(20),last_data_usage_date DATE,monthly_data_usage DECIMAL(5,2)); INSERT INTO subscribers(id,city,last_data_usage_date,monthly_data_usage) VALUES (1,'New York','2022-01-15',3.5),(2,'New York','2022-02-10',4.2),(3,'Chicago','2022-03-05',0.0);
SELECT city FROM subscribers WHERE monthly_data_usage = 0 AND last_data_usage_date < DATE_SUB(CURDATE(), INTERVAL 1 MONTH) GROUP BY city;
What is the recycling rate for the 'South' region in 2019?
CREATE TABLE recycling_rates (region VARCHAR(10),year INT,rate DECIMAL(3,2)); INSERT INTO recycling_rates (region,year,rate) VALUES ('North',2018,0.55),('North',2019,0.58),('North',2020,0.61),('South',2018,0.60),('South',2019,0.63),('South',2020,0.66),('East',2018,0.65),('East',2019,0.68),('East',2020,0.71),('West',2018,0.70),('West',2019,0.73),('West',2020,0.76);
SELECT rate FROM recycling_rates WHERE region = 'South' AND year = 2019;
What is the market share of public transportation systems in Japan?
CREATE TABLE PT_Usage (id INT,system_type VARCHAR(20),country VARCHAR(50),users INT,market_share FLOAT); INSERT INTO PT_Usage (id,system_type,country,users,market_share) VALUES (1,'Tokyo Metro','Japan',2500000,0.35),(2,'Osaka Municipal Subway','Japan',900000,0.12),(3,'Nagoya Municipal Subway','Japan',650000,0.09);
SELECT AVG(market_share) as avg_market_share FROM PT_Usage WHERE country = 'Japan';
Delete the marine protected area with the minimum depth
CREATE TABLE marine_protected_areas (area_id INT,name VARCHAR(50),depth FLOAT,ocean VARCHAR(10)); INSERT INTO marine_protected_areas (area_id,name,depth,ocean) VALUES (1,'Great Barrier Reef',34,'Pacific'),(2,'Galapagos Islands',170,'Pacific'),(3,'Azores',500,'Atlantic');
DELETE FROM marine_protected_areas WHERE depth = (SELECT MIN(depth) FROM marine_protected_areas);
Delete the papers related to 'Algorithmic Fairness' category.
CREATE TABLE papers (paper_id INT,title VARCHAR(100),author_id INT,published_date DATE,category VARCHAR(50)); INSERT INTO papers (paper_id,title,author_id,published_date,category) VALUES (1,'Fairness in AI',1,'2021-06-01','Algorithmic Fairness'); INSERT INTO papers (paper_id,title,author_id,published_date,category) VALUES (2,'AI Safety Challenges',2,'2021-07-15','AI Safety'); INSERT INTO papers (paper_id,title,author_id,published_date,category) VALUES (3,'Interpretable AI Models',1,'2020-12-20','Explainable AI'); INSERT INTO papers (paper_id,title,author_id,published_date,category) VALUES (4,'Neural Symbolic Machine Learning',3,'2022-02-16','Creative AI Applications');
DELETE FROM papers WHERE category = 'Algorithmic Fairness';
Identify the top 3 AI research papers in terms of citations, published in the last 2 years, along with their authors and the number of citations they have received.
CREATE TABLE ai_papers (paper_id INT,title VARCHAR(100),publication_year INT,author_id INT,num_citations INT);
SELECT title, author_id, num_citations FROM ai_papers WHERE publication_year >= YEAR(CURRENT_DATE) - 2 GROUP BY paper_id ORDER BY num_citations DESC LIMIT 3;
List all destinations with more than 1 sustainable certification, ordered by the number of certifications in descending order.
CREATE TABLE sustainable_certifications (certification_id INT,destination TEXT,certification_type TEXT,certification_date DATE); INSERT INTO sustainable_certifications (certification_id,destination,certification_type,certification_date) VALUES (1,'Bali','Green Globe','2022-01-01'),(2,'Paris','EarthCheck','2022-02-01'),(3,'Bali','Green Key','2022-03-01');
SELECT destination FROM sustainable_certifications GROUP BY destination HAVING COUNT(*) > 1 ORDER BY COUNT(*) DESC;
Calculate the total funding for startups that have more than one founder
CREATE TABLE companies (id INT,name TEXT,region TEXT,num_founders INT,funding FLOAT); INSERT INTO companies (id,name,region,num_founders,funding) VALUES (1,'Startup A','west_coast',2,5000000),(2,'Startup B','east_coast',1,3000000),(3,'Startup C','west_coast',3,7000000),(4,'Startup D','east_coast',1,8000000);
SELECT SUM(funding) FROM companies WHERE num_founders > 1;
Determine the month with the lowest water consumption for the city of New York.
CREATE TABLE water_consumption (city VARCHAR(50),consumption FLOAT,month INT,year INT); INSERT INTO water_consumption (city,consumption,month,year) VALUES ('New York',120.2,1,2021),('New York',130.5,2,2021),('New York',100.8,3,2021);
SELECT month, MIN(consumption) FROM water_consumption WHERE city = 'New York' AND year = 2021;
Find the top 3 menu categories with the highest revenue in the last 7 days.
CREATE TABLE restaurant_revenue (menu_category VARCHAR(50),transaction_date DATE,revenue NUMERIC(10,2)); INSERT INTO restaurant_revenue (menu_category,transaction_date,revenue) VALUES ('Appetizers','2023-03-01',1500.00),('Entrees','2023-03-03',2500.00),('Desserts','2023-03-02',1200.00);
SELECT menu_category, SUM(revenue) AS total_revenue FROM restaurant_revenue WHERE transaction_date >= CURRENT_DATE - INTERVAL '7 days' GROUP BY menu_category ORDER BY total_revenue DESC LIMIT 3;
What is the average age of readers who prefer technology news in India, partitioned by gender?
CREATE TABLE readers (id INT,age INT,gender VARCHAR(10),country VARCHAR(50),news_preference VARCHAR(50)); INSERT INTO readers (id,age,gender,country,news_preference) VALUES (1,30,'Male','India','Technology'),(2,40,'Female','India','Technology');
SELECT AVG(age) avg_age, gender FROM readers WHERE country = 'India' AND news_preference = 'Technology' GROUP BY gender;
Count the number of users who have made a post on January 1, 2022 in the 'social_media' table.
CREATE TABLE social_media (user_id INT,post_id INT,post_date DATE);
SELECT COUNT(*) FROM social_media WHERE post_date = '2022-01-01';
What are the names of clients who have not paid their bills?
CREATE TABLE Clients (id INT,name VARCHAR(50),attorney_id INT,paid DECIMAL(5,2)); CREATE TABLE Bills (id INT,client_id INT,amount DECIMAL(5,2)); INSERT INTO Clients (id,name,attorney_id,paid) VALUES (1,'Client1',1,600.00),(2,'Client2',1,NULL),(3,'Client3',2,1000.00); INSERT INTO Bills (id,client_id,amount) VALUES (1,1,500.00),(2,2,700.00),(3,3,1200.00);
SELECT Clients.name FROM Clients LEFT JOIN Bills ON Clients.id = Bills.client_id WHERE Clients.paid IS NULL OR Bills.amount - Clients.paid > 0;
What is the maximum depth mapped in the Pacific Ocean?
CREATE TABLE OceanFloorMapping (location TEXT,depth INTEGER,map_date DATE); INSERT INTO OceanFloorMapping (location,depth,map_date) VALUES ('Pacific Ocean',6000,'2022-01-01');
SELECT OceanFloorMapping.location, MAX(depth) FROM OceanFloorMapping WHERE location = 'Pacific Ocean';
List the market access strategies and their respective success rates.
CREATE TABLE market_access (strategy VARCHAR(255),success_rate FLOAT); INSERT INTO market_access (strategy,success_rate) VALUES ('Direct to consumer',0.75),('Physician recommendation',0.85),('Pharmacy sales',0.65);
SELECT strategy, success_rate FROM market_access;
What is the total donation amount for each cause in the first quarter of 2022?
CREATE TABLE donations (id INT,cause VARCHAR(50),donation DECIMAL(10,2),donation_date DATE);
SELECT cause, SUM(donation) FROM donations WHERE donation_date >= '2022-01-01' AND donation_date < '2022-04-01' GROUP BY cause;
List clients and their total billing hours in the 'billing' table?
CREATE TABLE billing (attorney_id INT,client_id INT,hours FLOAT,rate FLOAT); INSERT INTO billing (attorney_id,client_id,hours,rate) VALUES (1,101,10,300),(2,102,8,350),(3,103,12,250);
SELECT client_id, SUM(hours) FROM billing GROUP BY client_id;
Update the role of employee with id 3 to 'senior employee'.
CREATE TABLE employees (id INT,name VARCHAR(50),department VARCHAR(50),role VARCHAR(50)); INSERT INTO employees (id,name,department,role) VALUES (1,'John Doe','hr','employee'),(2,'Jane Smith','hr','manager'),(3,'Bob Johnson','operations','employee'),(4,'Alice','it','employee');
UPDATE employees SET role = 'senior employee' WHERE id = 3;
What is the maximum altitude reached by SpaceX's Falcon Heavy rocket?
CREATE TABLE Max_Altitude (rocket VARCHAR(50),altitude INT); INSERT INTO Max_Altitude (rocket,altitude) VALUES ('Falcon Heavy',20000000),('Falcon 9',15000000);
SELECT altitude FROM Max_Altitude WHERE rocket = 'Falcon Heavy';
What is the total number of disaster response and community development staff members in each country?
CREATE TABLE staff_categories (id INT,name VARCHAR(255)); CREATE TABLE staff (id INT,country_id INT,category_id INT,hired_date DATE);
SELECT countries.name, COUNT(staff.id) FROM staff JOIN countries ON staff.country_id = countries.id WHERE staff.category_id IN (SELECT id FROM staff_categories WHERE name IN ('disaster response', 'community development')) GROUP BY staff.country_id;
List the names and average co-owner percentages for all properties in the 'co_ownership' table where the co-owner percentage is greater than 50.
CREATE TABLE co_ownership (property_id INT,owner VARCHAR(255),percentage INT); INSERT INTO co_ownership (property_id,owner,percentage) VALUES (1,'Alice',50),(1,'Bob',50),(2,'Carol',75),(2,'Dave',25),(3,'Eve',60),(3,'Frank',40);
SELECT owner, AVG(percentage) FROM co_ownership WHERE percentage > 50 GROUP BY owner;
Which organizations have received donations in the 'global_health' sector?
CREATE TABLE global_health (donor_id INTEGER,donation_amount INTEGER,organization_name TEXT); INSERT INTO global_health (donor_id,donation_amount,organization_name) VALUES (1,5000,'Malaria Consortium'),(2,4000,'Schistosomiasis Control Initiative');
SELECT DISTINCT organization_name FROM global_health WHERE organization_name LIKE '%global_health%';
How many heritage sites are there in Japan and their average visitor count?
CREATE TABLE heritage_sites (id INT,country VARCHAR(50),name VARCHAR(100),visitor_count INT); INSERT INTO heritage_sites (id,country,name,visitor_count) VALUES (1,'Japan','Site A',2000),(2,'Japan','Site B',3000),(3,'Italy','Site C',4000);
SELECT country, AVG(visitor_count) FROM heritage_sites WHERE country = 'Japan' GROUP BY country;
list all artifacts from site 'Chichen Itza' with their analysis status
CREATE TABLE artifact_chichen_itza (artifact_id INTEGER,artifact_name TEXT,analysis_status TEXT); INSERT INTO artifact_chichen_itza (artifact_id,artifact_name,analysis_status) VALUES (1,'Temple of Kukulcan','Analyzed'),(2,'Great Ball Court','Not Analyzed'),(3,'Platform of Venus','Analyzed'),(4,'Observatory','Analyzed'),(5,'Red House','Analyzed'),(6,'Skull Platform','Not Analyzed');
SELECT * FROM artifact_chichen_itza WHERE artifact_name = 'Chichen Itza';
Calculate the total revenue from natural hair care products
CREATE TABLE orders (id INT,product_id INT,quantity INT,price DECIMAL(5,2)); CREATE TABLE products (id INT,name VARCHAR(50),natural BOOLEAN);
SELECT SUM(orders.quantity * products.price) FROM orders JOIN products ON orders.product_id = products.id WHERE products.natural = TRUE;
What is the total number of satellites deployed by each manufacturer?
CREATE TABLE Manufacturers (name VARCHAR(50),satellites INT); INSERT INTO Manufacturers (name,satellites) VALUES ('SpaceX',200),('Boeing',100),('Lockheed Martin',75);
SELECT name, SUM(satellites) FROM Manufacturers GROUP BY name;
How many policy advocacy events were held in the last 12 months for mental health?
CREATE TABLE policy_events (event_id INT,event_date DATE,event_topic VARCHAR(255));
SELECT COUNT(*) FROM policy_events WHERE event_topic = 'Mental Health' AND event_date >= DATEADD(month, -12, GETDATE());
What is the average ticket price for 'E-Sports' events in 'Q1'?
CREATE TABLE Events (event_id INT,event_name VARCHAR(255),team VARCHAR(255),quarter VARCHAR(255),price DECIMAL(5,2)); INSERT INTO Events VALUES (1,'Tournament 1','E-Sports','Q1',25.00),(2,'Tournament 2','E-Sports','Q1',30.00);
SELECT AVG(price) FROM Events WHERE team = 'E-Sports' AND quarter = 'Q1';
What is the total budget allocated for transportation in 'RegionD'?
CREATE TABLE regions (id INT,name VARCHAR(50)); INSERT INTO regions (id,name) VALUES (1,'RegionA'),(2,'RegionB'),(3,'RegionC'),(4,'RegionD'); CREATE TABLE budget (id INT,region_id INT,department VARCHAR(50),amount INT); INSERT INTO budget (id,region_id,department,amount) VALUES (1,1,'Education',500000),(2,1,'Health',700000),(3,2,'Education',300000),(4,2,'Health',600000),(5,3,'Transportation',900000),(6,4,'Transportation',1200000);
SELECT SUM(amount) FROM budget WHERE department = 'Transportation' AND region_id IN (SELECT id FROM regions WHERE name = 'RegionD');
How many unique IP addresses communicated with a specific domain in the last month?
CREATE TABLE comm_history (id INT,ip_address VARCHAR(255),domain VARCHAR(255),communication_date DATE); INSERT INTO comm_history (id,ip_address,domain,communication_date) VALUES (1,'192.168.1.1','example.com','2021-01-01'),(2,'192.168.1.2','example.com','2021-01-01'),(3,'192.168.1.1','example.com','2021-01-02'),(4,'192.168.1.3','example.com','2021-01-02');
SELECT COUNT(DISTINCT ip_address) as unique_ips FROM comm_history WHERE domain = 'example.com' AND communication_date >= DATEADD(day, -30, GETDATE());
Show all records from the 'ethical_manufacturing' table
CREATE TABLE ethical_manufacturing (id INT AUTO_INCREMENT,company_name VARCHAR(50),location VARCHAR(50),ethical_certification VARCHAR(50),PRIMARY KEY(id));
SELECT * FROM ethical_manufacturing;
Determine the number of users who started using a streaming service in the last month, by service.
CREATE TABLE subscribers (user_id INT,service VARCHAR(50),subscription_date DATE); INSERT INTO subscribers (user_id,service,subscription_date) VALUES (1,'Netflix','2022-03-23'),(2,'Disney+','2022-03-18');
SELECT service, COUNT(*) as new_subscribers FROM subscribers WHERE subscription_date >= DATEADD(month, -1, GETDATE()) GROUP BY service;
What is the total number of digital assets launched by companies based in the United States and Canada?
CREATE TABLE digital_assets (id INT,name VARCHAR(255),company VARCHAR(255),launch_date DATE,country VARCHAR(255)); INSERT INTO digital_assets (id,name,company,launch_date,country) VALUES (1,'Asset 1','Company A','2021-01-01','USA'),(2,'Asset 2','Company B','2021-02-15','Canada');
SELECT COUNT(*) FROM digital_assets WHERE country IN ('USA', 'Canada');
Update the production count for well 'B02' in 'Alaska' to 6500.
CREATE TABLE wells (well_id VARCHAR(10),well_location VARCHAR(20)); INSERT INTO wells (well_id,well_location) VALUES ('B02','Alaska'); CREATE TABLE production (well_id VARCHAR(10),production_count INT); INSERT INTO production (well_id,production_count) VALUES ('B02',5000);
UPDATE production SET production_count = 6500 WHERE well_id = 'B02';
How many safety incidents were reported at the facility located in the Northern region in 2021?
CREATE TABLE Incidents (facility VARCHAR(20),year INT,incidents INT); INSERT INTO Incidents (facility,year,incidents) VALUES ('Northern',2021,4),('Northern',2022,2);
SELECT incidents FROM Incidents WHERE facility = 'Northern' AND year = 2021;
List all the vendors that have supplied products to a particular store in the last six months, along with the quantities of products supplied.
CREATE TABLE vendors (id INT,name VARCHAR(50),country VARCHAR(50)); CREATE TABLE vendor_shipments (id INT,vendor_id INT,store_id INT,shipment_date DATE,quantity INT); CREATE TABLE stores (id INT,name VARCHAR(50),city VARCHAR(50),region VARCHAR(50));
SELECT vendors.name, vendor_shipments.product_id, vendor_shipments.quantity FROM vendors JOIN vendor_shipments ON vendors.id = vendor_shipments.vendor_id JOIN stores ON vendor_shipments.store_id = stores.id WHERE stores.name = 'Specific Store Name' AND vendor_shipments.shipment_date >= DATE(NOW()) - INTERVAL 6 MONTH;
What is the number of policies issued for each policy type?
CREATE TABLE policyholders (id INT,name VARCHAR(255),state VARCHAR(255),policy_type VARCHAR(255),premium FLOAT); INSERT INTO policyholders (id,name,state,policy_type,premium) VALUES (1,'John Doe','New York','Auto',1200),(2,'Jane Smith','California','Home',2000),(3,'Bob Johnson','California','Auto',1500),(4,'Alice Williams','California','Auto',1800),(5,'Charlie Brown','Texas','Home',2500),(6,'Lucy Van Pelt','Texas','Auto',1000);
SELECT policy_type, COUNT(*) FROM policyholders GROUP BY policy_type;
What is the average ad spend for businesses in the technology sector with more than 100 employees?
CREATE TABLE businesses (id INT,sector VARCHAR(255),employee_count INT); INSERT INTO businesses (id,sector,employee_count) VALUES (1,'technology',150),(2,'finance',50),(3,'retail',200); CREATE TABLE ad_spend (business_id INT,amount DECIMAL(10,2)); INSERT INTO ad_spend (business_id,amount) VALUES (1,5000.00),(1,6000.00),(2,3000.00),(3,4000.00);
SELECT AVG(amount) FROM ad_spend INNER JOIN businesses ON ad_spend.business_id = businesses.id WHERE businesses.sector = 'technology' AND businesses.employee_count > 100;
What is the most common mental health condition among patients aged 18-24?
CREATE TABLE PatientConditions (PatientID INT,Age INT,Condition VARCHAR(50));
SELECT Condition, COUNT(*) FROM PatientConditions WHERE Age BETWEEN 18 AND 24 GROUP BY Condition ORDER BY COUNT(*) DESC LIMIT 1;
What is the average waiting time for public transportation in each city, ordered by the average waiting time in ascending order?
CREATE TABLE Cities (City VARCHAR(255),WaitingTime INT); INSERT INTO Cities (City,WaitingTime) VALUES ('Calgary',10),('Vancouver',15),('Toronto',20),('Montreal',25);
SELECT City, AVG(WaitingTime) AS AvgWaitingTime FROM Cities GROUP BY City ORDER BY AvgWaitingTime ASC;
What was the total revenue for all artworks sold by the 'Impressionist' movement in the year 2010?
CREATE TABLE Artworks (artwork_id INT,movement VARCHAR(255),sale_year INT,revenue DECIMAL(10,2));
SELECT SUM(revenue) FROM Artworks WHERE movement = 'Impressionist' AND sale_year = 2010;
What is the total number of shelters in 'disaster_response' schema and their types?
CREATE TABLE shelters (shelter_id INT,shelter_name VARCHAR(255),location VARCHAR(255),sector VARCHAR(255)); INSERT INTO shelters (shelter_id,shelter_name,location,sector) VALUES (1,'Shelter A','City A','Education');
SELECT SUM(shelter_id) as total_shelters, sector FROM shelters GROUP BY sector;
What is the total number of green buildings in the 'GreenBuildings' table for each city?
CREATE TABLE CityGreenBuildings (city TEXT,building_count INT); INSERT INTO CityGreenBuildings (city,building_count) VALUES ('CityA',200),('CityB',300),('CityC',400);
SELECT city, SUM(building_count) FROM CityGreenBuildings GROUP BY city;
Which safety protocols were implemented in the last quarter of 2021?
CREATE TABLE safety_protocols (id INT,implemented_date DATE); INSERT INTO safety_protocols (id,implemented_date) VALUES (1,'2021-10-01'),(2,'2021-12-15'),(3,'2021-09-30');
SELECT * FROM safety_protocols WHERE implemented_date >= '2021-10-01' AND implemented_date < '2022-01-01'
Who are the painters that created works in the Cubism style?
CREATE TABLE Artists (ArtistID INT,ArtistName VARCHAR(100),Nationality VARCHAR(50)); INSERT INTO Artists (ArtistID,ArtistName,Nationality) VALUES (1,'Pablo Picasso','Spanish'); INSERT INTO Artists (ArtistID,ArtistName,Nationality) VALUES (2,'Georges Braque','French'); INSERT INTO Artists (ArtistID,ArtistName,Nationality) VALUES (3,'Vincent Van Gogh','Dutch'); CREATE TABLE ArtWorks (ArtworkID INT,Title VARCHAR(100),YearCreated INT,Category VARCHAR(50),ArtistID INT); INSERT INTO ArtWorks (ArtworkID,Title,YearCreated,Category,ArtistID) VALUES (1,'Guernica',1937,'Modern Art',1); INSERT INTO ArtWorks (ArtworkID,Title,YearCreated,Category,ArtistID) VALUES (2,'Woman with a Guitar',1913,'Cubism',2); INSERT INTO ArtWorks (ArtworkID,Title,YearCreated,Category,ArtistID) VALUES (3,'Starry Night',1889,'Post-Impressionism',3);
SELECT A.ArtistName FROM Artists A JOIN ArtWorks AW ON A.ArtistID = AW.ArtistID WHERE AW.Category = 'Cubism';
What is the average donation amount per day?
CREATE TABLE Donations (DonationID INT,DonorID INT,DonationAmount DECIMAL(10,2),DonationDate DATE);
SELECT AVG(D.DonationAmount) FROM Donations D;
What is the third most common disability type in 'Texas'?
CREATE TABLE disability_types (disability_id INT,disability_type VARCHAR(50),state VARCHAR(50),frequency INT); INSERT INTO disability_types (disability_id,disability_type,state,frequency) VALUES (1,'Mobility','Texas',3000),(2,'Vision','Texas',2000),(3,'Hearing','Texas',1500);
SELECT disability_type FROM (SELECT disability_type, ROW_NUMBER() OVER (PARTITION BY state ORDER BY frequency DESC) as rn FROM disability_types WHERE state = 'Texas') t WHERE rn = 3;
List safety incidents for VESSEL003
CREATE TABLE vessels (id VARCHAR(20),name VARCHAR(20)); INSERT INTO vessels (id,name) VALUES ('VES001','VESSEL001'),('VES003','VESSEL003'); CREATE TABLE safety_incidents (id INT,vessel_id VARCHAR(20),incident_type VARCHAR(50)); INSERT INTO safety_incidents (id,vessel_id,incident_type) VALUES (1,'VES001','Collision'),(2,'VES003','Fire'),(3,'VES003','Grounding');
SELECT incident_type FROM safety_incidents WHERE vessel_id = 'VES003';
What is the number of deep-sea expeditions conducted by each organization in the last 5 years, grouped by the year the expedition was conducted?
CREATE TABLE deep_sea_expeditions (expedition_id INT,organization VARCHAR(255),year INT); INSERT INTO deep_sea_expeditions (expedition_id,organization,year) VALUES (1,'NOAA',2018),(2,'WHOI',2019),(3,'NASA',2020),(4,'NOAA',2021),(5,'WHOI',2021);
SELECT year, organization, COUNT(*) as expeditions_in_last_5_years FROM deep_sea_expeditions WHERE year >= 2017 GROUP BY year, organization;
What is the average professional development budget per teacher for each gender?
CREATE TABLE teacher_pd (teacher_id INT,department VARCHAR(10),budget DECIMAL(5,2),gender VARCHAR(10)); INSERT INTO teacher_pd (teacher_id,department,budget,gender) VALUES (1,'Math',500.00,'Female'),(1,'English',600.00,'Female'),(2,'Math',550.00,'Male'),(2,'English',650.00,'Male'),(3,'Math',450.00,'Non-binary'),(3,'English',550.00,'Non-binary');
SELECT gender, AVG(budget) as avg_budget FROM teacher_pd GROUP BY gender;
What is the total revenue of movies released in 2020?
CREATE TABLE movies_revenue (movie_id INT,title VARCHAR(255),release_year INT,revenue INT); INSERT INTO movies_revenue (movie_id,title,release_year,revenue) VALUES (1,'Inception',2010,825),(2,'Avatar',2009,2788),(3,'Parasite',2019,258),(4,'The Lion King',2019,1657),(5,'Mulan',2020,60),(6,'Wonder Woman 1984',2020,169);
SELECT SUM(revenue) as total_revenue FROM movies_revenue WHERE release_year = 2020;
Insert a new garment into the garments table with the following details: ID 5, name 'Cotton Shirt', price 20.50, category 'Tops'
CREATE TABLE garments (id INT,name VARCHAR(100),price DECIMAL(5,2),category VARCHAR(50));
INSERT INTO garments (id, name, price, category) VALUES (5, 'Cotton Shirt', 20.50, 'Tops');
What is the average labor cost for manufacturing in Africa?
CREATE TABLE suppliers (id INT,name VARCHAR(255),location VARCHAR(255),sustainable_practices BOOLEAN); CREATE TABLE garments (id INT,name VARCHAR(255),category VARCHAR(255),price DECIMAL(5,2),quantity INT,supplier_id INT); CREATE TABLE manufacturing_costs (id INT,garment_id INT,labor_cost DECIMAL(5,2),material_cost DECIMAL(5,2),manufacturing_time INT); INSERT INTO suppliers (id,name,location,sustainable_practices) VALUES (4,'Supplier D','Africa',true); INSERT INTO garments (id,name,category,price,quantity,supplier_id) VALUES (4,'Garment W','Accessories',15.99,35,4); INSERT INTO manufacturing_costs (id,garment_id,labor_cost,material_cost,manufacturing_time) VALUES (4,4,12.50,11.25,30);
SELECT AVG(manufacturing_costs.labor_cost) FROM manufacturing_costs JOIN suppliers ON manufacturing_costs.supplier_id = suppliers.id WHERE suppliers.location = 'Africa';
How many threat intelligence reports were generated for the Asia-Pacific region in 2020?
CREATE TABLE threat_intel (report_id INT,report_date DATE,region TEXT); INSERT INTO threat_intel (report_id,report_date,region) VALUES (1,'2020-01-01','Asia-Pacific'),(2,'2020-02-15','Europe');
SELECT COUNT(*) FROM threat_intel WHERE region = 'Asia-Pacific' AND report_date >= '2020-01-01' AND report_date < '2021-01-01';
What is the total number of marine protected areas in the Pacific Ocean?
CREATE TABLE marine_protected_areas (area_name VARCHAR(255),ocean VARCHAR(255)); CREATE TABLE oceans (ocean_name VARCHAR(255),ocean_id INTEGER);
SELECT COUNT(area_name) FROM marine_protected_areas WHERE ocean = 'Pacific Ocean';
What is the total budget allocated for all services in 'Florida'?
CREATE TABLE budget (state VARCHAR(20),service VARCHAR(20),amount INT); INSERT INTO budget (state,service,amount) VALUES ('Florida','Education',40000),('Florida','Healthcare',60000),('Florida','Transportation',30000);
SELECT SUM(amount) FROM budget WHERE state = 'Florida';
Identify train routes in the NYC subway system with fares higher than Route A but lower than Route C.
CREATE TABLE train_routes (id INT,route_name VARCHAR(255),fare DECIMAL(5,2)); INSERT INTO train_routes (id,route_name,fare) VALUES (1,'Route A',2.75),(2,'Route B',3.50),(3,'Route C',2.25);
SELECT route_name, fare FROM train_routes WHERE fare > 2.75 AND fare < 2.25;
Find the first and last sale dates for each garment, partitioned by category and ordered by date.
CREATE TABLE sales (garment VARCHAR(50),category VARCHAR(50),sale_date DATE); INSERT INTO sales (garment,category,sale_date) VALUES ('Shirt','Tops','2021-01-05'),('Pants','Bottoms','2021-01-05'),('Dress','Tops','2021-01-10'),('Shirt','Tops','2022-01-05'),('Pants','Bottoms','2022-01-05'),('Dress','Tops','2022-01-10');
SELECT garment, category, MIN(sale_date) OVER (PARTITION BY garment) as first_sale_date, MAX(sale_date) OVER (PARTITION BY garment) as last_sale_date FROM sales;
What is the maximum fare for a single trip on the 'montreal' schema's metro system?
CREATE TABLE montreal.metro_fares (id INT,trip_type VARCHAR,fare DECIMAL); INSERT INTO montreal.metro_fares (id,trip_type,fare) VALUES (1,'single',3.5),(2,'round',6.5),(3,'weekly',25);
SELECT MAX(fare) FROM montreal.metro_fares WHERE trip_type = 'single';
Update 'vehicle_type' to 'EV' for records in the 'charging_stations' table where 'station_type' is 'fast_charger'
CREATE TABLE charging_stations (id INT,station_name VARCHAR(255),station_type VARCHAR(255),location VARCHAR(255));
UPDATE charging_stations SET vehicle_type = 'EV' WHERE station_type = 'fast_charger';
What is the population of the Beluga Whale in the Arctic?
CREATE TABLE Species (id INT PRIMARY KEY,species_name VARCHAR(50),population INT,region VARCHAR(50)); INSERT INTO Species (id,species_name,population,region) VALUES (1,'Polar Bear',25000,'Arctic'),(2,'Beluga Whale',15000,'Arctic');
SELECT species_name, population FROM Species WHERE species_name = 'Beluga Whale' AND region = 'Arctic';
How many users are there in each country, and what is the total number of posts for users in each country who joined in 2021?
CREATE TABLE users (id INT,name VARCHAR(50),location VARCHAR(50),join_date DATE); CREATE TABLE posts (id INT,user_id INT,post_date DATE); INSERT INTO users (id,name,location,join_date) VALUES (1,'Alice','Canada','2021-01-01'); INSERT INTO users (id,name,location,join_date) VALUES (2,'Bob','USA','2020-01-01'); INSERT INTO posts (id,user_id,post_date) VALUES (1,1,'2021-01-01'); INSERT INTO posts (id,user_id,post_date) VALUES (2,1,'2021-01-02'); INSERT INTO posts (id,user_id,post_date) VALUES (3,2,'2021-01-03');
SELECT u.location, COUNT(DISTINCT u.id) as user_count, COUNT(p.id) as post_count FROM users u JOIN posts p ON u.id = p.user_id WHERE u.join_date >= '2021-01-01' GROUP BY u.location;
What is the maximum funding amount received by companies founded by Latinx entrepreneurs?
CREATE TABLE company (id INT,name TEXT,founder_race TEXT,funding_amount INT); INSERT INTO company (id,name,founder_race,funding_amount) VALUES (1,'Kappa Inc','Latinx',1500000); INSERT INTO company (id,name,founder_race,funding_amount) VALUES (2,'Lambda Corp','Asian',2000000); INSERT INTO company (id,name,founder_race,funding_amount) VALUES (3,'Mu Inc','Latinx',1200000); INSERT INTO company (id,name,founder_race,funding_amount) VALUES (4,'Nu Corp','Caucasian',2500000);
SELECT MAX(funding_amount) FROM company WHERE founder_race = 'Latinx';
What is the average risk score of vulnerabilities for each product in the last month?
CREATE TABLE product_vulnerabilities (product_id INT,vulnerability_id INT,risk_score INT,detection_date DATE); INSERT INTO product_vulnerabilities (product_id,vulnerability_id,risk_score,detection_date) VALUES (1,1001,7,'2022-01-05'); INSERT INTO product_vulnerabilities (product_id,vulnerability_id,risk_score,detection_date) VALUES (1,1002,5,'2022-01-10'); INSERT INTO product_vulnerabilities (product_id,vulnerability_id,risk_score,detection_date) VALUES (2,1003,8,'2022-01-15');
SELECT product_id, AVG(risk_score) as avg_risk_score FROM product_vulnerabilities WHERE detection_date >= DATEADD(month, -1, CURRENT_DATE) GROUP BY product_id ORDER BY avg_risk_score DESC;
What is the total cost of mental health treatments for patients with depression?
CREATE TABLE MentalHealthParity (id INT,patientID INT,condition VARCHAR(50),treatment VARCHAR(50),cost DECIMAL(5,2)); INSERT INTO MentalHealthParity (id,patientID,condition,treatment,cost) VALUES (1,1001,'Anxiety','Counseling',80.00),(2,1002,'Depression','Medication',100.00);
SELECT patientID, SUM(cost) as 'TotalCost' FROM MentalHealthParity WHERE condition = 'Depression';
How many bridges were built in the last 5 years in the state of California?
CREATE TABLE Bridges (id INT,name TEXT,state TEXT,constructionDate DATE);
SELECT COUNT(*) FROM Bridges WHERE state = 'California' AND constructionDate >= DATE_SUB(CURRENT_DATE, INTERVAL 5 YEAR);
What is the most common mental health condition among patients from New York?
CREATE TABLE patients (id INT,name TEXT,age INT,condition TEXT,state TEXT); INSERT INTO patients (id,name,age,condition,state) VALUES (1,'John Doe',35,'Depression','NY'),(2,'Jane Smith',40,'Anxiety','NY');
SELECT condition, COUNT(*) AS count FROM patients WHERE state = 'NY' GROUP BY condition ORDER BY count DESC LIMIT 1;
Insert a new record into the 'quality_control' table with id 201, 'test_type' 'Visual Inspection', 'test_result' 'Passed', 'defect_count' 0, and 'shift' 'Morning'
CREATE TABLE quality_control (id INT,test_type VARCHAR(255),test_result VARCHAR(255),defect_count INT,shift VARCHAR(255));
INSERT INTO quality_control (id, test_type, test_result, defect_count, shift) VALUES (201, 'Visual Inspection', 'Passed', 0, 'Morning');
What is the average age of athletes who played in the FIFA World Cup 2018, grouped by their position?
CREATE TABLE athletes (id INT,name VARCHAR(100),position VARCHAR(50),age INT,world_cup_2018 BOOLEAN);
SELECT position, AVG(age) as avg_age FROM athletes WHERE world_cup_2018 = true GROUP BY position;
Find the bottom 2 cuisine types with the lowest average calories per dish, excluding the 'Salad' type.
CREATE TABLE dishes (dish_id INT,name VARCHAR(255),calories INT,cuisine_type VARCHAR(255)); INSERT INTO dishes (dish_id,name,calories,cuisine_type) VALUES (1,'Pizza',300,'Italian'),(2,'Pasta',400,'Italian'),(3,'Salad',200,'Salad'),(4,'Burger',500,'American'),(5,'Sushi',250,'Japanese'),(6,'Curry',350,'Indian');
SELECT cuisine_type, AVG(calories) AS avg_calories FROM dishes WHERE cuisine_type != 'Salad' GROUP BY cuisine_type ORDER BY avg_calories LIMIT 2;
What is the average transaction value for socially responsible loans in Q2 2022?
CREATE TABLE socially_responsible_loans (id INT,value DECIMAL(10,2),date DATE); INSERT INTO socially_responsible_loans (id,value,date) VALUES (1,5000,'2022-04-01'); INSERT INTO socially_responsible_loans (id,value,date) VALUES (2,7000,'2022-04-15');
SELECT AVG(value) FROM socially_responsible_loans WHERE date BETWEEN '2022-04-01' AND '2022-06-30';
What is the most expensive product in the Organic segment?
CREATE TABLE products (product_id INT,segment VARCHAR(20),price DECIMAL(5,2)); INSERT INTO products (product_id,segment,price) VALUES (1,'Natural',15.99),(2,'Organic',20.99),(3,'Natural',12.49);
SELECT segment, MAX(price) FROM products WHERE segment = 'Organic' GROUP BY segment;
Show the number of bus and train stations in each borough or district.
CREATE TABLE BusStations (id INT,borough VARCHAR(255),station_name VARCHAR(255)); CREATE TABLE TrainStations (id INT,district VARCHAR(255),station_name VARCHAR(255));
SELECT 'Bus' as transportation, borough, COUNT(*) as station_count FROM BusStations GROUP BY borough UNION ALL SELECT 'Train', district, COUNT(*) FROM TrainStations GROUP BY district;
What is the total waste generation in gram for each material type in the first quarter of 2021, grouped by material type, and only showing those with a total generation greater than 5000 grams?
CREATE TABLE WasteData (WasteID INT,Material VARCHAR(255),Quantity DECIMAL(10,2),GenerationDate DATE); INSERT INTO WasteData (WasteID,Material,Quantity,GenerationDate) VALUES (1,'Plastic',1200,'2021-01-01'),(2,'Glass',3000,'2021-01-03'),(3,'Paper',4500,'2021-01-05');
SELECT Material, SUM(Quantity) AS TotalWaste FROM WasteData WHERE GenerationDate BETWEEN '2021-01-01' AND '2021-03-31' GROUP BY Material HAVING SUM(Quantity) > 5000;
What is the representation percentage of each gender and minority group per company?
CREATE TABLE Company (id INT,name VARCHAR(50),industry VARCHAR(50),founding_year INT); INSERT INTO Company (id,name,industry,founding_year) VALUES (1,'Acme Inc','Tech',2010); INSERT INTO Company (id,name,industry,founding_year) VALUES (2,'Bravo Corp','Finance',2005); CREATE TABLE Diversity (id INT,company_id INT,gender VARCHAR(10),minority VARCHAR(50),percentage_representation DECIMAL(4,2)); INSERT INTO Diversity (id,company_id,gender,minority,percentage_representation) VALUES (1,1,'Male','Non-minority',0.65); INSERT INTO Diversity (id,company_id,gender,minority,percentage_representation) VALUES (2,1,'Female','Minority',0.35);
SELECT company_id, gender, minority, SUM(percentage_representation) as total_percentage FROM Diversity GROUP BY company_id, gender, minority;
What percentage of companies were founded by underrepresented racial or ethnic groups in Canada?
CREATE TABLE company (id INT,name TEXT,country TEXT,founding_date DATE,founder_race TEXT); INSERT INTO company (id,name,country,founding_date,founder_race) VALUES (1,'Delta Startups','Canada','2018-01-01','South Asian'); INSERT INTO company (id,name,country,founding_date,founder_race) VALUES (2,'Epsilon Enterprises','Canada','2020-01-01','Caucasian');
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM company)) FROM company WHERE founder_race IN ('Black', 'Hispanic', 'Indigenous', 'South Asian', 'Middle Eastern') AND country = 'Canada';
What is the minimum serving size for fair-trade coffee?
CREATE TABLE Beverages (id INT,is_fair_trade BOOLEAN,category VARCHAR(20),serving_size INT); INSERT INTO Beverages (id,is_fair_trade,category,serving_size) VALUES (1,true,'coffee',8),(2,false,'coffee',12),(3,true,'tea',16);
SELECT MIN(serving_size) FROM Beverages WHERE is_fair_trade = true AND category = 'coffee';
List all customers and their transaction amounts who have made a transaction over 100 in Mexico.
CREATE TABLE transactions (customer_id INT,transaction_amount DECIMAL(10,2),country VARCHAR(50)); INSERT INTO transactions (customer_id,transaction_amount,country) VALUES (1,120.50,'Mexico'),(2,75.30,'Mexico'),(3,50.00,'Mexico'),(4,150.00,'Mexico');
SELECT customer_id, transaction_amount FROM transactions WHERE country = 'Mexico' AND transaction_amount > 100;
What is the total donation amount per donor type?
CREATE TABLE donor_type (id INT,type VARCHAR(20)); INSERT INTO donor_type (id,type) VALUES (1,'Individual'),(2,'Corporate'),(3,'Foundation'); CREATE TABLE donations (id INT,donor_id INT,amount DECIMAL(10,2));
SELECT dt.type, SUM(d.amount) as total_donation FROM donations d JOIN donor_type dt ON d.donor_id = dt.id GROUP BY dt.type;
Delete the 'Red' line's data from the 'fares' and 'routes' tables.
CREATE TABLE routes (line VARCHAR(10),station VARCHAR(20)); INSERT INTO routes (line,station) VALUES ('Red','Station X'),('Red','Station Y'),('Red','Station Z'); CREATE TABLE fares (route VARCHAR(10),revenue DECIMAL(10,2)); INSERT INTO fares (route,revenue) VALUES ('Red',2000),('Red',2500),('Red',3000);
DELETE FROM routes WHERE line = 'Red'; DELETE FROM fares WHERE route IN (SELECT line FROM routes WHERE line = 'Red');
What is the number of cases handled by each community mediation center, ordered by the total number of cases, descending?
CREATE TABLE CommunityMediation (CenterID INT,CenterName VARCHAR(50),CaseID INT); INSERT INTO CommunityMediation (CenterID,CenterName,CaseID) VALUES (1,'Boston Community Mediation',100),(2,'Chicago Community Justice Center',150),(3,'Seattle Neighborhood Mediation',120),(4,'Denver Community Mediation',80);
SELECT CenterName, COUNT(*) AS TotalCases FROM CommunityMediation GROUP BY CenterName ORDER BY TotalCases DESC;
What is the total production for each country in the last year?
CREATE TABLE Production (ProductionID INT,WellID INT,ProductionDate DATE,ProductionRate FLOAT,Country VARCHAR(50)); INSERT INTO Production (ProductionID,WellID,ProductionDate,ProductionRate,Country) VALUES (1,1,'2021-01-01',500,'USA'),(2,2,'2021-01-15',600,'Canada'),(3,3,'2022-02-01',700,'Mexico');
SELECT Country, SUM(ProductionRate) AS TotalProduction FROM Production WHERE ProductionDate >= DATEADD(year, -1, GETDATE()) GROUP BY Country;
Find the number of members who have a higher heart rate during cycling than during yoga.
CREATE TABLE YogaHeartRate (MemberID INT,YogaHeartRate INT); CREATE TABLE CyclingHeartRate (MemberID INT,CyclingHeartRate INT); INSERT INTO YogaHeartRate (MemberID) VALUES (1),(2); INSERT INTO CyclingHeartRate (MemberID) VALUES (1,60),(2,50);
SELECT COUNT(*) FROM (SELECT MemberID, CyclingHeartRate, YogaHeartRate FROM CyclingHeartRate JOIN YogaHeartRate ON CyclingHeartRate.MemberID = YogaHeartRate.MemberID) WHERE CyclingHeartRate > YogaHeartRate;
Insert a new record of a new citizen in the 'Citizens' table
CREATE TABLE Citizens (citizen_id INT,name VARCHAR(50),age INT,city VARCHAR(50));
INSERT INTO Citizens (citizen_id, name, age, city) VALUES (1, 'Alex Garcia', 34, 'Los Angeles');
How many marine species were observed in the Southern ocean with a depth greater than 2000 meters?
CREATE TABLE marine_species (id INT,species_name VARCHAR(255),ocean VARCHAR(255),depth INT); INSERT INTO marine_species (id,species_name,ocean,depth) VALUES (1,'Southern Ocean Squid','Southern',3000); INSERT INTO marine_species (id,species_name,ocean,depth) VALUES (2,'Southern Ocean Crab','Southern',2500);
SELECT COUNT(*) FROM marine_species WHERE ocean = 'Southern' AND depth > 2000;
List community education programs in Indigenous communities and the number of participants
CREATE TABLE education_programs (id INT,program_name VARCHAR(255),community_type VARCHAR(255),num_participants INT); INSERT INTO education_programs (id,program_name,community_type,num_participants) VALUES (1,'Wildlife Awareness','Indigenous',500),(2,'Conservation Workshops','Urban',300),(3,'Nature Camps','Rural',400);
SELECT program_name, community_type, num_participants FROM education_programs WHERE community_type = 'Indigenous';
What is the distribution of gluten-free product sales by region?
CREATE TABLE sales (id INT,region TEXT,product_id INT,is_gluten_free BOOLEAN,revenue INT); INSERT INTO sales (id,region,product_id,is_gluten_free,revenue) VALUES (1,'Northeast',1,true,200),(2,'Northeast',2,false,150),(3,'Southeast',3,true,250),(4,'Southeast',4,false,180),(5,'Midwest',5,true,180),(6,'Midwest',6,false,120),(7,'Southwest',7,true,300),(8,'Southwest',8,false,200);
SELECT region, is_gluten_free, AVG(revenue) FROM sales GROUP BY region, is_gluten_free;
What is the total number of security incidents caused by each threat actor in the JP region?
CREATE TABLE security_incidents (id INT,incident_date DATE,region VARCHAR(255),incident_type VARCHAR(255),threat_actor VARCHAR(255)); INSERT INTO security_incidents (id,incident_date,region,incident_type,threat_actor) VALUES (1,'2022-01-05','JP','Phishing','Threat Actor 1'),(2,'2022-02-10','JP','Malware','Threat Actor 2'),(3,'2022-03-15','JP','SQL Injection','Threat Actor 1'),(4,'2022-04-20','JP','Cross-site Scripting','Threat Actor 3'),(5,'2022-05-25','JP','DoS/DDoS','Threat Actor 2');
SELECT threat_actor, COUNT(*) as incidents_per_threat_actor FROM security_incidents WHERE region = 'JP' GROUP BY threat_actor;
What is the quantity of item 'D01' in all warehouses?
CREATE TABLE inventory (item_code varchar(5),warehouse_id varchar(5),quantity int); INSERT INTO inventory (item_code,warehouse_id,quantity) VALUES ('D01','LHR',800),('D01','MAD',900);
SELECT SUM(quantity) FROM inventory WHERE item_code = 'D01';
Retrieve all records from 'dishes' table with a calorie count less than 400
CREATE TABLE dishes (id INT,name TEXT,vegan BOOLEAN,calories INT); INSERT INTO dishes (id,name,vegan,calories) VALUES (1,'Quinoa Salad',TRUE,350),(2,'Pizza Margherita',FALSE,500);
SELECT * FROM dishes WHERE calories < 400;
What is the maximum depth reached by a manned submersible in the Indian Ocean?
CREATE TABLE submersible_dives (ocean VARCHAR(255),depth FLOAT); INSERT INTO submersible_dives (ocean,depth) VALUES ('Indian Ocean',7020.0),('Atlantic Ocean',10928.0);
SELECT MAX(depth) FROM submersible_dives WHERE ocean = 'Indian Ocean';
Update the 'Members' table to add a new column 'MembershipStartDate' and set the value as the 'JoinDate'
CREATE TABLE Members (MemberID INT,MemberName VARCHAR(50),JoinDate DATETIME);
ALTER TABLE Members ADD MembershipStartDate DATETIME; UPDATE Members SET MembershipStartDate = JoinDate;
What is the average number of volunteer hours per volunteer in the South?
CREATE TABLE volunteer_hours (volunteer_id INT,vol_name TEXT,vol_region TEXT,hours_served INT); INSERT INTO volunteer_hours (volunteer_id,vol_name,vol_region,hours_served) VALUES (1,'John Doe','South',50),(2,'Jane Smith','South',75),(3,'Mary Johnson','South',100);
SELECT AVG(hours_served) as avg_hours_per_volunteer FROM volunteer_hours WHERE vol_region = 'South';
What is the total donation amount and the number of donations for each donor in the 'donors' table, sorted by total donation amount in descending order?
CREATE TABLE donors (donor_id INT,donor_name TEXT,total_donations DECIMAL(10,2),num_donations INT);
SELECT donor_id, donor_name, total_donations, num_donations FROM donors ORDER BY total_donations DESC;