instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
How many ethical labor practice violations were reported in Asia in the last 6 months?
|
CREATE TABLE violations (violation_id INT,report_date DATE,region TEXT,description TEXT); INSERT INTO violations (violation_id,report_date,region,description) VALUES (1,'2022-01-15','Asia','Child labor accusation');
|
SELECT COUNT(*) FROM violations WHERE report_date >= DATEADD(month, -6, CURRENT_DATE) AND region = 'Asia';
|
What is the name and price of the most expensive product in the 'Natural' category?
|
CREATE TABLE products (id INT,name VARCHAR(255),category VARCHAR(255),price DECIMAL(10,2)); INSERT INTO products (id,name,category,price) VALUES (1,'Nourishing Face Cream','Organic',25.99),(2,'Revitalizing Serum','Natural',34.99),(3,'Soothing Eye Cream','Organic',19.99);
|
SELECT name, price FROM products WHERE category = 'Natural' ORDER BY price DESC LIMIT 1;
|
Which communication types have been used in the coastal protection project?
|
CREATE TABLE communications (id INT,project_id INT,communication_type VARCHAR(50),message TEXT,date DATE); INSERT INTO communications (id,project_id,communication_type,message,date) VALUES (1,1,'Press Release','Solar Farm Completed','2022-01-05'),(2,2,'Email','Meeting Invitation','2022-04-10'); CREATE TABLE projects (id INT,name VARCHAR(100),location VARCHAR(100)); INSERT INTO projects (id,name,location) VALUES (1,'Coastal Protection','Florida'),(2,'Wind Farm','Texas');
|
SELECT communication_type FROM communications WHERE project_id = (SELECT id FROM projects WHERE name = 'Coastal Protection');
|
How many 5-star hotels are there in the 'Rural_Hotels' table?
|
CREATE TABLE Rural_Hotels (hotel_id INT,hotel_name TEXT,rating INT); INSERT INTO Rural_Hotels (hotel_id,hotel_name,rating) VALUES (1,'Forest Retreat',5),(2,'Mountain Escape',4);
|
SELECT COUNT(*) FROM Rural_Hotels WHERE rating = 5;
|
What is the total area of all wildlife habitats in square kilometers?
|
CREATE TABLE wildlife_habitat (id INT,name VARCHAR(50),area FLOAT); INSERT INTO wildlife_habitat (id,name,area) VALUES (1,'Habitat1',150.3),(2,'Habitat2',250.8),(3,'Habitat3',175.5);
|
SELECT SUM(area) FROM wildlife_habitat;
|
Insert a new post with post_id 3 and 75 likes for user_id 2.
|
CREATE TABLE users (user_id INT); INSERT INTO users (user_id) VALUES (1),(2); CREATE TABLE posts (post_id INT,user_id INT,likes INT); INSERT INTO posts (post_id,user_id,likes) VALUES (1,1,100),(2,1,200),(3,2,50);
|
INSERT INTO posts (post_id, user_id, likes) VALUES (3, 2, 75);
|
What is the maximum number of construction labor hours worked in a year in the city of Los Angeles?
|
CREATE TABLE labor_hours (labor_id INT,city VARCHAR(20),year INT,hours_worked INT); INSERT INTO labor_hours (labor_id,city,year,hours_worked) VALUES (1,'Los Angeles',2019,1500000),(2,'Los Angeles',2018,1400000),(3,'New York',2019,1200000),(4,'Los Angeles',2020,1600000);
|
SELECT city, MAX(hours_worked) FROM labor_hours GROUP BY city;
|
Create a table named 'project_milestones' with columns 'project_id', 'milestone', 'due_date'
|
CREATE TABLE project_milestones (project_id INT,milestone VARCHAR(50),due_date DATE);
|
CREATE TABLE project_milestones (project_id INT, milestone VARCHAR(50), due_date DATE);
|
Who are the top 5 contractors by number of permits in Texas?
|
CREATE TABLE Contractors (id INT,name TEXT,permits INT);CREATE VIEW Contractor_Permits AS SELECT contractor_id,COUNT(*) as num_permits FROM Building_Permits GROUP BY contractor_id;
|
SELECT name, SUM(num_permits) as total_permits FROM Contractor_Permits JOIN Contractors ON Contractor_Permits.contractor_id = Contractors.id GROUP BY name ORDER BY total_permits DESC LIMIT 5;
|
Insert a new record of a new budget allocation for the 'Waste Management' department in the 'BudgetAllocation' table
|
CREATE TABLE BudgetAllocation (department VARCHAR(20),budget INT);
|
INSERT INTO BudgetAllocation (department, budget) VALUES ('Waste Management', 600000);
|
Find the total number of safety tests conducted per quarter
|
CREATE TABLE safety_tests (id INT,test_date DATE); INSERT INTO safety_tests (id,test_date) VALUES (1,'2022-01-15'),(2,'2022-02-12'),(3,'2022-03-17'),(4,'2022-04-05'),(5,'2022-05-03'),(6,'2022-06-10'),(7,'2022-07-01'),(8,'2022-08-14'),(9,'2022-09-28'),(10,'2022-10-06'),(11,'2022-11-19'),(12,'2022-12-25');
|
SELECT EXTRACT(QUARTER FROM test_date) as quarter, COUNT(*) as tests_per_quarter FROM safety_tests GROUP BY quarter;
|
What is the average number of donations per donor?
|
CREATE TABLE Donations (DonationID INT,DonationAmount INT,DonorID INT,DonationDate DATE); INSERT INTO Donations (DonationID,DonationAmount,DonorID,DonationDate) VALUES (1,100,1,'2022-01-01'),(2,200,2,'2021-05-15');
|
SELECT AVG(DonationCount) FROM (SELECT DonorID, COUNT(DonationID) AS DonationCount FROM Donations GROUP BY DonorID) AS Subquery;
|
What is the total weight of shipments from Southeast Asia to Oceania?
|
CREATE TABLE shipments (id INT,origin_region VARCHAR(255),destination_continent VARCHAR(255),weight FLOAT); INSERT INTO shipments (id,origin_region,destination_continent,weight) VALUES (1,'Southeast Asia','Oceania',900.0),(2,'Southeast Asia','Oceania',700.0);
|
SELECT SUM(weight) FROM shipments WHERE origin_region = 'Southeast Asia' AND destination_continent = 'Oceania';
|
What is the energy efficiency score for the top 5 countries in renewable energy consumption?
|
CREATE TABLE renewable_energy (country TEXT,consumption FLOAT); INSERT INTO renewable_energy (country,consumption) VALUES ('China',1963.73),('United States',815.62),('Brazil',556.50),('Germany',353.34),('Spain',275.60),('India',245.65),('Japan',206.97),('France',202.51),('Canada',194.51),('Italy',168.65); CREATE TABLE energy_efficiency (country TEXT,score FLOAT); INSERT INTO energy_efficiency (country,score) VALUES ('China',79.8),('United States',116.0),('Brazil',81.5),('Germany',96.5),('Spain',95.2),('India',65.5),('Japan',80.7),('France',93.0),('Canada',92.5),('Italy',87.4);
|
SELECT e.country, e.score FROM (SELECT country FROM renewable_energy ORDER BY consumption DESC LIMIT 5) AS r JOIN energy_efficiency AS e ON r.country = e.country
|
What is the percentage of organic ingredients in cosmetics produced in France?
|
CREATE TABLE ingredients (product_id INT,ingredient_name VARCHAR(50),organic BOOLEAN); INSERT INTO ingredients VALUES (1,'Water',false),(1,'Paraben',false),(2,'Aloe Vera',true),(2,'Fragrance',false); CREATE TABLE sourcing (product_id INT,country VARCHAR(20),organic BOOLEAN); INSERT INTO sourcing VALUES (1,'France',false),(2,'Germany',true); CREATE TABLE products (product_id INT,product_name VARCHAR(100)); INSERT INTO products VALUES (1,'Mascara'),(2,'Lipstick');
|
SELECT 100.0 * AVG(sourcing.organic) AS percentage FROM ingredients JOIN sourcing ON ingredients.product_id = sourcing.product_id JOIN products ON ingredients.product_id = products.product_id WHERE country = 'France';
|
Insert a new support program for the state of New York called "Empowering Disability Services".
|
CREATE TABLE disability_support_programs (id INT,state VARCHAR(255),program_name VARCHAR(255),description VARCHAR(255));
|
INSERT INTO disability_support_programs (id, state, program_name, description) VALUES (4, 'New York', 'Empowering Disability Services', 'Program to empower individuals with disabilities in New York');
|
List all projects with a start date in the year 2022 or later from the "Projects" table.
|
CREATE TABLE Projects (project_id INT,contractor_id INT,start_date DATE,end_date DATE);
|
SELECT * FROM Projects WHERE start_date >= '2022-01-01' OR YEAR(start_date) = 2022;
|
Which hotel in the 'APAC' region had the highest revenue in Q3 2022?
|
CREATE TABLE hotel_revenue (id INT,hotel_id INT,region TEXT,quarter INT,revenue FLOAT);
|
SELECT hotel_id, MAX(revenue) OVER (PARTITION BY region, quarter) as max_revenue FROM hotel_revenue WHERE region = 'APAC' AND quarter = 3;
|
What is the minimum R&D expenditure for a specific drug in a certain year?
|
CREATE TABLE drugs (id INT,name VARCHAR(255),category VARCHAR(255)); CREATE TABLE rd_expenditures (id INT,drug_id INT,year INT,amount DECIMAL(10,2));
|
SELECT MIN(rd_expenditures.amount) FROM rd_expenditures JOIN drugs ON rd_expenditures.drug_id = drugs.id WHERE drugs.name = 'DrugA' AND rd_expenditures.year = 2020;
|
Find the total number of exhibitions and average guest rating for each artist's works in New York, and rank them in descending order of total number of exhibitions.
|
CREATE TABLE Artists (id INT,name VARCHAR(30)); CREATE TABLE Works (id INT,artist_id INT,title VARCHAR(50)); CREATE TABLE Exhibitions (id INT,work_id INT,gallery_id INT,city VARCHAR(20),guest_rating FLOAT,revenue FLOAT); INSERT INTO Exhibitions (id,work_id,gallery_id,city,guest_rating,revenue) VALUES (1,1,1,'New York',4.5,6000),(2,2,2,'New York',4.2,7000),(3,3,3,'New York',4.7,5000);
|
SELECT a.name, COUNT(e.id) as total_exhibitions, AVG(e.guest_rating) as avg_guest_rating, RANK() OVER (PARTITION BY a.name ORDER BY COUNT(e.id) DESC) as rank FROM Artists a JOIN Works w ON a.id = w.artist_id JOIN Exhibitions e ON w.id = e.work_id WHERE e.city = 'New York' GROUP BY a.name, rank ORDER BY total_exhibitions DESC;
|
Update the sighting_date for species_id 1 to '2022-06-16'.
|
CREATE TABLE marine_species (species_id INT,species_name VARCHAR(50),ocean_name VARCHAR(50),sighting_date DATE); INSERT INTO marine_species VALUES (1,'Clownfish','Pacific Ocean','2022-06-15');
|
UPDATE marine_species SET sighting_date = '2022-06-16' WHERE species_id = 1;
|
Which sustainable menu items were sold more than 50 times in the month of March 2021?
|
CREATE TABLE sustainable_menu_items (menu_item_id INT,menu_item_name VARCHAR(255),sustainable_ingredient BOOLEAN); CREATE TABLE menu_sales (menu_item_id INT,sale_date DATE,quantity INT); INSERT INTO sustainable_menu_items (menu_item_id,menu_item_name,sustainable_ingredient) VALUES (1,'Quinoa Salad',true),(2,'Chicken Sandwich',false),(3,'Tofu Stir Fry',true); INSERT INTO menu_sales (menu_item_id,sale_date,quantity) VALUES (1,'2021-03-01',55),(1,'2021-03-02',60),(2,'2021-03-01',40),(2,'2021-03-02',35),(3,'2021-03-01',50),(3,'2021-03-02',53);
|
SELECT menu_item_name, SUM(quantity) as total_quantity FROM menu_sales JOIN sustainable_menu_items ON menu_sales.menu_item_id = sustainable_menu_items.menu_item_id WHERE sustainable_menu_items.sustainable_ingredient = true GROUP BY menu_item_name HAVING total_quantity > 50;
|
How many visual artists are represented in the database, and what is the distribution by their gender?
|
CREATE TABLE artists (id INT,name VARCHAR(255),birth_date DATE,gender VARCHAR(50));
|
SELECT COUNT(*) as total_artists, gender FROM artists GROUP BY gender;
|
Display the total mass of space debris in kg for each debris type
|
CREATE TABLE space_debris (debris_id INT,debris_type VARCHAR(50),mass FLOAT); INSERT INTO space_debris (debris_id,debris_type,mass) VALUES (1,'Fuel Tanks',350.0); INSERT INTO space_debris (debris_id,debris_type,mass) VALUES (2,'Instruments',75.2); INSERT INTO space_debris (debris_id,debris_type,mass) VALUES (3,'Payload Adapters',120.5);
|
SELECT debris_type, SUM(mass) as total_mass_kg FROM space_debris GROUP BY debris_type;
|
What is the total number of customers in the financial sector?
|
CREATE TABLE customer (customer_id INT,name VARCHAR(255),sector VARCHAR(255)); INSERT INTO customer (customer_id,name,sector) VALUES (1,'John Doe','financial'),(2,'Jane Smith','technology');
|
SELECT COUNT(*) FROM customer WHERE sector = 'financial';
|
Who are the researchers with expertise in biodiversity or resource management?
|
CREATE TABLE Researchers (id INT PRIMARY KEY,name VARCHAR(100),expertise VARCHAR(100),affiliation VARCHAR(100)); INSERT INTO Researchers (id,name,expertise,affiliation) VALUES (1,'Jane Doe','Biodiversity','University of Toronto');
|
SELECT r.name FROM Researchers r WHERE r.expertise IN ('Biodiversity', 'Resource Management');
|
What's the total number of 'Education' and 'Legal Support' services provided in 'Syria' and 'Yemen'?
|
CREATE TABLE Education (country VARCHAR(255),num_services INT); INSERT INTO Education (country,num_services) VALUES ('Syria',1000),('Yemen',800),('Afghanistan',1200); CREATE TABLE Legal_Support (country VARCHAR(255),num_services INT); INSERT INTO Legal_Support (country,num_services) VALUES ('Syria',500),('Yemen',700),('Iraq',900);
|
SELECT SUM(num_services) FROM (SELECT num_services FROM Education WHERE country IN ('Syria', 'Yemen') UNION ALL SELECT num_services FROM Legal_Support WHERE country IN ('Syria', 'Yemen')) AS combined_countries;
|
What was the total cost of all infrastructure projects in the Philippines in 2021?
|
CREATE TABLE infrastructure_projects (id INT,country VARCHAR(255),project VARCHAR(255),cost FLOAT,year INT); INSERT INTO infrastructure_projects (id,country,project,cost,year) VALUES (1,'Philippines','Road Construction',5000000,2021),(2,'Philippines','Bridge Building',3000000,2021),(3,'Indonesia','Irrigation System',7000000,2021);
|
SELECT SUM(cost) FROM infrastructure_projects WHERE country = 'Philippines' AND year = 2021;
|
What is the average price of Vegan certified products?
|
CREATE TABLE products (product_id INT,name VARCHAR(255),price DECIMAL(5,2),certification VARCHAR(255));
|
SELECT AVG(price) FROM products WHERE certification = 'Vegan';
|
What is the total revenue of sustainable tourism in Barcelona in 2021?
|
CREATE TABLE tourism_revenue (year INT,city TEXT,revenue FLOAT); INSERT INTO tourism_revenue (year,city,revenue) VALUES (2021,'Barcelona',200000),(2022,'Barcelona',250000);
|
SELECT SUM(revenue) FROM tourism_revenue WHERE city = 'Barcelona' AND year = 2021;
|
What is the total number of trees in the forestry_data schema, excluding trees that are in the no_management_zone table?
|
CREATE TABLE forestry_data.young_forest (tree_id INT,species VARCHAR(50),age INT,height INT,location VARCHAR(50));CREATE TABLE forestry_data.mature_forest (tree_id INT,species VARCHAR(50),age INT,height INT,location VARCHAR(50));CREATE TABLE forestry_data.protected_zone (tree_id INT,species VARCHAR(50),age INT,height INT,location VARCHAR(50));CREATE TABLE forestry_data.no_management_zone (tree_id INT,species VARCHAR(50),age INT,height INT,location VARCHAR(50));
|
SELECT COUNT(*) FROM forestry_data.young_forest UNION ALL SELECT COUNT(*) FROM forestry_data.mature_forest EXCEPT SELECT COUNT(*) FROM forestry_data.no_management_zone;
|
Maximum impact investment amount in the education sector?
|
CREATE TABLE impact_investments_education (id INT,sector VARCHAR(20),investment_amount FLOAT); INSERT INTO impact_investments_education (id,sector,investment_amount) VALUES (1,'Education',100000.0),(2,'Education',120000.0),(3,'Education',150000.0);
|
SELECT MAX(investment_amount) FROM impact_investments_education WHERE sector = 'Education';
|
What is the average claim amount for policies in the 'personal_auto' table?
|
CREATE TABLE personal_auto (policy_id INT,claim_amount DECIMAL(10,2)); INSERT INTO personal_auto (policy_id,claim_amount) VALUES (1,250.50),(2,400.75),(3,120.00);
|
SELECT AVG(claim_amount) FROM personal_auto;
|
What is the minimum power output of a wind turbine in the 'Northeast' region?
|
CREATE TABLE wind_turbines (id INT,region VARCHAR(20),power_output FLOAT); INSERT INTO wind_turbines (id,region,power_output) VALUES (1,'Northeast',3.4),(2,'Midwest',4.2),(3,'Northeast',5.1),(4,'South',2.9);
|
SELECT MIN(power_output) FROM wind_turbines WHERE region = 'Northeast';
|
How many news stories have been published about climate change in the past year, grouped by the publication's country?
|
CREATE TABLE news_stories (id INT,title VARCHAR(100),date DATE,topic VARCHAR(50),publication_id INT);CREATE TABLE publications (id INT,country VARCHAR(50)); INSERT INTO news_stories VALUES (1,'Climate crisis','2022-01-01','Climate change',1); INSERT INTO publications VALUES (1,'The New York Times');
|
SELECT publications.country, COUNT(news_stories.id) FROM news_stories INNER JOIN publications ON news_stories.publication_id = publications.id WHERE news_stories.date >= DATEADD(year, -1, GETDATE()) AND news_stories.topic = 'Climate change' GROUP BY publications.country;
|
What is the total volume of timber harvested in '2022' from the 'Pacific Northwest' region?
|
CREATE TABLE regions (id INT,name VARCHAR(50)); INSERT INTO regions (id,name) VALUES (1,'Pacific Northwest'); CREATE TABLE timber_harvest (id INT,region_id INT,year INT,volume FLOAT); INSERT INTO timber_harvest (id,region_id,year,volume) VALUES (1,1,2022,1200.5);
|
SELECT SUM(volume) FROM timber_harvest WHERE region_id = 1 AND year = 2022;
|
What is the minimum revenue of hotels in Japan that have more than 100 reviews?
|
CREATE TABLE hotels (id INT,name TEXT,country TEXT,revenue FLOAT,reviews INT);
|
SELECT MIN(revenue) FROM hotels WHERE country = 'Japan' AND reviews > 100;
|
What is the total number of labor hours spent on workforce development programs for each department in the past year?
|
CREATE TABLE departments(id INT,department TEXT);CREATE TABLE employees(id INT,name TEXT,department TEXT,labor_hours INT,training_date DATE);INSERT INTO departments(id,department) VALUES (1,'Department A'),(2,'Department B'),(3,'Department C'); INSERT INTO employees(id,name,department,labor_hours,training_date) VALUES (1,'Employee 1','Department A',10,'2021-01-10'),(2,'Employee 2','Department B',15,'2021-02-15'),(3,'Employee 3','Department A',20,'2021-03-20'),(4,'Employee 4','Department C',25,'2021-04-25'),(5,'Employee 5','Department B',30,'2021-05-30'),(6,'Employee 6','Department C',35,'2021-06-30'),(7,'Employee 7','Department A',40,'2021-07-31'),(8,'Employee 8','Department B',45,'2021-08-31'),(9,'Employee 9','Department C',50,'2021-09-30'),(10,'Employee 10','Department A',55,'2021-10-31');
|
SELECT department, SUM(labor_hours) as total_labor_hours FROM employees WHERE training_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY department;
|
What are the endangered species with no protection programs in place?
|
CREATE TABLE Species (id INT PRIMARY KEY,name VARCHAR(50),family VARCHAR(50),conservation_status VARCHAR(50)); CREATE TABLE Threats (id INT PRIMARY KEY,species_id INT,threat_type VARCHAR(50),severity VARCHAR(50)); CREATE TABLE Protection_Programs (id INT PRIMARY KEY,species_id INT,program_name VARCHAR(50),start_year INT,end_year INT);
|
SELECT Species.name FROM Species LEFT JOIN Protection_Programs ON Species.id = Protection_Programs.species_id WHERE Species.conservation_status = 'Endangered' AND Protection_Programs.id IS NULL;
|
Which energy storage technology has the highest capacity in the EnergyStorage table?
|
CREATE TABLE EnergyStorage (technology TEXT,capacity INT); INSERT INTO EnergyStorage (technology,capacity) VALUES ('Lithium-ion',3000),('Lead-acid',2000);
|
SELECT technology, capacity FROM EnergyStorage ORDER BY capacity DESC LIMIT 1;
|
What is the total number of fire stations in Boston?
|
CREATE TABLE boston_fire_stations (id INT,station_name VARCHAR(20),location VARCHAR(20)); INSERT INTO boston_fire_stations (id,station_name,location) VALUES (1,'Station 1','Boston'),(2,'Station 2','Boston');
|
SELECT COUNT(*) FROM boston_fire_stations;
|
What is the average age of players who play VR games, grouped by their country?
|
CREATE TABLE players (id INT,age INT,country VARCHAR(255)); INSERT INTO players (id,age,country) VALUES (1,25,'USA'),(2,30,'Canada'),(3,35,'Mexico'); CREATE TABLE games (id INT,name VARCHAR(255),category VARCHAR(255)); INSERT INTO games (id,name,category) VALUES (1,'GameA','VR'),(2,'GameB','Non-VR'),(3,'GameC','VR'); CREATE TABLE player_games (player_id INT,game_id INT); INSERT INTO player_games (player_id,game_id) VALUES (1,1),(2,1),(3,1),(1,3),(2,3);
|
SELECT p.country, AVG(p.age) as avg_age FROM players p JOIN player_games pg ON p.id = pg.player_id JOIN games g ON pg.game_id = g.id WHERE g.category = 'VR' GROUP BY p.country;
|
How many patients have been treated by gender?
|
CREATE TABLE patient_demographics (patient_id INT,gender VARCHAR(10)); INSERT INTO patient_demographics (patient_id,gender) VALUES (1,'Female');
|
SELECT gender, COUNT(*) FROM patient_demographics GROUP BY gender;
|
What is the average habitat preservation funding per square kilometer for each Asian conservation area?
|
CREATE TABLE asian_conservation_areas (id INT,name VARCHAR(255),area_size FLOAT,funding FLOAT);
|
SELECT aca.name, AVG(aca.funding / aca.area_size) as avg_funding_per_sq_km FROM asian_conservation_areas aca GROUP BY aca.name;
|
What is the minimum broadband speed for customers in the state of Florida?
|
CREATE TABLE broadband_subscribers (subscriber_id INT,speed FLOAT,state VARCHAR(20)); INSERT INTO broadband_subscribers (subscriber_id,speed,state) VALUES (1,75,'Florida'),(2,150,'Florida');
|
SELECT MIN(speed) FROM broadband_subscribers WHERE state = 'Florida';
|
Calculate the average energy storage capacity for each energy type
|
CREATE TABLE energy_storage (energy_type VARCHAR(50),capacity FLOAT); INSERT INTO energy_storage (energy_type,capacity) VALUES ('Batteries',45.6),('Flywheels',32.7),('Batteries',54.3);
|
SELECT energy_type, AVG(capacity) FROM energy_storage GROUP BY energy_type;
|
How many wells are there in each region?
|
CREATE TABLE wells (well_id INT,well_name VARCHAR(50),region VARCHAR(20)); INSERT INTO wells (well_id,well_name,region) VALUES (1,'Well A','onshore'); INSERT INTO wells (well_id,well_name,region) VALUES (2,'Well B','offshore'); INSERT INTO wells (well_id,well_name,region) VALUES (3,'Well C','onshore');
|
SELECT region, COUNT(*) FROM wells GROUP BY region;
|
What is the total claim amount for the 'South' region?
|
CREATE TABLE Claims (ClaimID INT,PolicyID INT,Amount INT,Region VARCHAR(10)); INSERT INTO Claims (ClaimID,PolicyID,Amount,Region) VALUES (1,101,500,'North'); INSERT INTO Claims (ClaimID,PolicyID,Amount,Region) VALUES (2,102,750,'South');
|
SELECT SUM(Amount) FROM Claims WHERE Region = 'South';
|
What is the average billing amount for attorneys in the 'billing' table, grouped by their specialty?
|
CREATE TABLE attorneys (attorney_id INT,specialty VARCHAR(255)); CREATE TABLE billing (bill_id INT,attorney_id INT,amount DECIMAL(10,2));
|
SELECT a.specialty, AVG(b.amount) FROM attorneys a INNER JOIN billing b ON a.attorney_id = b.attorney_id GROUP BY a.specialty;
|
What is the combined data usage in GB for the 'West' region and 'Canada' country for the last month?
|
CREATE TABLE usage_data (subscriber_id INT,region VARCHAR(20),country VARCHAR(20),usage_gb DECIMAL(10,2)); INSERT INTO usage_data (subscriber_id,region,country,usage_gb) VALUES (1,'West',NULL,10.5),(2,NULL,'Canada',7.3);
|
SELECT SUM(usage_gb) FROM usage_data WHERE region = 'West' OR country = 'Canada' AND usage_date >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH);
|
What is the total duration of all classical songs?
|
CREATE TABLE songs (id INT,title TEXT,length FLOAT,genre TEXT); INSERT INTO songs (id,title,length,genre) VALUES (1,'Song1',3.2,'classical'),(2,'Song2',4.1,'rock'),(3,'Song3',3.8,'pop'),(4,'Song4',2.1,'classical'),(5,'Song5',5.3,'classical');
|
SELECT SUM(length) FROM songs WHERE genre = 'classical';
|
What is the average age of readers who prefer digital newspapers in 'CityNews' and 'DailyDigest'?
|
CREATE TABLE CityNews (id INT,reader_age INT,preference VARCHAR(20)); CREATE TABLE DailyDigest (id INT,reader_age INT,preference VARCHAR(20));
|
SELECT AVG(cn.reader_age) as avg_age FROM CityNews cn INNER JOIN DailyDigest dd ON cn.id = dd.id WHERE cn.preference = 'digital' AND dd.preference = 'digital';
|
What is the average engine power level for each manufacturer, and how many aircraft and satellites have been produced by them?
|
CREATE TABLE Manufacturer_Stats (Manufacturer_ID INT,Avg_Engine_Power DECIMAL(5,2),Aircraft_Count INT,Satellites_Count INT);
|
SELECT Manufacturers.Manufacturer, AVG(Engines.Power_Level) AS Avg_Engine_Power, COUNT(DISTINCT Aircraft.Aircraft_ID) AS Aircraft_Count, COUNT(DISTINCT Satellites.Satellite_ID) AS Satellites_Count FROM Manufacturers LEFT JOIN Engines ON Manufacturers.Manufacturer_ID = Engines.Manufacturer_ID LEFT JOIN Aircraft ON Manufacturers.Manufacturer_ID = Aircraft.Manufacturer_ID LEFT JOIN Satellites ON Manufacturers.Manufacturer_ID = Satellites.Manufacturer_ID GROUP BY Manufacturers.Manufacturer_ID;
|
Insert a new manufacturer 'SustainableFabrics' in the 'Americas' region with 'No' FairTrade status.
|
CREATE TABLE Manufacturers (ManufacturerID INT,ManufacturerName VARCHAR(50),Region VARCHAR(50),FairTrade VARCHAR(5));
|
INSERT INTO Manufacturers (ManufacturerID, ManufacturerName, Region, FairTrade) VALUES (5, 'SustainableFabrics', 'Americas', 'No');
|
What are the names of the aircraft manufactured by companies located in the USA, excluding military aircraft?
|
CREATE TABLE Aircraft (AircraftID INT,AircraftName VARCHAR(50),ManufacturerID INT,Type VARCHAR(50));
|
SELECT AircraftName FROM Aircraft JOIN AircraftManufacturers ON Aircraft.ManufacturerID = AircraftManufacturers.ID WHERE Type != 'Military' AND Country = 'USA';
|
How many Mars rovers has NASA deployed?
|
CREATE TABLE MarsRovers (Id INT,Name VARCHAR(50),Operator VARCHAR(50),LaunchYear INT); INSERT INTO MarsRovers (Id,Name,Operator,LaunchYear) VALUES (1,'Sojourner','NASA',1996),(2,'Spirit','NASA',2003),(3,'Opportunity','NASA',2003),(4,'Curiosity','NASA',2011),(5,'Perseverance','NASA',2020);
|
SELECT COUNT(*) FROM MarsRovers WHERE Operator = 'NASA';
|
Which graduate students have received research grants from the department of Education in the amount greater than $10,000?
|
CREATE TABLE students (student_id INT,name TEXT,department TEXT); INSERT INTO students (student_id,name,department) VALUES (1,'Alice Johnson','Computer Science'),(2,'Bob Brown','Education'); CREATE TABLE grants (grant_id INT,student_id INT,department TEXT,amount INT); INSERT INTO grants (grant_id,student_id,department,amount) VALUES (1,1,'Health',5000),(2,2,'Education',15000);
|
SELECT s.name, g.amount FROM students s INNER JOIN grants g ON s.student_id = g.student_id WHERE g.department = 'Education' AND g.amount > 10000;
|
How many travel advisories were issued for Japan in the last 6 months?
|
CREATE TABLE travel_advisories (id INT,country VARCHAR(50),issue_date DATE); INSERT INTO travel_advisories (id,country,issue_date) VALUES (1,'Japan','2022-01-05'),(2,'Japan','2021-12-10'),(3,'Japan','2021-07-20');
|
SELECT COUNT(*) FROM travel_advisories WHERE country = 'Japan' AND issue_date >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH);
|
What is the daily count and average severity of high incidents in Africa?
|
CREATE TABLE incidents(id INT,date DATE,severity VARCHAR(10),country VARCHAR(50),attack_vector VARCHAR(50)); INSERT INTO incidents(id,date,severity,country,attack_vector) VALUES (1,'2021-01-01','high','Egypt','malware'),(2,'2021-01-02','medium','South Africa','phishing');
|
SELECT date, COUNT(*) as total_incidents, AVG(severity = 'high'::int) as avg_high_severity FROM incidents WHERE country = 'Africa' GROUP BY date ORDER BY date;
|
What is the total funding received by each biotech startup?
|
CREATE SCHEMA if not exists biotech;CREATE TABLE if not exists biotech.startups(id INT,name TEXT,location TEXT,funding FLOAT);INSERT INTO biotech.startups (id,name,location,funding) VALUES (1,'StartupA','US',5000000),(2,'StartupB','UK',3000000),(3,'StartupC','UK',4000000);
|
SELECT name, SUM(funding) FROM biotech.startups GROUP BY name;
|
How many unique donors funded the 'Youth Art Education' program in 2021?
|
CREATE TABLE donors (id INT PRIMARY KEY,name VARCHAR(50),donation_amount DECIMAL(10,2),donation_date DATE); CREATE TABLE program_funding (donor_id INT,program_name VARCHAR(50),funding_year INT);
|
SELECT COUNT(DISTINCT donor_id) AS num_unique_donors FROM donors INNER JOIN program_funding ON donors.id = program_funding.donor_id WHERE program_name = 'Youth Art Education' AND funding_year = 2021;
|
What is the most common type of cancer in each state, and how many cases were reported for that type of cancer?
|
CREATE TABLE CancerData (State VARCHAR(255),CancerType VARCHAR(255),Cases DECIMAL(10,2)); INSERT INTO CancerData (State,CancerType,Cases) VALUES ('State A','Breast',1200.00),('State A','Lung',1100.00),('State A','Colon',800.00),('State B','Breast',1400.00),('State B','Lung',1000.00),('State B','Colon',1100.00);
|
SELECT State, CancerType, Cases FROM CancerData WHERE (State, CancerType) IN (SELECT State, MAX(Cases) FROM CancerData GROUP BY State);
|
How many customers in each age group have made a purchase in the past year, grouped by their preferred sustainable fabric type?
|
CREATE TABLE Customers (CustomerID INT,Age INT,PreferredFabric TEXT); INSERT INTO Customers (CustomerID,Age,PreferredFabric) VALUES (1,25,'Organic Cotton'),(2,35,'Recycled Polyester'),(3,45,'Hemp'),(4,55,'Polyester');
|
SELECT PreferredFabric, Age, COUNT(DISTINCT Customers.CustomerID) FROM Customers INNER JOIN Purchases ON Customers.CustomerID = Purchases.CustomerID WHERE Purchases.PurchaseDate BETWEEN '2021-01-01' AND '2022-12-31' GROUP BY PreferredFabric, Age;
|
What are the total sales for a specific brand?
|
CREATE TABLE if not exists sales (id INT PRIMARY KEY,product_id INT,purchase_date DATE,quantity INT,price DECIMAL(5,2)); INSERT INTO sales (id,product_id,purchase_date,quantity,price) VALUES (1,1,'2022-01-01',5,12.99); CREATE TABLE if not exists product (id INT PRIMARY KEY,name TEXT,brand_id INT,price DECIMAL(5,2)); INSERT INTO product (id,name,brand_id,price) VALUES (1,'Solid Shampoo Bar',1,12.99); CREATE TABLE if not exists brand (id INT PRIMARY KEY,name TEXT,category TEXT,country TEXT); INSERT INTO brand (id,name,category,country) VALUES (1,'Lush','Cosmetics','United Kingdom');
|
SELECT SUM(quantity * price) FROM sales JOIN product ON sales.product_id = product.id JOIN brand ON product.brand_id = brand.id WHERE brand.name = 'Lush';
|
Calculate the average response time for natural disasters in the second half of 2019
|
CREATE TABLE natural_disasters (id INT,disaster_date DATE,response_time INT); INSERT INTO natural_disasters (id,disaster_date,response_time) VALUES (1,'2019-07-01',12),(2,'2019-08-01',15),(3,'2019-12-25',18);
|
SELECT AVG(response_time) as avg_response_time FROM natural_disasters WHERE disaster_date BETWEEN '2019-07-01' AND '2019-12-31';
|
How many heritage sites are there in each country?
|
CREATE TABLE heritage_sites (id INT,site_name VARCHAR(255),country VARCHAR(255),year INT); INSERT INTO heritage_sites (id,site_name,country,year) VALUES (1,'Taj Mahal','India',1653),(2,'Machu Picchu','Peru',1460);
|
SELECT country, COUNT(*) FROM heritage_sites GROUP BY country;
|
How many transactions were made by each client in Q1 of 2021?
|
CREATE TABLE clients (client_id INT,name VARCHAR(50)); CREATE TABLE transactions (transaction_id INT,client_id INT,date DATE); INSERT INTO clients (client_id,name) VALUES (1,'John Doe'),(2,'Jane Smith'); INSERT INTO transactions (transaction_id,client_id,date) VALUES (1,1,'2021-01-01'),(2,1,'2021-01-15'),(3,2,'2021-01-30');
|
SELECT c.client_id, c.name, COUNT(*) FROM clients c INNER JOIN transactions t ON c.client_id = t.client_id WHERE t.date BETWEEN '2021-01-01' AND '2021-03-31' GROUP BY c.client_id, c.name;
|
What is the percentage of projects in the 'Renewable Energy' sector for each year since 2018?
|
CREATE TABLE projects (id INT,name VARCHAR(255),sector VARCHAR(255),project_start_date DATE);
|
SELECT YEAR(project_start_date) AS year, (COUNT(*) FILTER (WHERE sector = 'Renewable Energy')) * 100.0 / COUNT(*) AS percentage FROM projects WHERE YEAR(project_start_date) >= 2018 GROUP BY year;
|
Find the total revenue for the West coast region.
|
CREATE TABLE sales (id INT,location VARCHAR(20),quantity INT,price DECIMAL(5,2)); INSERT INTO sales (id,location,quantity,price) VALUES (1,'Northeast',50,12.99),(2,'Midwest',75,19.99),(3,'West',35,14.49);
|
SELECT SUM(quantity * price) AS total_revenue FROM sales WHERE location = 'West';
|
List the top 5 states with the highest total sales of sativa strains.
|
CREATE TABLE sales (strain_type VARCHAR(10),state VARCHAR(20),total_sales INT); INSERT INTO sales (strain_type,state,total_sales) VALUES ('sativa','California',500); INSERT INTO sales (strain_type,state,total_sales) VALUES ('sativa','Colorado',400); INSERT INTO sales (strain_type,state,total_sales) VALUES ('sativa','Washington',300); INSERT INTO sales (strain_type,state,total_sales) VALUES ('sativa','Oregon',200); INSERT INTO sales (strain_type,state,total_sales) VALUES ('sativa','Nevada',100);
|
SELECT state, SUM(total_sales) AS total_sales FROM sales WHERE strain_type = 'sativa' GROUP BY state ORDER BY total_sales DESC LIMIT 5;
|
List the top 5 most popular workouts by duration in April 2022.'
|
CREATE SCHEMA workouts; CREATE TABLE workout_durations (workout_id INT,workout_name VARCHAR(50),duration INT,duration_unit VARCHAR(10),workout_date DATE); INSERT INTO workout_durations VALUES (1,'Yoga',60,'minutes','2022-04-01'),(2,'Cycling',45,'minutes','2022-04-02'),(3,'Pilates',45,'minutes','2022-04-03'),(4,'Running',30,'minutes','2022-04-04'),(5,'Swimming',60,'minutes','2022-04-05');
|
SELECT workout_name, SUM(duration) as total_duration FROM workouts.workout_durations WHERE workout_date >= '2022-04-01' AND workout_date <= '2022-04-30' GROUP BY workout_name ORDER BY total_duration DESC LIMIT 5;
|
Update the average salary for the 'metalwork' department in the 'factory1' to 3200.00.
|
CREATE TABLE factories (factory_id INT,department VARCHAR(255),worker_count INT,average_salary DECIMAL(10,2)); INSERT INTO factories VALUES (1,'textiles',50,2500.00),(2,'metalwork',30,3000.00);
|
UPDATE factories SET average_salary = 3200.00 WHERE factory_id = 1 AND department = 'metalwork';
|
What is the number of users registered in each hour of the day?
|
CREATE TABLE user_registrations (registration_time TIMESTAMP); INSERT INTO user_registrations (registration_time) VALUES ('2021-01-01 10:30:00'),('2021-01-01 12:20:00'),('2021-01-01 13:10:00'),('2021-01-02 09:05:00'),('2021-01-02 10:40:00'),('2021-01-02 11:35:00');
|
SELECT EXTRACT(HOUR FROM registration_time) AS hour, COUNT(*) FROM user_registrations GROUP BY hour;
|
What is the total network investment in the telecom sector for the current year?
|
CREATE TABLE network_investments (investment_id INT,investment_amount DECIMAL(10,2),investment_date DATE,sector VARCHAR(255));
|
SELECT SUM(investment_amount) as total_investment FROM network_investments WHERE sector = 'telecom' AND investment_date >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR);
|
What are the client demographics for cases with a positive outcome?
|
CREATE TABLE cases (case_id INT,client_id INT,outcome VARCHAR(10)); CREATE TABLE clients (client_id INT,age INT,gender VARCHAR(6),income DECIMAL(10,2)); INSERT INTO cases (case_id,client_id,outcome) VALUES (1,1,'Positive'),(2,2,'Negative'); INSERT INTO clients (client_id,age,gender,income) VALUES (1,35,'Female',50000.00),(2,45,'Male',60000.00);
|
SELECT c.age, c.gender, c.income FROM clients c JOIN cases cs ON c.client_id = cs.client_id WHERE cs.outcome = 'Positive';
|
Which traditional dances in the Caribbean region have more than 2000 annual participants?
|
CREATE TABLE DanceForms (id INT,name VARCHAR(50),region VARCHAR(50)); INSERT INTO DanceForms (id,name,region) VALUES (1,'Bomba','Caribbean'),(2,'Plena','Caribbean'),(3,'Merengue','Caribbean'),(4,'Bachata','Caribbean'),(5,'Salsa','Caribbean'); CREATE TABLE Dancers (id INT,dance_form_id INT,name VARCHAR(50),annual_participants INT); INSERT INTO Dancers (id,dance_form_id,name,annual_participants) VALUES (1,1,'Ana',2500),(2,2,'Ben',1800),(3,3,'Carla',1200),(4,4,'Diego',2300),(5,5,'Elena',1900);
|
SELECT df.name, df.region FROM DanceForms df JOIN Dancers d ON df.id = d.dance_form_id WHERE d.annual_participants > 2000;
|
Find the top 3 routes with the most packages shipped in 2021?
|
CREATE TABLE packages (route_id INT,route_name VARCHAR(255),shipped_qty INT,shipped_year INT); INSERT INTO packages (route_id,route_name,shipped_qty,shipped_year) VALUES (1,'NYC to LA',500,2021),(2,'LA to NYC',550,2021),(3,'NYC to CHI',400,2021);
|
SELECT route_name, SUM(shipped_qty) as total_shipped FROM packages WHERE shipped_year = 2021 GROUP BY route_name ORDER BY total_shipped DESC LIMIT 3;
|
What is the total budget for intelligence operations for the year 2022?
|
CREATE TABLE budget (category TEXT,year INT,amount INT); INSERT INTO budget (category,year,amount) VALUES ('intelligence operations',2022,10000000); INSERT INTO budget (category,year,amount) VALUES ('military technology',2022,15000000);
|
SELECT SUM(amount) FROM budget WHERE category = 'intelligence operations' AND year = 2022;
|
Calculate the total visitor count for exhibitions held in Tokyo and Seoul.
|
CREATE TABLE ExhibitionLocations (exhibition_id INT,city VARCHAR(20),visitor_count INT); INSERT INTO ExhibitionLocations (exhibition_id,city,visitor_count) VALUES (1,'Tokyo',50),(2,'Tokyo',75),(3,'Seoul',100),(4,'Paris',120);
|
SELECT SUM(visitor_count) FROM ExhibitionLocations WHERE city IN ('Tokyo', 'Seoul');
|
Update the "topic" of the training with id 1 in the "ai_ethics_trainings" table to 'AI bias and fairness'
|
CREATE TABLE ai_ethics_trainings (id INT PRIMARY KEY,date DATE,topic VARCHAR(255),description VARCHAR(255));
|
WITH updated_data AS (UPDATE ai_ethics_trainings SET topic = 'AI bias and fairness' WHERE id = 1 RETURNING *) SELECT * FROM updated_data;
|
Find the total quantity of Terbium imported to Asian countries before 2018 and the number of unique importers.
|
CREATE TABLE imports (id INT,country VARCHAR(50),Terbium_imported FLOAT,importer_id INT,datetime DATETIME); INSERT INTO imports (id,country,Terbium_imported,importer_id,datetime) VALUES (1,'China',120.0,500,'2017-01-01 10:00:00'),(2,'Japan',90.0,350,'2017-02-15 14:30:00');
|
SELECT country, SUM(Terbium_imported) AS total_Terbium, COUNT(DISTINCT importer_id) AS unique_importers FROM imports WHERE YEAR(datetime) < 2018 AND Terbium_imported IS NOT NULL AND country LIKE 'Asia%' GROUP BY country;
|
How many items were shipped from each warehouse in January 2022?
|
CREATE TABLE warehouse (id VARCHAR(5),name VARCHAR(10),location VARCHAR(15)); INSERT INTO warehouse (id,name,location) VALUES ('W01','BOS','Boston'),('W02','NYC','New York'),('W03','SEA','Seattle'); CREATE TABLE shipment (id INT,warehouse_id VARCHAR(5),destination VARCHAR(10),weight INT,shipped_date DATE); INSERT INTO shipment (id,warehouse_id,destination,weight,shipped_date) VALUES (1,'SEA','NYC',100,'2022-01-05'),(2,'SEA','LAX',200,'2022-01-10'),(3,'SEA','CHI',150,'2022-01-15'),(4,'NYC','MIA',50,'2022-01-20');
|
SELECT w.location, COUNT(s.id) FROM shipment s JOIN warehouse w ON s.warehouse_id = w.id WHERE s.shipped_date >= '2022-01-01' AND s.shipped_date < '2022-02-01' GROUP BY w.location;
|
Delete records of vehicles with missing production dates.
|
CREATE TABLE vehicle (id INT PRIMARY KEY,name VARCHAR(255),production_date DATE); INSERT INTO vehicle (id,name,production_date) VALUES (1,'Tesla Model S','2012-06-22'),(2,'Nissan Leaf',NULL),(3,'Chevrolet Bolt','2016-12-13');
|
DELETE FROM vehicle WHERE production_date IS NULL;
|
What is the average CO2 emission reduction (in metric tons) for wind projects that came online in 2021?
|
CREATE TABLE if not exists wind_projects (project_id integer,project_start_date date,co2_emission_reduction_tons integer); INSERT INTO wind_projects (project_id,project_start_date,co2_emission_reduction_tons) VALUES (1,'2021-01-01',1000),(2,'2021-06-01',2000),(3,'2021-12-31',1500);
|
SELECT AVG(co2_emission_reduction_tons) as avg_reduction FROM wind_projects WHERE project_start_date BETWEEN '2021-01-01' AND '2021-12-31';
|
Which countries have the lowest number of suppliers with organic products in the SupplyChainTransparency table?
|
CREATE TABLE SupplyChainTransparency(supplier_id INT,supplier_country VARCHAR(50),is_organic BOOLEAN);
|
SELECT supplier_country, COUNT(*) as num_suppliers FROM SupplyChainTransparency WHERE is_organic = TRUE GROUP BY supplier_country ORDER BY num_suppliers ASC LIMIT 1;
|
What was the total revenue for the "Premium" product line in Q3 2021?
|
CREATE TABLE sales (product_line VARCHAR(10),date DATE,revenue FLOAT); INSERT INTO sales (product_line,date,revenue) VALUES ('Premium','2021-07-01',6000),('Basic','2021-07-01',4000),('Premium','2021-07-02',7000),('Basic','2021-07-02',5000);
|
SELECT SUM(revenue) FROM sales WHERE product_line = 'Premium' AND date BETWEEN '2021-07-01' AND '2021-09-30';
|
Delete safety records with missing safety_inspection_date
|
CREATE TABLE safety_records (safety_record_id INT,vessel_id INT,safety_inspection_date DATE); INSERT INTO safety_records (safety_record_id,vessel_id,safety_inspection_date) VALUES (1,1,'2022-03-01'),(2,3,'2022-05-15'),(3,5,NULL);
|
DELETE FROM safety_records WHERE safety_inspection_date IS NULL;
|
How many production licenses were issued in Colorado and Oregon?
|
CREATE TABLE Licenses (LicenseID INT,State TEXT,Type TEXT); INSERT INTO Licenses (LicenseID,State,Type) VALUES (1,'Colorado','Production'); INSERT INTO Licenses (LicenseID,State,Type) VALUES (2,'Oregon','Production');
|
SELECT COUNT(*) FROM Licenses WHERE State IN ('Colorado', 'Oregon') AND Type = 'Production';
|
What is the name of the volunteer with the most hours in the 'Environment' department?
|
CREATE TABLE Volunteers (VolunteerID INT,VolunteerName TEXT,Department TEXT,Hours DECIMAL); INSERT INTO Volunteers (VolunteerID,VolunteerName,Department,Hours) VALUES (1,'Alice','Environment',50),(2,'Bob','Marketing',25),(3,'Charlie','Environment',75),(4,'David','Arts',100);
|
SELECT VolunteerName FROM Volunteers WHERE Department = 'Environment' AND Hours = (SELECT MAX(Hours) FROM Volunteers WHERE Department = 'Environment');
|
List all the transactions that occurred in the last month in the ethical labor practices retail sector.
|
CREATE TABLE Transactions (transactionID int,transactionDate datetime,retailSector varchar(255)); INSERT INTO Transactions VALUES (1,'2022-01-01','ethical labor practices');
|
SELECT * FROM Transactions WHERE transactionDate >= DATE_SUB(NOW(), INTERVAL 1 MONTH) AND retailSector = 'ethical labor practices';
|
Identify the most common disinformation topic in the past week.
|
CREATE TABLE Disinformation (ID INT,Topic TEXT,Date DATE); INSERT INTO Disinformation (ID,Topic,Date) VALUES (1,'Politics','2022-01-01'),(2,'Health','2022-01-05'),(3,'Politics','2022-01-07');
|
SELECT Topic, COUNT(*) as Count FROM Disinformation WHERE Date >= DATEADD(week, -1, CURRENT_DATE) GROUP BY Topic ORDER BY Count DESC LIMIT 1;
|
Update the wage for garment worker with ID 3002 to $160.00
|
CREATE TABLE Wages (id INT,worker_id INT,country VARCHAR(255),wage DECIMAL(10,2)); INSERT INTO Wages (id,worker_id,country,wage) VALUES (1,3001,'Vietnam',120.00),(2,3002,'Cambodia',150.00),(3,3003,'Vietnam',130.00);
|
UPDATE Wages SET wage = 160.00 WHERE worker_id = 3002;
|
What is the most common age range for patients diagnosed with anxiety?
|
CREATE TABLE diagnoses (id INT,patient_id INT,condition VARCHAR(255)); CREATE TABLE patients (id INT,age INT,country VARCHAR(255)); INSERT INTO diagnoses (id,patient_id,condition) VALUES (1,1,'Anxiety'),(2,2,'Depression'),(3,3,'Bipolar'); INSERT INTO patients (id,age,country) VALUES (1,35,'USA'),(2,42,'Canada'),(3,28,'Mexico'),(4,22,'USA'),(5,31,'Canada');
|
SELECT FLOOR(age / 10) * 10 AS age_range, COUNT(*) FROM patients JOIN diagnoses ON patients.id = diagnoses.patient_id WHERE condition = 'Anxiety' GROUP BY age_range ORDER BY COUNT(*) DESC LIMIT 1;
|
How many candidates from underrepresented communities were hired in the last year?
|
CREATE TABLE Candidates (CandidateID INT,Community VARCHAR(30),HireDate DATE); INSERT INTO Candidates (CandidateID,Community,HireDate) VALUES (4,'Underrepresented','2022-03-15');
|
SELECT COUNT(*) FROM Candidates WHERE Community = 'Underrepresented' AND HireDate BETWEEN DATE_SUB(CURDATE(), INTERVAL 1 YEAR) AND CURDATE();
|
What is the total number of wildlife sightings in Yukon and Northwest Territories?
|
CREATE TABLE WildlifeSightings (id INT,territory VARCHAR(20),animal VARCHAR(20),sighted_date DATE); INSERT INTO WildlifeSightings (id,territory,animal,sighted_date) VALUES (1,'Yukon','Moose','2021-07-01'); INSERT INTO WildlifeSightings (id,territory,animal,sighted_date) VALUES (2,'Northwest Territories','Caribou','2021-08-10');
|
SELECT SUM(signcount) FROM (SELECT CASE WHEN territory IN ('Yukon', 'Northwest Territories') THEN 1 ELSE 0 END AS signcount FROM WildlifeSightings) AS subquery;
|
Update the 'location' column to 'San Francisco Bay Area' in the 'ports' table for the port with id = 2
|
CREATE TABLE ports (id INT,name VARCHAR(50),country VARCHAR(20),location VARCHAR(50)); INSERT INTO ports (id,name,country,location) VALUES (1,'Port of Tokyo','Japan','Tokyo'); INSERT INTO ports (id,name,country,location) VALUES (2,'Port of San Francisco','USA','San Francisco');
|
UPDATE ports SET location = 'San Francisco Bay Area' WHERE id = 2;
|
What is the total number of flight hours for all Boeing 737 aircraft?
|
CREATE TABLE Aircraft (Id INT,Name VARCHAR(50),Manufacturer VARCHAR(50),FlightHours INT); INSERT INTO Aircraft (Id,Name,Manufacturer,FlightHours) VALUES (1,'737-100','Boeing',30000),(2,'737-200','Boeing',50000),(3,'737-300','Boeing',70000),(4,'737-400','Boeing',80000),(5,'737-500','Boeing',90000),(6,'737-600','Boeing',100000),(7,'737-700','Boeing',120000),(8,'737-800','Boeing',140000),(9,'737-900','Boeing',160000);
|
SELECT SUM(FlightHours) FROM Aircraft WHERE Name LIKE '737%' AND Manufacturer = 'Boeing';
|
Which countries have the highest and lowest usage of ethical labor practices?
|
CREATE TABLE labor_practices (country VARCHAR(255),ethical_practice BOOLEAN); INSERT INTO labor_practices (country,ethical_practice) VALUES ('US',TRUE),('China',FALSE),('Bangladesh',FALSE),('Italy',TRUE);
|
SELECT country, CASE WHEN ethical_practice = TRUE THEN 'High' ELSE 'Low' END as labor_practice_rank FROM labor_practices;
|
What is the total revenue of companies that use sustainable materials?
|
CREATE TABLE company_sales (id INT,company VARCHAR(100),sustainable_materials BOOLEAN,revenue DECIMAL(10,2)); INSERT INTO company_sales (id,company,sustainable_materials,revenue) VALUES (1,'Company A',TRUE,1000000),(2,'Company B',FALSE,500000),(3,'Company C',TRUE,2000000);
|
SELECT SUM(revenue) FROM company_sales WHERE sustainable_materials = TRUE;
|
What is the total number of veteran hires in the defense industry in the last quarter, broken down by job title?
|
CREATE TABLE veteran_hires (id INT,hire_number VARCHAR(255),industry VARCHAR(255),job_title VARCHAR(255),date DATE);
|
SELECT industry, job_title, COUNT(*) FROM veteran_hires WHERE industry = 'defense' AND date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH) GROUP BY industry, job_title;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.