instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
Which sustainable materials are used in the production of clothing in Africa?
|
CREATE TABLE clothing_materials (country TEXT,material TEXT); INSERT INTO clothing_materials (country,material) VALUES ('Africa','organic cotton'),('Africa','recycled polyester'),('Africa','hemp'),('Africa','tencel');
|
SELECT DISTINCT material FROM clothing_materials WHERE country = 'Africa';
|
Delete users who haven't posted in the last 6 months from the "users" table
|
CREATE TABLE users (id INT,username VARCHAR(255),last_post_date DATE);
|
DELETE FROM users WHERE last_post_date < DATE_SUB(CURDATE(), INTERVAL 6 MONTH);
|
Which countries are the top 3 sources of sustainable textiles?
|
CREATE TABLE Textile_Sources (Source_ID INT,Source_Country TEXT,Sustainable BOOLEAN,Quantity INT); INSERT INTO Textile_Sources (Source_ID,Source_Country,Sustainable,Quantity) VALUES (1,'India',true,1000),(2,'Bangladesh',false,800),(3,'China',true,1200),(4,'Vietnam',false,900),(5,'Italy',true,1100),(6,'USA',false,700);
|
SELECT Source_Country FROM Textile_Sources WHERE Sustainable = true ORDER BY Quantity DESC LIMIT 3;
|
Which size-inclusive garments have the highest revenue?
|
CREATE TABLE garments (id INT,size TEXT,revenue DECIMAL); INSERT INTO garments (id,size,revenue) VALUES (1,'XS',200),(2,'S',300),(3,'M',500),(4,'L',700),(5,'XL',800),(6,'XXL',900); CREATE TABLE sizes (id INT,size TEXT,description TEXT); INSERT INTO sizes (id,size,description) VALUES (1,'XS','Extra Small'),(2,'S','Small'),(3,'M','Medium'),(4,'L','Large'),(5,'XL','Extra Large'),(6,'XXL','Extra Extra Large');
|
SELECT g.size, SUM(g.revenue) as total_revenue FROM garments g JOIN sizes s ON g.size = s.size GROUP BY g.size ORDER BY total_revenue DESC LIMIT 1;
|
How many socially responsible lending loans have been issued by region?
|
CREATE TABLE socially_responsible_lending(id INT,loan_number INT,region VARCHAR(50)); INSERT INTO socially_responsible_lending VALUES (1,1001,'North'); INSERT INTO socially_responsible_lending VALUES (2,1002,'South'); INSERT INTO socially_responsible_lending VALUES (3,1003,'East'); INSERT INTO socially_responsible_lending VALUES (4,1004,'West');
|
SELECT region, COUNT(loan_number) FROM socially_responsible_lending GROUP BY region;
|
What is the average financial wellbeing score of customers aged 35-50 for the year 2020?
|
CREATE TABLE customers (customer_id INT,age INT,wellbeing_score INT,registration_date DATE);
|
SELECT AVG(wellbeing_score) FROM customers WHERE age BETWEEN 35 AND 50 AND EXTRACT(YEAR FROM registration_date) = 2020;
|
What is the total weight of seafood imported from Asia in the past month?
|
CREATE TABLE Customs (id INT,importId INT,item VARCHAR(50),weight FLOAT,region VARCHAR(50),importDate DATE);
|
SELECT SUM(weight) FROM Customs WHERE item LIKE '%seafood%' AND region = 'Asia' AND importDate >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH);
|
Delete all shipments from 'ABC' warehouse
|
CREATE TABLE warehouse (id INT PRIMARY KEY,name VARCHAR(255)); INSERT INTO warehouse (id,name) VALUES (1,'ABC'),(2,'DEF'); CREATE TABLE shipments (id INT PRIMARY KEY,warehouse_id INT,FOREIGN KEY (warehouse_id) REFERENCES warehouse(id)); INSERT INTO shipments (id,warehouse_id) VALUES (1,1),(2,2);
|
DELETE FROM shipments WHERE warehouse_id = (SELECT id FROM warehouse WHERE name = 'ABC');
|
Which warehouse locations have less than 50 items in stock for a specific item?
|
CREATE TABLE warehouse_data (warehouse_id INT,item_name VARCHAR(100),quantity INT,warehouse_location VARCHAR(50)); INSERT INTO warehouse_data (warehouse_id,item_name,quantity,warehouse_location) VALUES (1,'Widget',30,'California'),(2,'Gizmo',50,'New York'),(3,'Doodad',75,'California'),(4,'Thingamajig',120,'Texas'),(5,'Whatzit',150,'California'),(6,'Widget',40,'New York');
|
SELECT warehouse_location FROM warehouse_data WHERE item_name = 'Widget' GROUP BY warehouse_location HAVING SUM(quantity) < 50;
|
What is the average CO2 emission reduction of green building projects in California?
|
CREATE TABLE green_building_projects (id INT,project_name VARCHAR(50),city VARCHAR(50),state VARCHAR(50),country VARCHAR(50),co2_reduction FLOAT); INSERT INTO green_building_projects (id,project_name,city,state,country,co2_reduction) VALUES (1,'California Green Building','Los Angeles','CA','USA',15.4);
|
SELECT AVG(co2_reduction) FROM green_building_projects WHERE state = 'CA';
|
How many community health workers are employed in each region?
|
CREATE TABLE RegionHealthWorkers (Region TEXT,HealthWorkerCount INT); INSERT INTO RegionHealthWorkers (Region,HealthWorkerCount) VALUES ('Northeast',500),('South',700),('Midwest',600);
|
SELECT Region, HealthWorkerCount FROM RegionHealthWorkers;
|
List the names and departments of all mental health parity officers in the mental_health schema.
|
CREATE TABLE mental_health_parity_officers (officer_id INT,name VARCHAR(50),department VARCHAR(50)); INSERT INTO mental_health_parity_officers (officer_id,name,department) VALUES (1,'Alice Johnson','Compliance'); INSERT INTO mental_health_parity_officers (officer_id,name,department) VALUES (2,'Bob Brown','Legal');
|
SELECT name, department FROM mental_health.mental_health_parity_officers;
|
What is the minimum rating of eco-friendly hotels in Spain?
|
CREATE TABLE eco_hotels (hotel_id INT,hotel_name TEXT,country TEXT,rating FLOAT); INSERT INTO eco_hotels (hotel_id,hotel_name,country,rating) VALUES (1,'Green Hotel','Spain',4.1),(2,'Eco Lodge','Spain',4.7);
|
SELECT MIN(rating) FROM eco_hotels WHERE country = 'Spain';
|
What is the percentage of hotels in the 'EMEA' region that adopted AI technology in 2022?
|
CREATE TABLE ai_adoption (id INT,hotel_id INT,region TEXT,year INT,ai_adoption INT);
|
SELECT region, (SUM(ai_adoption) * 100.0 / COUNT(*)) as adoption_percentage FROM ai_adoption WHERE region = 'EMEA' AND year = 2022 GROUP BY region;
|
Delete the record with id 3 from the "animals" table
|
CREATE TABLE animals (id INT PRIMARY KEY,name VARCHAR(100),species VARCHAR(100),population INT);
|
WITH del AS (DELETE FROM animals WHERE id = 3 RETURNING id) SELECT id FROM del;
|
How many patients with anxiety have received medication in the last 3 months in the LGBTQ+ community?
|
CREATE TABLE patients (patient_id INT,age INT,gender VARCHAR(10),condition VARCHAR(255),ethnicity VARCHAR(255)); CREATE TABLE therapy_sessions (session_id INT,patient_id INT,therapist_id INT,session_date DATE,medication BOOLEAN);
|
SELECT COUNT(*) FROM patients JOIN therapy_sessions ON patients.patient_id = therapy_sessions.patient_id WHERE patients.condition = 'anxiety' AND patients.ethnicity = 'LGBTQ+' AND therapy_sessions.session_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH) AND therapy_sessions.medication = TRUE;
|
What is the minimum elevation of all bridges in the database?
|
CREATE TABLE Bridges (id INT,name VARCHAR(100),elevation FLOAT); INSERT INTO Bridges (id,name,elevation) VALUES (1,'Golden Gate Bridge',220),(2,'Bay Bridge',132),(3,'Chesapeake Bay Bridge',67);
|
SELECT MIN(elevation) FROM Bridges;
|
What is the average time to process a case for each case type in the justice_database?
|
CREATE TABLE case_processing (id INT,case_id INT,case_type VARCHAR(255),processing_time INTEGER); INSERT INTO case_processing (id,case_id,case_type,processing_time) VALUES (1,1,'Felony',60),(2,2,'Misdemeanor',30);
|
SELECT case_type, AVG(processing_time) FROM case_processing GROUP BY case_type;
|
Update menu item records for 'Chicken Sandwich' to increase the price by $0.75
|
CREATE TABLE menu_items (menu_id INT PRIMARY KEY,item_name VARCHAR(255),price DECIMAL(5,2));
|
UPDATE menu_items SET price = price + 0.75 WHERE item_name = 'Chicken Sandwich';
|
Insert new records into the Employee table with the following data: EmployeeID 3, FirstName 'Mike', LastName 'Smith', Department 'Environment'.
|
CREATE TABLE Employee (EmployeeID INT,FirstName VARCHAR(50),LastName VARCHAR(50),Department VARCHAR(50));
|
INSERT INTO Employee (EmployeeID, FirstName, LastName, Department) VALUES (3, 'Mike', 'Smith', 'Environment');
|
What is the total number of accidents for each company, in the last 6 months?
|
CREATE TABLE company (id INT,name TEXT); CREATE TABLE accident (id INT,company_id INT,date DATE);
|
SELECT company.name, COUNT(accident.id) as total_accidents FROM company INNER JOIN accident ON company.id = accident.company_id WHERE accident.date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH) AND CURRENT_DATE GROUP BY company.name;
|
Delete all music genres with less than 10 artists.
|
CREATE TABLE music_genres(genre_id INT,name VARCHAR(50)); CREATE TABLE artist_activity(artist_id INT,genre_id INT,streams INT); CREATE TABLE artists(artist_id INT,name VARCHAR(50),genre_id INT);
|
DELETE FROM music_genres WHERE genre_id NOT IN (SELECT genre_id FROM artists GROUP BY genre_id HAVING COUNT(DISTINCT artist_id) >= 10);
|
Update records in the 'Volunteers' table where the volunteer's skill level is 'Beginner' and change it to 'Intermediate'
|
CREATE TABLE Volunteers (id INT PRIMARY KEY,volunteer_name VARCHAR(255),skill_level VARCHAR(255),last_volunteered DATE);
|
UPDATE Volunteers SET skill_level = 'Intermediate' WHERE skill_level = 'Beginner';
|
What is the average length of all underwater cables in the Indian Ocean, and how many cables are there?
|
CREATE TABLE UNDERWATER_CABLES (NAME TEXT,LENGTH NUMERIC,REGION TEXT); INSERT INTO UNDERWATER_CABLES (NAME,LENGTH,REGION) VALUES ('SAEx1',12000,'Indian Ocean'),('EASSy',10000,'Indian Ocean'),('SEA-ME-WE 3',39000,'Indian Ocean'),('EIG',13000,'Indian Ocean'),('TEA- IN',15000,'Indian Ocean');
|
SELECT AVG(LENGTH) AS AVG_LENGTH, COUNT(*) AS NUM_CABLES FROM UNDERWATER_CABLES WHERE REGION = 'Indian Ocean';
|
Identify the top 5 property managers with the highest number of co-owned properties in Vancouver.
|
CREATE TABLE property_managers (id INT,name VARCHAR(30),num_properties INT); CREATE TABLE co_owned_properties (manager_id INT,property_id INT); INSERT INTO property_managers (id,name,num_properties) VALUES (1,'Smith Property Management',25),(2,'Jones Management',30),(3,'Green Properties',35),(4,'Eco Management',20),(5,'Blue Sky Management',40),(6,'ABC Properties',15); INSERT INTO co_owned_properties (manager_id,property_id) VALUES (1,1),(1,2),(2,3),(2,4),(2,5),(3,6),(3,7),(3,8),(4,9),(4,10),(5,11),(5,12),(5,13),(5,14);
|
SELECT pm.name, COUNT(cop.manager_id) as num_co_owned FROM property_managers pm INNER JOIN co_owned_properties cop ON pm.id = cop.manager_id GROUP BY pm.name ORDER BY num_co_owned DESC LIMIT 5;
|
List all property owners in Los Angeles who have not adopted inclusive housing policies.
|
CREATE TABLE Owners (OwnerID int,PropertyID int,City varchar(20)); CREATE TABLE Properties (PropertyID int,City varchar(20),Inclusive varchar(5)); INSERT INTO Owners (OwnerID,PropertyID,City) VALUES (1,1,'Los Angeles'); INSERT INTO Properties (PropertyID,City,Inclusive) VALUES (1,'Los Angeles','No'); INSERT INTO Owners (OwnerID,PropertyID,City) VALUES (2,2,'Los Angeles'); INSERT INTO Properties (PropertyID,City,Inclusive) VALUES (2,'Los Angeles','Yes');
|
SELECT Owners.Name, Properties.City FROM Owners INNER JOIN Properties ON Owners.PropertyID = Properties.PropertyID WHERE Properties.City = 'Los Angeles' AND Properties.Inclusive = 'No';
|
Show the number of menu items for each restaurant category
|
CREATE TABLE vendors (id INT,name VARCHAR(50),type VARCHAR(50)); CREATE TABLE menus (id INT,vendor_id INT,category VARCHAR(50)); CREATE TABLE menu_items (id INT,name VARCHAR(50),category VARCHAR(50),price DECIMAL(5,2)); INSERT INTO vendors (id,name,type) VALUES (1,'Sushi Bar','Restaurant'),(2,'Bakery','Restaurant'),(3,'Grocery','Market'); INSERT INTO menus (id,vendor_id,category) VALUES (101,1,'Sushi'),(102,1,'Japanese'),(103,2,'Bread'),(104,2,'Pastries'),(105,3,'Organic'),(106,3,'Vegan'); INSERT INTO menu_items (id,name,category) VALUES (1001,'California Roll','Sushi'),(1002,'Tuna Roll','Sushi'),(1003,'Tiramisu','Pastries'),(1004,'Croissant','Bread'),(1005,'Kale Salad','Organic'),(1006,'Tofu Burger','Vegan');
|
SELECT menus.category, COUNT(menu_items.id) AS menu_items_count FROM menus JOIN menu_items ON menus.category = menu_items.category GROUP BY menus.category;
|
What is the total number of successful space missions for each space agency?
|
CREATE SCHEMA space; USE space; CREATE TABLE agency (name VARCHAR(50),country VARCHAR(50),missions INT,successes INT); INSERT INTO agency (name,country,missions,successes) VALUES ('ESA','Europe',120,105),('NASA','USA',230,210),('ROSCOSMOS','Russia',150,130);
|
SELECT s.name, SUM(s.successes) FROM space.agency s GROUP BY s.name;
|
List all policies, claim types, and claim amounts for policyholders living in 'California'?
|
CREATE TABLE Policyholders (PolicyholderID INT,State VARCHAR(20)); INSERT INTO Policyholders (PolicyholderID,State) VALUES (1,'California'),(2,'New York'),(3,'Florida'); CREATE TABLE Claims (ClaimID INT,PolicyholderID INT,ClaimType VARCHAR(20),ClaimAmount INT); INSERT INTO Claims (ClaimID,PolicyholderID,ClaimType,ClaimAmount) VALUES (1,1,'Theft',5000),(2,1,'Fire',20000),(3,2,'Accident',7000);
|
SELECT Policyholders.State, Claims.ClaimType, Claims.ClaimAmount FROM Policyholders INNER JOIN Claims ON Policyholders.PolicyholderID = Claims.PolicyholderID WHERE Policyholders.State = 'California';
|
List the policy types and total claim amount for policyholders from Ontario with an auto or life insurance policy.
|
CREATE TABLE Policyholder (PolicyholderID INT,State VARCHAR(255),PolicyType VARCHAR(255),ClaimAmount DECIMAL(10,2)); INSERT INTO Policyholder VALUES (1,'ON','Auto',5000),(2,'NY','Home',7000),(3,'NJ','Auto',8000),(4,'CA','Life',6000),(5,'ON','Life',9000);
|
SELECT PolicyType, SUM(ClaimAmount) as TotalClaimAmount FROM Policyholder WHERE State = 'ON' AND PolicyType IN ('Auto', 'Life') GROUP BY PolicyType;
|
Modify 'vehicle_specs' table to add 2 new records
|
CREATE TABLE vehicle_specs (id INT PRIMARY KEY,vehicle_type VARCHAR(255),engine_type VARCHAR(255));
|
INSERT INTO vehicle_specs (id, vehicle_type, engine_type) VALUES (3, 'Electric Sedan', 'Electric Motor'), (4, 'Hybrid SUV', 'Hybrid Engine');
|
What is the average recycling rate and the number of circular economy initiatives for each location and material, for the second quarter of 2022?
|
CREATE TABLE RecyclingRates (Date date,Location text,Material text,Rate real);CREATE TABLE CircularEconomyInitiatives (Location text,Initiative text,StartDate date);
|
SELECT rr.Location, rr.Material, AVG(rr.Rate) as AvgRecyclingRate, COUNT(DISTINCT cei.Initiative) as NumberOfInitiatives FROM RecyclingRates rr LEFT JOIN CircularEconomyInitiatives cei ON rr.Location = cei.Location WHERE rr.Date >= '2022-04-01' AND rr.Date < '2022-07-01' GROUP BY rr.Location, rr.Material;
|
What is the total water usage by state in the US?
|
CREATE TABLE states (state_name VARCHAR(50),state_abbr VARCHAR(5),population INT); INSERT INTO states (state_name,state_abbr,population) VALUES ('California','CA',39512223),('Texas','TX',29528404),('New York','NY',19453561); CREATE TABLE water_usage (state_abbr VARCHAR(5),usage_gallons INT); INSERT INTO water_usage (state_abbr,usage_gallons) VALUES ('CA',678345200),('TX',543210945),('NY',432109321);
|
SELECT s.state_name, SUM(w.usage_gallons) as total_usage FROM water_usage w JOIN states s ON w.state_abbr = s.state_abbr GROUP BY s.state_name;
|
How many outdoor cycling workouts were conducted for VIP members in the past month?
|
CREATE TABLE workouts (workout_id INT,member_id INT,type VARCHAR(20),date DATE); INSERT INTO workouts VALUES (1,1,'Outdoor Cycling','2022-01-05'); INSERT INTO workouts VALUES (2,2,'Outdoor Cycling','2022-01-10'); CREATE TABLE members (member_id INT,tier VARCHAR(10)); INSERT INTO members VALUES (1,'VIP'); INSERT INTO members VALUES (2,'Standard');
|
SELECT COUNT(workouts.workout_id) FROM workouts INNER JOIN members ON workouts.member_id = members.member_id WHERE workouts.type = 'Outdoor Cycling' AND members.tier = 'VIP' AND workouts.date >= DATEADD(month, -1, GETDATE());
|
What is the average age of male members who do weightlifting?
|
CREATE TABLE Members (MemberID INT,Age INT,Gender VARCHAR(10),WorkoutType VARCHAR(20)); INSERT INTO Members (MemberID,Age,Gender,WorkoutType) VALUES (1,30,'Male','Weightlifting'),(2,25,'Female','Yoga'),(3,45,'Male','Weightlifting'),(4,35,'Male','Running');
|
SELECT AVG(Age) FROM Members WHERE Gender = 'Male' AND WorkoutType = 'Weightlifting';
|
Show all research projects focused on Mars exploration.
|
CREATE TABLE ResearchProjects (id INT,project_name VARCHAR(100),field VARCHAR(50),leader VARCHAR(50),start_date DATE,end_date DATE); INSERT INTO ResearchProjects (id,project_name,field,leader,start_date,end_date) VALUES (1,'Project1','Space Exploration','Jane Smith','2021-01-01','2022-12-31'),(2,'Project2','Mars Exploration','Jim Brown','2022-01-01','2023-12-31');
|
SELECT * FROM ResearchProjects WHERE field = 'Mars Exploration';
|
What is the total biomass of fish in farms with a water temperature above 25 degrees Celsius?
|
CREATE TABLE Farm (FarmID int,FarmName varchar(50),WaterTemperature numeric,Biomass numeric); INSERT INTO Farm (FarmID,FarmName,WaterTemperature,Biomass) VALUES (1,'Farm A',15,50); INSERT INTO Farm (FarmID,FarmName,WaterTemperature,Biomass) VALUES (2,'Farm B',28,70); INSERT INTO Farm (FarmID,FarmName,WaterTemperature,Biomass) VALUES (3,'Farm C',14,60); INSERT INTO Farm (FarmID,FarmName,WaterTemperature,Biomass) VALUES (4,'Farm D',30,80); INSERT INTO Farm (FarmID,FarmName,WaterTemperature,Biomass) VALUES (5,'Farm E',22,90);
|
SELECT SUM(Biomass) FROM Farm WHERE WaterTemperature > 25;
|
What is the total number of building permits issued for commercial buildings in the state of New York in 2021?
|
CREATE TABLE building_permits (permit_id INT,building_type VARCHAR(50),state VARCHAR(50),issue_date DATE); INSERT INTO building_permits (permit_id,building_type,state,issue_date) VALUES (1,'Commercial','New York','2021-01-01'); INSERT INTO building_permits (permit_id,building_type,state,issue_date) VALUES (2,'Residential','New York','2021-02-01');
|
SELECT COUNT(*) FROM building_permits WHERE building_type = 'Commercial' AND state = 'New York' AND issue_date BETWEEN '2021-01-01' AND '2021-12-31';
|
What is the most expensive sativa sold in California dispensaries in Q3 2022?
|
CREATE TABLE Prices (id INT,strain TEXT,state TEXT,sale_price DECIMAL(5,2)); INSERT INTO Prices (id,strain,state,sale_price) VALUES (1,'Green Crack','CA',15.99),(2,'Jack Herer','CA',14.50),(3,'Durban Poison','CA',17.99),(4,'Super Lemon Haze','CA',16.50);
|
SELECT strain, MAX(sale_price) as max_price FROM Prices WHERE state = 'CA' AND strain LIKE '%sativa%' AND quarter(order_date) = 3 AND year(order_date) = 2022 GROUP BY strain HAVING max_price = (SELECT MAX(sale_price) FROM Prices WHERE state = 'CA' AND strain LIKE '%sativa%' AND quarter(order_date) = 3 AND year(order_date) = 2022);
|
List all chemical manufacturing facilities with their respective safety officer names and contact email addresses.
|
CREATE TABLE facilities (facility_id INT,facility_name TEXT,safety_officer_name TEXT,safety_officer_email TEXT); INSERT INTO facilities (facility_id,facility_name,safety_officer_name,safety_officer_email) VALUES (1,'Facility A','John Doe','[email protected]'),(2,'Facility B','Jane Smith','[email protected]'),(3,'Facility C','Alice Johnson','[email protected]');
|
SELECT facility_name, safety_officer_name, safety_officer_email FROM facilities;
|
List chemicals manufactured in 2021 and 2022.
|
CREATE TABLE Chemicals (Id INT,Name VARCHAR(50),Type VARCHAR(50),ManufacturingDate DATE); INSERT INTO Chemicals (Id,Name,Type,ManufacturingDate) VALUES (1,'Acetone','Solvent','2021-01-01'),(2,'Ammonia','Gas','2022-02-01');
|
SELECT * FROM Chemicals WHERE YEAR(ManufacturingDate) IN (2021, 2022);
|
What chemicals were shipped to the United States via rail transport after January 1, 2022?
|
CREATE TABLE transport_routes (id INT PRIMARY KEY,chemical_id INT,origin VARCHAR(255),destination VARCHAR(255),transport_type VARCHAR(255)); CREATE TABLE chemicals (id INT PRIMARY KEY,name VARCHAR(255),category VARCHAR(255),supplier_id INT,quantity INT);
|
SELECT c.name FROM transport_routes tr JOIN chemicals c ON tr.chemical_id = c.id WHERE tr.transport_type = 'Rail' AND tr.destination = 'United States' AND tr.date > '2022-01-01'
|
Insert new records into the 'renewable_energy_investment' table for 'Solar' and 'Wind' with amounts 10000000 and 15000000, respectively, and year 2022
|
CREATE TABLE renewable_energy_investment (energy_source VARCHAR(255),amount INT,year INT);
|
INSERT INTO renewable_energy_investment (energy_source, amount, year) VALUES ('Solar', 10000000, 2022), ('Wind', 15000000, 2022);
|
What is the total number of healthcare providers who speak a language other than English?
|
CREATE TABLE healthcare_providers_language (id INT,name VARCHAR(50),language VARCHAR(50)); INSERT INTO healthcare_providers_language (id,name,language) VALUES (1,'Dr. Chen','Spanish'),(2,'Dr. Singh','Hindi'),(3,'Dr. Park','Korean');
|
SELECT COUNT(*) FROM healthcare_providers_language WHERE language <> 'English';
|
Delete the "innovation_trends" table
|
CREATE TABLE innovation_trends (id INT PRIMARY KEY,company_id INT,innovation_type VARCHAR(20),year INT); INSERT INTO innovation_trends (id,company_id,innovation_type,year) VALUES (1,1001,'AI',2017),(2,1002,'ML',2018),(3,1003,'AR',2019),(4,1001,'VR',2020);
|
DROP TABLE innovation_trends;
|
What is the total funding amount for startups founded in the last 5 years?
|
CREATE TABLE companies (id INT,name TEXT,founded DATE); INSERT INTO companies (id,name,founded) VALUES (1,'Foobar Inc','2017-01-01'),(2,'Gizmos Inc','2019-06-15'),(3,'Widgets Inc','2015-09-27'); CREATE TABLE funding (company_id INT,amount INT); INSERT INTO funding (company_id,amount) VALUES (1,1000000),(1,2000000),(2,5000000),(3,3000000);
|
SELECT SUM(funding.amount) as total_funding FROM funding JOIN companies ON funding.company_id = companies.id WHERE companies.founded >= DATEADD(year, -5, GETDATE());
|
What is the total production of fruits and vegetables in Kenya?
|
CREATE TABLE production_data (farm_id INT,country VARCHAR(50),product VARCHAR(50),production INT); INSERT INTO production_data (farm_id,country,product,production) VALUES (1,'Kenya','Apples',200),(2,'Kenya','Carrots',300),(3,'Tanzania','Bananas',400);
|
SELECT SUM(production) FROM production_data WHERE country = 'Kenya' AND (product = 'Fruits' OR product = 'Vegetables');
|
What is the average population size of marine turtles?
|
CREATE TABLE marine_species (name TEXT,category TEXT,population INT); INSERT INTO marine_species (name,category,population) VALUES ('Leatherback Turtle','Turtle',5000),('Green Sea Turtle','Turtle',8000),('Loggerhead Turtle','Turtle',6000);
|
SELECT AVG(population) FROM marine_species WHERE category = 'Turtle';
|
What is the total number of smart contracts on the Ethereum blockchain, and how many of them were deployed in the last month?
|
CREATE TABLE ethereum_smart_contracts (contract_id INT,deploy_date DATE); INSERT INTO ethereum_smart_contracts (contract_id,deploy_date) VALUES (1,'2022-01-01'),(2,'2022-02-01'),(3,'2022-03-01'),(4,'2022-04-01'),(5,'2022-05-01');
|
SELECT COUNT(*), SUM(CASE WHEN deploy_date >= DATEADD(MONTH, -1, GETDATE()) THEN 1 ELSE 0 END) FROM ethereum_smart_contracts;
|
Find the total volume of timber sold in 2021
|
CREATE TABLE forests (id INT,name VARCHAR(50),hectares DECIMAL(5,2),year_planted INT,PRIMARY KEY (id)); INSERT INTO forests (id,name,hectares,year_planted) VALUES (1,'Forest A',123.45,1990),(2,'Forest B',654.32,1985); CREATE TABLE timber_sales (id INT,forest_id INT,year INT,volume DECIMAL(10,2),PRIMARY KEY (id)); INSERT INTO timber_sales (id,forest_id,year,volume) VALUES (1,1,2021,120.50),(2,1,2022,150.75),(3,2,2021,450.23),(4,2,2022,520.89);
|
SELECT SUM(ts.volume) FROM timber_sales ts INNER JOIN forests f ON ts.forest_id = f.id WHERE ts.year = 2021;
|
How many forests have high timber production and high biodiversity?
|
CREATE TABLE forests_data (id INT,timber_production FLOAT,biodiversity FLOAT);
|
SELECT COUNT(*) FROM forests_data WHERE timber_production > 50 AND biodiversity > 50;
|
List all the forests that have 'Quercus' species in the 'wildlife' table.
|
CREATE TABLE wildlife (id INT,forest_id INT,species VARCHAR(50));
|
SELECT DISTINCT forest_id FROM wildlife WHERE species = 'Quercus';
|
What is the total area of all protected wildlife habitats in the forestry database, in square kilometers?
|
CREATE TABLE wildlife_habitats (id INT,name VARCHAR(255),area_sq_km FLOAT);
|
SELECT SUM(area_sq_km) FROM wildlife_habitats WHERE protection_status = 'protected';
|
Delete records from 'cosmetics_sales' table where sale_date is before 2021-01-01
|
CREATE TABLE cosmetics_sales (product_id INT,product_name VARCHAR(255),units_sold INT,revenue DECIMAL(10,2),sale_date DATE); INSERT INTO cosmetics_sales (product_id,product_name,units_sold,revenue,sale_date) VALUES (1,'Liquid Foundation',20,200.50,'2021-01-01'),(2,'Organic Lip Balm',30,75.00,'2021-01-02'),(3,'Natural Mascara',15,120.00,'2021-01-03');
|
DELETE FROM cosmetics_sales WHERE sale_date < '2021-01-01';
|
Update the Rating for the 'Cleanser' product in the Products table to 4.6.
|
CREATE TABLE Products (Product VARCHAR(50),Label VARCHAR(50),Rating DECIMAL(3,2)); INSERT INTO Products (Product,Label,Rating) VALUES ('Cleanser','Vegan',4.5),('Moisturizer','Vegan',4.7),('Toner','Vegan',4.2);
|
UPDATE Products SET Rating = 4.6 WHERE Product = 'Cleanser';
|
Insert a new record into the 'EmergencyContacts' table with the following data: '911', 'Emergency Phone Number'
|
CREATE TABLE EmergencyContacts (ContactID INT PRIMARY KEY,ContactValue VARCHAR(50),ContactDescription VARCHAR(50));
|
INSERT INTO EmergencyContacts (ContactValue, ContactDescription) VALUES ('911', 'Emergency Phone Number');
|
What is the average number of military personnel in each branch of the military over the past 5 years?
|
CREATE TABLE military_personnel (id INT,branch VARCHAR(255),year INT,personnel INT); INSERT INTO military_personnel (id,branch,year,personnel) VALUES (1,'Army',2017,100000),(2,'Army',2018,110000),(3,'Army',2019,120000),(4,'Navy',2017,60000),(5,'Navy',2018,65000),(6,'Navy',2019,70000),(7,'Air Force',2017,50000),(8,'Air Force',2018,55000),(9,'Air Force',2019,60000);
|
SELECT branch, AVG(personnel) as avg_personnel FROM military_personnel GROUP BY branch;
|
What is the total tonnage of non-hazardous cargo unloaded at 'Port of Rotterdam' by 'Vessel Z' in Q1 2022?
|
CREATE TABLE vessels (id INT,name TEXT); CREATE TABLE cargo (id INT,hazardous_material BOOLEAN,tonnage INT,vessel_id INT,unloaded_date DATE,port_id INT); INSERT INTO vessels (id,name) VALUES (1,'Vessel Z'); INSERT INTO cargo (id,hazardous_material,tonnage,vessel_id,unloaded_date,port_id) VALUES (1,false,60,1,'2022-03-05',1),(2,true,100,1,'2022-02-10',1);
|
SELECT SUM(tonnage) FROM cargo INNER JOIN vessels ON cargo.vessel_id = vessels.id WHERE vessels.name = 'Vessel Z' AND cargo.unloaded_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH) AND cargo.hazardous_material = false AND cargo.port_id = 1;
|
List all unique skills in the 'employee_skills' table
|
CREATE TABLE employee_skills (employee_id INT,skill_name VARCHAR(50),experience_years INT); INSERT INTO employee_skills (employee_id,skill_name,experience_years) VALUES (1,'sustainable_manufacturing',3),(2,'quality_control',1),(3,'sustainable_manufacturing',5);
|
SELECT DISTINCT skill_name FROM employee_skills;
|
Update excavation notes for site 123
|
CREATE TABLE excavations (id INT PRIMARY KEY,site_id INT,date DATE,notes TEXT);
|
UPDATE excavations SET notes = 'Additional tools and resources found' WHERE site_id = 123 AND date = '2021-09-01';
|
What is the number of female patients in the 'rural_clinic_3' table?
|
CREATE TABLE rural_clinic_3 (patient_id INT,age INT,gender VARCHAR(10)); INSERT INTO rural_clinic_3 (patient_id,age,gender) VALUES (1,35,'Male'),(2,50,'Female'),(3,42,'Male'),(4,60,'Male'),(5,30,'Female'),(6,40,'Female');
|
SELECT COUNT(*) FROM rural_clinic_3 WHERE gender = 'Female';
|
What is the prevalence of diabetes in "Alabama" rural areas
|
CREATE TABLE diabetes_prevalence(id INT,location TEXT,population INT,diabetes_cases INT); INSERT INTO diabetes_prevalence(id,location,population,diabetes_cases) VALUES (1,'Alabama Rural Area',5000,750),(2,'Alabama Urban Area',10000,1500),(3,'Georgia Rural Area',6000,900),(4,'Georgia Urban Area',12000,1800);
|
SELECT diabetes_cases/population FROM diabetes_prevalence WHERE location LIKE '%Alabama Rural Area%';
|
What are the intelligence operations in the 'asia' and 'africa' regions?
|
CREATE TABLE intelligence_operations (id INT,operation TEXT,region TEXT); INSERT INTO intelligence_operations (id,operation,region) VALUES (1,'Op1','americas'),(2,'Op2','americas'),(3,'Op3','asia'),(4,'Op4','asia'),(5,'Op5','africa'),(6,'Op6','africa');
|
SELECT operation FROM intelligence_operations WHERE region IN ('asia', 'africa');
|
Who are the top 2 artists with the most songs in the country genre?
|
CREATE TABLE artists (id INT,name TEXT); CREATE TABLE songs_artists (song_id INT,artist_id INT); CREATE TABLE songs (id INT,title TEXT,length FLOAT,genre TEXT); INSERT INTO artists (id,name) VALUES (1,'Artist1'),(2,'Artist2'),(3,'Artist3'); INSERT INTO songs_artists (song_id,artist_id) VALUES (1,1),(2,2),(3,1),(4,3); INSERT INTO songs (id,title,length,genre) VALUES (1,'Song1',3.2,'country'),(2,'Song2',4.1,'rock'),(3,'Song3',3.8,'pop'),(4,'Song4',2.1,'country');
|
SELECT artists.name, COUNT(songs.id) AS song_count FROM artists JOIN songs_artists ON artists.id = songs_artists.artist_id JOIN songs ON songs_artists.song_id = songs.id WHERE songs.genre = 'country' GROUP BY artists.name ORDER BY song_count DESC LIMIT 2;
|
Calculate the average time spent in training by department in the "employee" and "training" tables
|
CREATE TABLE employee (id INT,department_id INT); CREATE TABLE training (id INT,employee_id INT,time_spent_minutes INT);
|
SELECT e.department_id, AVG(t.time_spent_minutes) AS avg_time_spent_minutes FROM employee e JOIN training t ON e.id = t.employee_id GROUP BY e.department_id;
|
What is the average salary for employees hired in Q2 2022?
|
CREATE TABLE Employees (EmployeeID INT,HireDate DATE,Salary INT); INSERT INTO Employees (EmployeeID,HireDate,Salary) VALUES (1,'2022-04-15',70000); INSERT INTO Employees (EmployeeID,HireDate,Salary) VALUES (2,'2022-06-01',75000);
|
SELECT AVG(Salary) FROM Employees WHERE HireDate BETWEEN '2022-04-01' AND '2022-06-30';
|
List the top 3 energy efficient appliances in the US by energy star rating?
|
CREATE TABLE appliances (id INT,name VARCHAR(255),country VARCHAR(255),energy_star_rating INT); INSERT INTO appliances (id,name,country,energy_star_rating) VALUES (1,'Fridge A','USA',5),(2,'TV B','USA',4),(3,'Laptop C','USA',5),(4,'Microwave D','USA',3);
|
SELECT name, energy_star_rating FROM appliances WHERE country = 'USA' ORDER BY energy_star_rating DESC LIMIT 3;
|
What was the total energy consumption in New York for the year 2020, segmented by renewable and non-renewable sources?
|
CREATE TABLE energy_consumption (state VARCHAR(20),year INT,energy_type VARCHAR(10),consumption FLOAT); INSERT INTO energy_consumption (state,year,energy_type,consumption) VALUES ('New York',2020,'Renewable',12000),('New York',2020,'Non-Renewable',25000);
|
SELECT state, year, SUM(CASE WHEN energy_type = 'Renewable' THEN consumption ELSE 0 END) AS renewable_consumption, SUM(CASE WHEN energy_type = 'Non-Renewable' THEN consumption ELSE 0 END) AS non_renewable_consumption FROM energy_consumption WHERE state = 'New York' AND year = 2020 GROUP BY state, year;
|
Show the number of wells drilled in each state
|
CREATE TABLE state_wells (state VARCHAR(2),num_wells INT); INSERT INTO state_wells (state,num_wells) VALUES ('TX',1200),('CA',800),('AK',500),('OK',900);
|
SELECT state, num_wells FROM state_wells;
|
What is the average number of goals scored per game by the home team in matches where the attendance was over 50,000?
|
CREATE TABLE games (home_team VARCHAR(50),away_team VARCHAR(50),attendance INTEGER,goals_home INTEGER,goals_away INTEGER); INSERT INTO games (home_team,away_team,attendance,goals_home,goals_away) VALUES ('Barcelona','Real Madrid',65000,3,1),('Manchester United','Liverpool',75000,2,0);
|
SELECT AVG(goals_home) FROM games WHERE attendance > 50000;
|
What is the maximum number of meals served daily in any refugee camp?
|
CREATE TABLE meals_served (id INT PRIMARY KEY,camp VARCHAR(50),month VARCHAR(20),day INT,number INT); INSERT INTO meals_served (id,camp,month,day,number) VALUES (1,'Camp A','April',1,1500),(2,'Camp B','April',1,1200),(3,'Camp A','April',2,1600),(4,'Camp B','April',2,1400),(5,'Camp C','April',3,1800);
|
SELECT MAX(number) FROM meals_served;
|
What is the average fare collected per trip for wheelchair accessible buses?
|
CREATE TABLE buses (id INT,type VARCHAR(20),fare FLOAT); CREATE TABLE trips (id INT,bus_id INT,wheelchair_accessible BOOLEAN); INSERT INTO buses (id,type,fare) VALUES (1,'Standard',2.00),(2,'Wheelchair Accessible',2.50); INSERT INTO trips (id,bus_id,wheelchair_accessible) VALUES (1,1,FALSE),(2,2,TRUE);
|
SELECT AVG(buses.fare) FROM buses JOIN trips ON buses.id = trips.bus_id WHERE trips.wheelchair_accessible = TRUE;
|
Delete the fabric with the highest production cost from the fabrics table.
|
CREATE TABLE fabrics (id INT,name VARCHAR(255),sustainability_rating FLOAT,production_cost FLOAT); INSERT INTO fabrics (id,name,sustainability_rating,production_cost) VALUES (1,'Organic Cotton',4.3,3.2),(2,'Recycled Polyester',3.8,2.9),(3,'Hemp',4.5,2.5),(4,'Piñatex',4.6,3.5),(5,'Bamboo',4.7,2.3),(6,'Linen',4.4,2.7),(7,'Modal',4.2,3.9),(8,'Tencel',4.8,2.1);
|
DELETE FROM fabrics WHERE production_cost = (SELECT MAX(production_cost) FROM fabrics);
|
What is the average bioprocess engineering project cost by continent and year, ordered by year?
|
CREATE SCHEMA if not exists bioprocess;CREATE TABLE if not exists bioprocess.projects (id INT PRIMARY KEY,name VARCHAR(255),continent VARCHAR(50),year INT,cost DECIMAL(10,2)); INSERT INTO bioprocess.projects (id,name,continent,year,cost) VALUES (1,'ProjectA','Asia',2018,500000.00),(2,'ProjectB','North America',2020,800000.00),(3,'ProjectC','Asia',2019,600000.00),(4,'ProjectD','Europe',2021,700000.00);
|
SELECT continent, AVG(cost) AS avg_cost, year FROM bioprocess.projects WINDOW W AS (PARTITION BY year ORDER BY year ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) GROUP BY continent, W.year ORDER BY year;
|
Who are the top 3 countries with the most genetic research experiments?
|
CREATE SCHEMA if not exists biotech;USE biotech;CREATE TABLE if not exists experiments (id INT,country VARCHAR(255),type VARCHAR(255));INSERT INTO experiments (id,country,type) VALUES (1,'Germany','Genetic'),(2,'France','Genetic'),(3,'USA','Bioprocess'),(4,'Germany','Biosensor'),(5,'UK','Genetic'),(6,'France','Bioprocess');
|
SELECT country, COUNT(*) as num_experiments FROM experiments WHERE type = 'Genetic' GROUP BY country ORDER BY num_experiments DESC LIMIT 3;
|
What is the average salary of employees in each federal agency?
|
CREATE TABLE agency (name VARCHAR(255),employees INT); CREATE TABLE employee (agency VARCHAR(255),salary DECIMAL(10,2)); INSERT INTO agency (name,employees) VALUES ('Department of Defense',750000),('Department of Veterans Affairs',400000),('Department of Health and Human Services',650000),('Department of Justice',120000),('Department of State',80000); INSERT INTO employee (agency,salary) VALUES ('Department of Defense',75000),('Department of Defense',80000),('Department of Veterans Affairs',50000),('Department of Veterans Affairs',55000),('Department of Health and Human Services',60000);
|
SELECT agency, AVG(salary) FROM employee GROUP BY agency;
|
Find the total installed capacity of renewable energy projects in the country 'Germany'
|
CREATE TABLE renewable_projects (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),installed_capacity INT); INSERT INTO renewable_projects (id,name,location,installed_capacity) VALUES (1,'Solarpark Finow Tower','Germany',45000); INSERT INTO renewable_projects (id,name,location,installed_capacity) VALUES (2,'Waldpolenz Solar Park','Germany',44500);
|
SELECT SUM(installed_capacity) FROM renewable_projects WHERE location = 'Germany';
|
What is the average CO2 emission of buildings in the United Kingdom?
|
CREATE TABLE UKBuildings (id INT,city VARCHAR(20),co2_emission FLOAT); INSERT INTO UKBuildings (id,city,co2_emission) VALUES (1,'London',320.5),(2,'Manchester',380.6),(3,'London',340.1);
|
SELECT AVG(co2_emission) FROM UKBuildings WHERE city = 'London';
|
What is the minimum health equity metric score achieved by healthcare providers working in rural areas?
|
CREATE TABLE healthcare_providers (id INT,name VARCHAR(100),location VARCHAR(50),health_equity_metric_score INT); INSERT INTO healthcare_providers (id,name,location,health_equity_metric_score) VALUES (1,'Pat','Rural',80),(2,'Quinn','Urban',85),(3,'Riley','Rural',75);
|
SELECT MIN(health_equity_metric_score) FROM healthcare_providers WHERE location = 'Rural';
|
Which community health workers have not conducted any mental health parity assessments in Texas?
|
CREATE TABLE CommunityHealthWorkers (CHW_ID INT,Name VARCHAR(100),State VARCHAR(2)); INSERT INTO CommunityHealthWorkers (CHW_ID,Name,State) VALUES (1,'John Doe','Texas'); INSERT INTO CommunityHealthWorkers (CHW_ID,Name,State) VALUES (2,'Jane Smith','California'); CREATE TABLE MentalHealthParityAssessments (AssessmentID INT,CHW_ID INT,AssessmentDate DATE); INSERT INTO MentalHealthParityAssessments (AssessmentID,CHW_ID,AssessmentDate) VALUES (1,1,'2021-01-01');
|
SELECT CHW_ID, Name FROM CommunityHealthWorkers cdw LEFT JOIN MentalHealthParityAssessments mhpa ON cdw.CHW_ID = mhpa.CHW_ID WHERE mhpa.CHW_ID IS NULL AND cdw.State = 'Texas';
|
Find the names of all the indigenous communities in the 'Arctic_Communities' table that have a population size greater than the average population size in the 'Antarctic_Communities' table.
|
CREATE TABLE Arctic_Communities (name TEXT,population INTEGER); CREATE TABLE Antarctic_Communities (name TEXT,population INTEGER);
|
SELECT name FROM Arctic_Communities WHERE Arctic_Communities.population > (SELECT AVG(population) FROM Antarctic_Communities)
|
Find the number of unique species observed at each monitoring station and the earliest observation date.
|
CREATE TABLE monitoring_stations (id INT PRIMARY KEY,name VARCHAR(50),location VARCHAR(50)); CREATE TABLE species_observations (id INT PRIMARY KEY,station_id INT,species_id INT,observation_date DATE); CREATE TABLE species (id INT PRIMARY KEY,name VARCHAR(50));
|
SELECT monitoring_stations.name, COUNT(DISTINCT species_observations.species_id) AS unique_species_count, MIN(species_observations.observation_date) AS earliest_observation_date FROM monitoring_stations INNER JOIN species_observations ON monitoring_stations.id = species_observations.station_id GROUP BY monitoring_stations.name;
|
CREATE TABLE HeritageSites (Site VARCHAR(50), CountryName VARCHAR(50));
|
INSERT INTO Countries (Name,Population) VALUES ('Australia',25000000),('Brazil',210000000),('China',1400000000),('India',1350000000),('Indonesia',265000000),('Russia',1450000000),('United States',330000000);
|
FROM HeritageSites h JOIN Countries c ON h.CountryName = c.Name
|
What traditional art forms have been preserved by communities in East Africa with a population of over 100,000?
|
CREATE TABLE Arts (id INT PRIMARY KEY,art_form VARCHAR(255),year_emerged INT,location VARCHAR(255),community_engagement INT); INSERT INTO Arts (id,art_form,year_emerged,location,community_engagement) VALUES (2,'Tingatinga Painting',1960,'Tanzania',400000);
|
SELECT a.art_form, a.year_emerged, a.location, c.community_name, c.region, c.engagement_level FROM Arts a INNER JOIN Communities c ON a.location = c.region WHERE c.speakers > 100000;
|
How many depression patients are there in each age group?
|
CREATE TABLE age_groups (age_group_id INT,age_group_name VARCHAR(50),lower_limit INT,upper_limit INT); INSERT INTO age_groups (age_group_id,age_group_name,lower_limit,upper_limit) VALUES (1,'18-30',18,30);
|
SELECT age_groups.age_group_name, COUNT(patients.patient_id) FROM patients INNER JOIN age_groups ON patients.age BETWEEN age_groups.lower_limit AND age_groups.upper_limit WHERE patients.diagnosis = 'Depression' GROUP BY age_groups.age_group_name;
|
Update the metric_value of the resilience metric with id 1 to 92
|
CREATE TABLE resilience_metrics (id INT PRIMARY KEY,metric_name VARCHAR(255),metric_value INT,project_id INT); INSERT INTO resilience_metrics (id,metric_name,metric_value,project_id) VALUES (1,'Earthquake Resistance',90,1); INSERT INTO resilience_metrics (id,metric_name,metric_value,project_id) VALUES (2,'Wind Resistance',95,1);
|
UPDATE resilience_metrics SET metric_value = 92 WHERE id = 1;
|
Insert a new record of a tourist visiting New Zealand from Singapore in 2024.
|
CREATE TABLE tourism_data (id INT,country VARCHAR(50),destination VARCHAR(50),arrival_date DATE,age INT);
|
INSERT INTO tourism_data (id, country, destination, arrival_date, age) VALUES (12, 'Singapore', 'New Zealand', '2024-02-18', 25);
|
Update the species ID to 3 for the marine life sighting with ID 2
|
CREATE TABLE marine_life_sightings (id INT PRIMARY KEY,species_id INT,location VARCHAR(255),date DATE); INSERT INTO marine_life_sightings (id,species_id,location,date) VALUES (1,1,'Pacific Ocean','2022-02-01'),(2,2,'Atlantic Ocean','2022-03-01');
|
WITH cte_sightings AS (UPDATE marine_life_sightings SET species_id = 3 WHERE id = 2 RETURNING id, species_id, location, date) SELECT * FROM cte_sightings;
|
What are the names of the vessels that have complied with maritime law in the Pacific Ocean in the last 3 years?
|
CREATE TABLE vessels (vessel_name TEXT,compliance_status TEXT,ocean TEXT,year INT); INSERT INTO vessels (vessel_name,compliance_status,ocean,year) VALUES ('VesselA','compliant','Pacific',2020),('VesselB','non-compliant','Pacific',2020),('VesselC','compliant','Pacific',2020),('VesselA','compliant','Pacific',2021),('VesselB','non-compliant','Pacific',2021),('VesselC','compliant','Pacific',2021);
|
SELECT DISTINCT vessel_name FROM vessels WHERE compliance_status = 'compliant' AND ocean = 'Pacific' AND year BETWEEN 2019 AND 2021;
|
What is the maximum pollution level recorded in the Atlantic ocean?
|
CREATE TABLE pollution_monitoring_atlantic (location VARCHAR(255),pollution_level FLOAT); INSERT INTO pollution_monitoring_atlantic (location,pollution_level) VALUES ('Atlantic Ocean',6.5),('Gulf of Mexico',7.2);
|
SELECT MAX(pollution_level) FROM pollution_monitoring_atlantic WHERE location = 'Atlantic Ocean';
|
Show the number of articles and videos, by category, that have been created by studios located in Brazil and Japan.
|
CREATE TABLE media_content (id INT,title VARCHAR(255),category VARCHAR(255),studio_location VARCHAR(255)); INSERT INTO media_content (id,title,category,studio_location) VALUES (1,'Article1','Politics','Brazil'),(2,'Video1','Sports','Japan');
|
SELECT category, COUNT(*) as total FROM media_content WHERE studio_location IN ('Brazil', 'Japan') GROUP BY category;
|
What is the number of movies produced by studios located in Africa and the percentage of those movies that are documentaries?
|
CREATE TABLE movie_africa (id INT,studio VARCHAR(255),movie_type VARCHAR(255)); INSERT INTO movie_africa (id,studio,movie_type) VALUES (1,'Foluke Productions','Drama'); INSERT INTO movie_africa (id,studio,movie_type) VALUES (2,'Foluke Productions','Documentary'); INSERT INTO movie_africa (id,studio,movie_type) VALUES (3,'Kunle Afolayan Productions','Drama'); INSERT INTO movie_africa (id,studio,movie_type) VALUES (4,'Kunle Afolayan Productions','Documentary'); INSERT INTO movie_africa (id,studio,movie_type) VALUES (5,'RAK Studios','Drama');
|
SELECT COUNT(*) as count, ROUND(100.0 * SUM(CASE WHEN movie_type = 'Documentary' THEN 1 ELSE 0 END) / COUNT(*), 2) as doc_percentage FROM movie_africa WHERE studio IN (SELECT studio_name FROM movie_studios WHERE country IN (SELECT region FROM regions WHERE continent = 'Africa'));
|
Who are the top 3 contract negotiators for defense projects in Europe?
|
CREATE TABLE contract_negotiators (id INT,name VARCHAR(255),region VARCHAR(255)); INSERT INTO contract_negotiators (id,name,region) VALUES (1,'John Smith','Europe'),(2,'Jane Doe','Americas'),(3,'Mike Johnson','Asia Pacific'),(4,'Sara Connor','Europe'),(5,'Tom Williams','Middle East'),(6,'Kate Brown','Europe');
|
SELECT name FROM contract_negotiators WHERE region = 'Europe' LIMIT 3;
|
List the mines in the mining_sites table that have the lowest extraction rates, up to a maximum of 3 mines, excluding mines located in 'California'.
|
CREATE TABLE mining_sites (id INT,name VARCHAR(50),location VARCHAR(50),extraction_rate DECIMAL(5,2)); INSERT INTO mining_sites (id,name,location,extraction_rate) VALUES (1,'Gold Mine','California',12.5),(2,'Silver Mine','Nevada',15.2),(3,'Copper Mine','Arizona',18.9),(4,'Iron Mine','Minnesota',21.1);
|
SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY extraction_rate ASC) rn FROM mining_sites WHERE location != 'California') t WHERE rn <= 3;
|
List the names and locations of mines that have not mined any type of metal.
|
CREATE TABLE mine (id INT,name VARCHAR(50),location VARCHAR(50));CREATE TABLE coal_mine (mine_id INT,amount INT);CREATE TABLE iron_mine (mine_id INT,amount INT);CREATE TABLE gold_mine (mine_id INT,amount INT);CREATE TABLE silver_mine (mine_id INT,amount INT);
|
SELECT m.name, m.location FROM mine m LEFT JOIN coal_mine c ON m.id = c.mine_id LEFT JOIN iron_mine i ON m.id = i.mine_id LEFT JOIN gold_mine g ON m.id = g.mine_id LEFT JOIN silver_mine s ON m.id = s.mine_id WHERE c.mine_id IS NULL AND i.mine_id IS NULL AND g.mine_id IS NULL AND s.mine_id IS NULL;
|
Update the quantity of 'Dump Truck' to 12 in the equipment_rental table.
|
CREATE TABLE equipment_rental(id INT,equipment VARCHAR(50),quantity INT); INSERT INTO equipment_rental (id,equipment,quantity) VALUES (1,'Bulldozer',10),(2,'Excavator',15),(3,'Dump Truck',8);
|
UPDATE equipment_rental SET quantity = 12 WHERE equipment = 'Dump Truck';
|
What is the total amount of network infrastructure investments for APAC countries?
|
CREATE TABLE network_investments (country VARCHAR(20),investment_amount FLOAT); INSERT INTO network_investments (country,investment_amount) VALUES ('China',500000),('Japan',400000),('India',350000);
|
SELECT SUM(investment_amount) FROM network_investments WHERE country IN ('China', 'Japan', 'India', 'Australia', 'South Korea');
|
What is the average age of journalists in the "journalists" table by gender?
|
CREATE TABLE journalists (id INT,name VARCHAR(50),age INT,gender VARCHAR(10));
|
SELECT gender, AVG(age) FROM journalists GROUP BY gender;
|
Delete 'species' table
|
CREATE TABLE species (id INT PRIMARY KEY,name VARCHAR(255),population INT,conservation_status VARCHAR(255),last_sighting DATE); INSERT INTO species (id,name,population,conservation_status,last_sighting) VALUES (1,'Blue Whale',10000,'Critically Endangered','2020-01-01');
|
DROP TABLE species;
|
How many research vessels are registered in the Mediterranean region?
|
CREATE TABLE research_vessels (name VARCHAR(255),region VARCHAR(255)); INSERT INTO research_vessels (name,region) VALUES ('Oceanus','Mediterranean'),('Alvin','Atlantic'),('Thunderbird','Pacific');
|
SELECT COUNT(*) FROM research_vessels WHERE region = 'Mediterranean';
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.