instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
Create a table for mental health treatment approaches | CREATE TABLE mental_health_treatment_approaches (id INT PRIMARY KEY,name VARCHAR(255),description TEXT); | CREATE TABLE mental_health_treatment_approaches (id INT PRIMARY KEY, name VARCHAR(255), description TEXT); |
How many esports events were held in Tokyo and New York? | CREATE TABLE Events (EventID INT,City VARCHAR(20)); INSERT INTO Events (EventID,City) VALUES (1,'Tokyo'),(2,'Los Angeles'),(3,'New York'),(4,'Paris'); | SELECT COUNT(*) FROM Events WHERE City IN ('Tokyo', 'New York'); |
What is the total number of hospital beds in hospitals in New Delhi? | CREATE TABLE Hospitals (HospitalID INT,Name VARCHAR(50),City VARCHAR(30),Country VARCHAR(20),TotalBeds INT); INSERT INTO Hospitals (HospitalID,Name,City,Country,TotalBeds) VALUES (3,'AIIMS','New Delhi','India',2000); INSERT INTO Hospitals (HospitalID,Name,City,Country,TotalBeds) VALUES (4,'Fortis','New Delhi','India',1500); | SELECT SUM(TotalBeds) FROM Hospitals WHERE City = 'New Delhi'; |
Find the number of wells drilled in each country in 2020 | CREATE TABLE wells (id INT,country VARCHAR(50),drill_date DATE); INSERT INTO wells (id,country,drill_date) VALUES (1,'USA','2020-01-01'); INSERT INTO wells (id,country,drill_date) VALUES (2,'Canada','2020-02-15'); | SELECT country, COUNT(*) as num_wells FROM wells WHERE YEAR(drill_date) = 2020 GROUP BY country; |
What are the top 5 most read articles in 2015? | CREATE TABLE Articles (id INT,title VARCHAR(255),read_count INT); INSERT INTO Articles (id,title,read_count) VALUES (1,'Article 1',100),(2,'Article 2',200),(3,'Article 3',300),(4,'Article 4',400),(5,'Article 5',500); | SELECT * FROM Articles WHERE YEAR(publish_date) = 2015 ORDER BY read_count DESC LIMIT 5; |
Identify genetic research studies that use CRISPR technology and are conducted in the US or Canada? | CREATE SCHEMA if not exists genetics; CREATE TABLE if not exists genetics.studies (id INT,name VARCHAR(255),location VARCHAR(255),technology VARCHAR(255)); INSERT INTO genetics.studies (id,name,location,technology) VALUES (1,'Study1','Country1','CRISPR'),(2,'Study2','Country2','AnotherTech'); | SELECT name FROM genetics.studies WHERE technology = 'CRISPR' AND (location = 'US' OR location = 'Canada'); |
What is the total construction labor cost for electricians in Florida? | CREATE TABLE construction_labor (state VARCHAR(20),job VARCHAR(50),cost FLOAT); INSERT INTO construction_labor VALUES ('Florida','Electrician',52.0),('Florida','Electrician',53.0),('Florida','Carpenter',48.0); | SELECT SUM(cost) FROM construction_labor WHERE state = 'Florida' AND job = 'Electrician'; |
What is the total budget allocated to health and education services in 2020, in 'CityA'? | CREATE TABLE CityA_Budget (Year INT,Service VARCHAR(20),Budget FLOAT); INSERT INTO CityA_Budget (Year,Service,Budget) VALUES (2020,'Health',5000000),(2020,'Education',7000000); | SELECT SUM(Budget) FROM CityA_Budget WHERE Year = 2020 AND Service IN ('Health', 'Education'); |
Display the number of accessible and non-accessible stations for each public transportation mode | CREATE TABLE station_accessibility (station_id INT,mode VARCHAR(10),accessible BOOLEAN); | SELECT mode, SUM(accessible) AS accessible_stations, SUM(NOT accessible) AS non_accessible_stations FROM station_accessibility GROUP BY mode; |
What is the average pH value for each location in the 'WaterQuality' table in the last month? | CREATE TABLE WaterQuality (ID INT,LocationID INT,MeasurementDate DATE,pH FLOAT,Turbidity FLOAT); INSERT INTO WaterQuality (ID,LocationID,MeasurementDate,pH,Turbidity) VALUES (1,1,'2022-07-20',7.5,30); INSERT INTO WaterQuality (ID,LocationID,MeasurementDate,pH,Turbidity) VALUES (2,2,'2022-07-25',7.2,20); | SELECT LocationID, AVG(pH) FROM WaterQuality WHERE MeasurementDate BETWEEN DATEADD(month, -1, GETDATE()) AND GETDATE() GROUP BY LocationID; |
What is the total biomass of fish in each farm, ranked by the most to least? | CREATE TABLE fish_farms (id INT,name VARCHAR(255)); INSERT INTO fish_farms (id,name) VALUES (1,'Farm A'),(2,'Farm B'),(3,'Farm C'); CREATE TABLE fish_inventory (id INT,farm_id INT,species_id INT,biomass FLOAT); INSERT INTO fish_inventory (id,farm_id,species_id,biomass) VALUES (1,1,1,1000),(2,1,2,800),(3,2,1,1200),(4,3,2,900),(5,1,3,1500); | SELECT f.name, SUM(fi.biomass) as total_biomass FROM fish_inventory fi JOIN fish_farms f ON fi.farm_id = f.id GROUP BY f.name ORDER BY SUM(fi.biomass) DESC; |
What is the average number of workplace safety incidents for unions in the 'technology' sector? | CREATE TABLE union_stats (id INT,union_name VARCHAR(30),sector VARCHAR(20),num_safety_incidents INT); INSERT INTO union_stats (id,union_name,sector,num_safety_incidents) VALUES (1,'Union A','technology',15),(2,'Union B','education',8),(3,'Union C','technology',3); | SELECT AVG(num_safety_incidents) FROM union_stats WHERE sector = 'technology'; |
What is the average price of sustainable skincare products in France? | CREATE TABLE SkincareSales (product_id INT,product_name VARCHAR(100),category VARCHAR(50),price DECIMAL(10,2),quantity INT,sale_date DATE,country VARCHAR(50),sustainable BOOLEAN); | SELECT AVG(price) FROM SkincareSales WHERE category = 'Skincare' AND country = 'France' AND sustainable = TRUE; |
How many IoT devices are active in region 'East'? | CREATE TABLE IoTDevices (device_id INT,device_type VARCHAR(20),region VARCHAR(10)); INSERT INTO IoTDevices (device_id,device_type,region) VALUES (1,'Soil Moisture Sensor','West'); INSERT INTO IoTDevices (device_id,device_type,region) VALUES (2,'Light Sensor','East'); INSERT INTO IoTDevices (device_id,device_type,region) VALUES (3,'Temperature Sensor','North'); | SELECT COUNT(*) FROM IoTDevices WHERE region = 'East'; |
Which country had the least total number of shipments in 'July 2022'? | CREATE TABLE Shipments (country varchar(20),shipment_date date); INSERT INTO Shipments (country,shipment_date) VALUES ('Country A','2022-07-01'),('Country B','2022-07-02'); | SELECT country, MIN(SUM(CASE WHEN EXTRACT(MONTH FROM shipment_date) = 7 AND EXTRACT(YEAR FROM shipment_date) = 2022 THEN 1 ELSE 0 END)) OVER () AS total_shipments_all_countries FROM (SELECT country, COUNT(*) AS total_shipments FROM Shipments GROUP BY country, EXTRACT(MONTH FROM shipment_date), EXTRACT(YEAR FROM shipment_date)) subquery WHERE EXTRACT(MONTH FROM shipment_date) = 7 AND EXTRACT(YEAR FROM shipment_date) = 2022 GROUP BY country ORDER BY total_shipments DESC LIMIT 1; |
Find the top 3 countries with the most satellites in orbit? | CREATE TABLE country_satellites (id INT,country VARCHAR(50),num_satellites INT); | SELECT country, num_satellites FROM (SELECT country, COUNT(*) AS num_satellites, RANK() OVER (ORDER BY COUNT(*) DESC) AS country_rank FROM satellites GROUP BY country) AS subquery WHERE country_rank <= 3; |
How many visitors attended the "Modern Art" exhibition in Tokyo last year? | CREATE TABLE Exhibition_Attendance (exhibition_id INT,city VARCHAR(50),year INT,visitor_count INT); | SELECT visitor_count FROM Exhibition_Attendance WHERE exhibition_id = 'Modern Art' AND city = 'Tokyo' AND year = 2021; |
Show all the defense contracts that have 'artificial intelligence' in their description? | CREATE TABLE Contracts (id INT,title VARCHAR(100),description TEXT); INSERT INTO Contracts (id,title,description) VALUES (1,'Artificial Intelligence Services','Artificial Intelligence for defense'),(2,'IT Infrastructure Upgrade','Network Infrastructure Upgrade'); | SELECT Contracts.id, Contracts.title, Contracts.description FROM Contracts WHERE Contracts.description LIKE '%artificial intelligence%'; |
Identify the top 3 states with the highest rural hospital readmission rates for patients with diabetes in the last year. | CREATE TABLE hospitals (id INT,state TEXT); CREATE TABLE readmissions (id INT,hospital_id INT,readmission_date DATE,diagnosis TEXT); | SELECT h.state, COUNT(*) AS readmissions FROM hospitals h JOIN readmissions r ON h.id = r.hospital_id WHERE diagnosis = 'Diabetes' AND readmission_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 1 YEAR) AND CURDATE() GROUP BY h.state ORDER BY readmissions DESC LIMIT 3; |
What is the earliest date of an intelligence operation in the 'intelligence_operations' table? | CREATE TABLE intelligence_operations (id INT,operation_date DATE); | SELECT MIN(operation_date) FROM intelligence_operations; |
What is the total number of animals in the rescue center from the 'Australian Outback' region? | CREATE TABLE rescue_center_animals (animal_id INT,animal_name VARCHAR(50),region VARCHAR(50)); INSERT INTO rescue_center_animals (animal_id,animal_name,region) VALUES (1,'Kangaroo','Australian Outback'); INSERT INTO rescue_center_animals (animal_id,animal_name,region) VALUES (2,'Emu','Australian Outback'); | SELECT COUNT(animal_id) FROM rescue_center_animals WHERE region = 'Australian Outback'; |
What is the number of traffic violations committed by each driver in New York City in 2020? | CREATE TABLE violations_2 (driver_id INT,violation_type VARCHAR(255),year INT); INSERT INTO violations_2 (driver_id,violation_type,year) VALUES (1,'Speeding',2020); INSERT INTO violations_2 (driver_id,violation_type,year) VALUES (1,'Reckless Driving',2020); | SELECT driver_id, COUNT(DISTINCT violation_type) OVER (PARTITION BY driver_id) as num_violations FROM violations_2 WHERE year = 2020 |
What is the total water usage in California, including both residential and agricultural sectors, for the year 2020? | CREATE TABLE residential_water_usage (id INT,state VARCHAR(20),year INT,usage FLOAT); CREATE TABLE agricultural_water_usage (id INT,state VARCHAR(20),year INT,usage FLOAT); | SELECT SUM(r.usage) + SUM(a.usage) AS total_usage FROM residential_water_usage r JOIN agricultural_water_usage a ON r.state = a.state AND r.year = a.year WHERE r.state = 'California' AND r.year = 2020; |
What is the total number of Mars rovers deployed by NASA? | CREATE TABLE mars_rovers (name TEXT,agency TEXT); INSERT INTO mars_rovers (name,agency) VALUES ('Sojourner','NASA'),('Spirit','NASA'),('Opportunity','NASA'),('Curiosity','NASA'); | SELECT COUNT(*) FROM mars_rovers WHERE agency = 'NASA'; |
What is the minimum funding amount for any pollution control initiative? | CREATE TABLE pollution_control_initiatives (initiative_name TEXT,funding_amount FLOAT); INSERT INTO pollution_control_initiatives (initiative_name,funding_amount) VALUES ('Clean Oceans Act',15000000.0),('Ocean Restoration Project',20000000.0),('Plastic Reduction Program',10000000.0); | SELECT MIN(funding_amount) FROM pollution_control_initiatives; |
Count the number of players for each game type | CREATE TABLE Players (PlayerID INT,PlayerName VARCHAR(50),GameType VARCHAR(50)); INSERT INTO Players (PlayerID,PlayerName,GameType) VALUES (1,'John Doe','FPS'); INSERT INTO Players (PlayerID,PlayerName,GameType) VALUES (2,'Jane Smith','RPG'); INSERT INTO Players (PlayerID,PlayerName,GameType) VALUES (3,'Mike Johnson','FPS'); | SELECT GameType, COUNT(*) FROM Players GROUP BY GameType; |
Delete all donations made in January 2023 | CREATE TABLE donations (donation_id INT,donor_id INT,donation_amount NUMERIC,donation_date DATE); INSERT INTO donations (donation_id,donor_id,donation_amount,donation_date) VALUES (1,1,100,'2023-01-01'),(2,2,200,'2023-01-15'),(3,3,50,'2023-02-01'),(4,4,300,'2023-03-15'); | DELETE FROM donations WHERE donation_date BETWEEN '2023-01-01' AND '2023-01-31'; |
What is the minimum quantity of garments sold online per transaction in the 'Tokyo' region? | CREATE TABLE sales (id INT PRIMARY KEY,transaction_date DATE,quantity_sold INT,payment_method VARCHAR(255),region VARCHAR(255)); | SELECT MIN(quantity_sold) as min_quantity_sold_online_per_transaction FROM sales WHERE region = 'Tokyo' AND payment_method IS NOT NULL; |
How many users have booked virtual city tours? | CREATE TABLE bookings (id INT PRIMARY KEY,user_id INT,tour_id INT,booked_date DATE); CREATE TABLE virtual_tours (id INT PRIMARY KEY,name VARCHAR(255)); ALTER TABLE bookings ADD FOREIGN KEY (tour_id) REFERENCES virtual_tours(id); | SELECT COUNT(*) FROM bookings INNER JOIN virtual_tours ON bookings.tour_id = virtual_tours.id WHERE virtual_tours.name LIKE '%Virtual City%'; |
What is the total number of tourists visiting sustainable destinations for each continent in 2023? | CREATE TABLE sustainable_destinations (id INT,destination VARCHAR(50),continent VARCHAR(50)); INSERT INTO sustainable_destinations (id,destination,continent) VALUES (1,'Bali','Asia'),(2,'Costa Rica','Americas'),(3,'Gorongosa National Park','Africa'),(4,'Dubrovnik','Europe'),(5,'Great Barrier Reef','Australia'); CREATE TABLE tourists_2023 (id INT,destination VARCHAR(50),num_tourists INT); INSERT INTO tourists_2023 (id,destination,num_tourists) VALUES (1,'Bali',1800),(2,'Costa Rica',2200),(3,'Gorongosa National Park',500),(4,'Dubrovnik',3000),(5,'Great Barrier Reef',4000); | SELECT s.continent, SUM(t2023.num_tourists) AS total_tourists FROM sustainable_destinations s JOIN tourists_2023 t2023 ON s.destination = t2023.destination GROUP BY s.continent; |
Show the number of hospital beds in "Oregon" state | CREATE TABLE hospital_beds(id INT,hospital_name TEXT,state TEXT,num_beds INT); INSERT INTO hospital_beds(id,hospital_name,state,num_beds) VALUES (1,'Oregon Medical Center','Oregon',600),(2,'Rural Health Clinic','Oregon',40),(3,'Portland Health Care','Oregon',750),(4,'Salem Hospital','Oregon',500); | SELECT state, SUM(num_beds) FROM hospital_beds WHERE state = 'Oregon' GROUP BY state; |
What is the average age of members in unions that have a collective bargaining agreement? | CREATE TABLE union_membership (member_id INT,union_id INT,age INT); INSERT INTO union_membership (member_id,union_id,age) VALUES (1,101,32),(2,101,34),(3,102,45),(4,103,50),(5,103,52); CREATE TABLE unions (union_id INT,has_cba BOOLEAN); INSERT INTO unions (union_id,has_cba) VALUES (101,TRUE),(102,FALSE),(103,TRUE); | SELECT AVG(um.age) FROM union_membership um INNER JOIN unions u ON um.union_id = u.union_id WHERE u.has_cba = TRUE; |
What is the average budget for ethical AI initiatives in North America? | CREATE TABLE ethical_ai_initiatives (initiative_id INT,region VARCHAR(20),budget DECIMAL(10,2)); INSERT INTO ethical_ai_initiatives (initiative_id,region,budget) VALUES (1,'North America',50000.00),(2,'Europe',100000.00),(3,'South America',25000.00); | SELECT AVG(budget) FROM ethical_ai_initiatives WHERE region = 'North America'; |
Which Latin Pop song received the most streams? | CREATE TABLE SongStreamCount (SongID INT,StreamCount INT); | SELECT S.Title, SS.StreamCount FROM Songs S INNER JOIN SongStreamCount SS ON S.SongID = SS.SongID WHERE S.Genre = 'Latin Pop' ORDER BY SS.StreamCount DESC LIMIT 1; |
What is the total budget for inclusion efforts in the last 6 months for the Asian community in New York? | CREATE TABLE inclusion_budget (id INT PRIMARY KEY,category VARCHAR(255),community VARCHAR(255),state VARCHAR(255),budget DECIMAL(10,2),date DATE); | SELECT SUM(budget) FROM inclusion_budget WHERE category = 'inclusion efforts' AND community = 'Asian' AND state = 'New York' AND date >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH); |
What is the total number of spacecraft manufactured by country? | CREATE TABLE spacecraft_manufacturers (id INT PRIMARY KEY,country VARCHAR(50),number_of_spacecraft INT); | SELECT country, SUM(number_of_spacecraft) as total_spacecraft FROM spacecraft_manufacturers GROUP BY country; |
What is the percentage of uninsured individuals in each county, in California? | CREATE TABLE healthcare_access (id INT,county VARCHAR(50),insured BOOLEAN,population INT); INSERT INTO healthcare_access (id,county,insured,population) VALUES (1,'Los Angeles',false,500000); INSERT INTO healthcare_access (id,county,insured,population) VALUES (2,'San Diego',true,350000); INSERT INTO healthcare_access (id,county,insured,population) VALUES (3,'San Francisco',false,850000); | SELECT county, (SUM(CASE WHEN insured = false THEN population ELSE 0 END) / SUM(population)) * 100 as uninsured_percentage FROM healthcare_access WHERE state = 'CA' GROUP BY county; |
What was the total cost of agricultural innovation projects in the 'Innovation' table, grouped by type, that started after 2014? | CREATE TABLE Innovation (id INT,project VARCHAR(255),region VARCHAR(255),year INT,cost FLOAT); INSERT INTO Innovation (id,project,region,year,cost) VALUES (1,'Precision Farming','Rural North',2013,2000000),(2,'Drip Irrigation','Urban East',2017,3000000),(3,'Soil Sensor','Rural South',2015,1000000),(4,'Vertical Farming','Urban West',2016,4000000); | SELECT SUBSTRING(project, 1, INSTR(project, ' ')-1) as project_type, SUM(cost) as total_cost FROM Innovation WHERE year > 2014 GROUP BY project_type; |
List all the unique investors who have invested in companies with a valuation greater than $100 million, sorted alphabetically. | CREATE TABLE investment (id INT,company TEXT,investor TEXT,valuation INT); INSERT INTO investment (id,company,investor,valuation) VALUES (1,'Acme Inc','VC Firm A',500000000); | SELECT DISTINCT investor FROM investment WHERE valuation > 100000000 ORDER BY investor; |
List the top 2 destinations with the highest total number of packages shipped in December 2021 | CREATE TABLE Shipments (id INT,destination VARCHAR(50),packages INT,timestamp DATE); INSERT INTO Shipments (id,destination,packages,timestamp) VALUES (1,'Sydney',50,'2021-12-01'),(2,'Melbourne',30,'2021-12-02'),(3,'Brisbane',40,'2021-12-03'),(4,'Perth',55,'2021-12-04'),(5,'Adelaide',60,'2021-12-05'); | SELECT destination, SUM(packages) FROM Shipments WHERE timestamp BETWEEN '2021-12-01' AND '2021-12-31' GROUP BY destination ORDER BY SUM(packages) DESC LIMIT 2; |
Add a new strain called 'Purple Haze' | CREATE TABLE strains (id INT,name TEXT,type TEXT,thc_level REAL); | INSERT INTO strains (id, name, type, thc_level) VALUES (1, 'Purple Haze', 'Sativa', 18.5); |
Calculate the percentage of industrial water consumption that is wastewater in New York. | CREATE TABLE new_york_water_usage (id INT,water_type VARCHAR(20),consumption FLOAT); INSERT INTO new_york_water_usage (id,water_type,consumption) VALUES (1,'Industrial Wastewater',50000),(2,'Industrial Non-wastewater',150000); | SELECT (SUM(CASE WHEN water_type = 'Industrial Wastewater' THEN consumption ELSE 0 END) * 100.0 / SUM(consumption)) FROM new_york_water_usage; |
What is the total amount of money invested in the social impact investing sector? | CREATE TABLE investments (id INT,sector VARCHAR(255),amount FLOAT); INSERT INTO investments (id,sector,amount) VALUES (1,'Social Impact Investing',5000000.0),(2,'Social Impact Investing',7000000.0),(3,'Renewable Energy',8000000.0); | SELECT SUM(amount) FROM investments WHERE sector = 'Social Impact Investing'; |
List all unique environmental impact assessment IDs for products manufactured in the USA and Canada. | CREATE TABLE product (id INT,name VARCHAR(255),manufacturer_country VARCHAR(255)); CREATE TABLE eia (id INT,product_id INT,assessment_date DATE,impact_score INT); INSERT INTO product (id,name,manufacturer_country) VALUES (1,'Product A','USA'),(2,'Product B','Canada'),(3,'Product C','Mexico'); INSERT INTO eia (id,product_id,assessment_date,impact_score) VALUES (1,1,'2021-08-01',50),(2,1,'2022-02-01',55),(3,2,'2021-10-15',60); | SELECT DISTINCT eia.id FROM eia INNER JOIN product p ON eia.product_id = p.id WHERE p.manufacturer_country IN ('USA', 'Canada'); |
Insert new case outcome records | CREATE TABLE case_outcomes (case_id INT,outcome TEXT,precedent TEXT); | INSERT INTO case_outcomes (case_id, outcome, precedent) VALUES (1, 'Won', 'Precedent A'), (2, 'Lost', 'Precedent B'), (3, 'Settled', 'Precedent C'); |
Find the number of animals for each species, grouped by region, and filter for species with more than 100 animals in the "animal_population", "countries", and "endangered_species" tables | CREATE TABLE animal_population (species VARCHAR(255),animal_count INT,country VARCHAR(255),endangered BOOLEAN); CREATE TABLE countries (country VARCHAR(255),region VARCHAR(255)); | SELECT c1.region, e1.species, SUM(e1.animal_count) as total_count FROM animal_population e1 INNER JOIN countries c1 ON e1.country = c1.country WHERE e1.endangered = FALSE GROUP BY c1.region, e1.species HAVING total_count > 100; |
What is the minimum and maximum mass of space debris? | CREATE TABLE space_debris_v2 (id INT,name VARCHAR(255),mass FLOAT); INSERT INTO space_debris_v2 (id,name,mass) VALUES (1,'Space Debris 1',100.0),(2,'Space Debris 2',2000.0),(3,'Space Debris 3',50.0); | SELECT MIN(mass) AS minimum_mass, MAX(mass) AS maximum_mass FROM space_debris_v2; |
Identify the locations with the most safety inspections in the last 60 days. | CREATE TABLE safety_inspections_new3 (id INT PRIMARY KEY,location VARCHAR(50),inspection_date DATE,passed BOOLEAN); | SELECT location, COUNT(*) as num_inspections FROM safety_inspections_new3 WHERE inspection_date > CURDATE() - INTERVAL 60 DAY GROUP BY location ORDER BY num_inspections DESC LIMIT 1; |
Who are the teachers who have taught courses with a mental health rating below 3? | CREATE TABLE teacher_courses (teacher_id INT,course_id INT); INSERT INTO teacher_courses (teacher_id,course_id) VALUES (1,1),(1,2),(2,3),(2,4),(3,5),(4,6); CREATE TABLE courses (course_id INT,name TEXT,mental_health_rating FLOAT); INSERT INTO courses (course_id,name,mental_health_rating) VALUES (1,'Intro to Psychology',4.5),(2,'Yoga for Wellness',3.8),(3,'Mindfulness Meditation',4.7),(4,'Stress Management',2.5),(5,'Critical Thinking',5.0),(6,'Lifelong Learning',4.0); | SELECT DISTINCT t.teacher_id, t.name FROM teacher_courses tc JOIN courses c ON tc.course_id = c.course_id JOIN teachers t ON tc.teacher_id = t.teacher_id WHERE c.mental_health_rating < 3; |
What is the total number of mobile and broadband subscribers for each network type? | CREATE TABLE subscriber_data (subscriber_type VARCHAR(20),network_type VARCHAR(20),subscriber_count INT); INSERT INTO subscriber_data (subscriber_type,network_type,subscriber_count) VALUES ('Mobile','4G',5000),('Broadband','Fiber',3000),('Mobile','5G',7000),('Broadband','Cable',4000); | SELECT network_type, SUM(subscriber_count) FROM subscriber_data GROUP BY network_type; |
What is the maximum geopolitical risk assessment score for Raytheon Technologies in the European Union in 2021? | CREATE TABLE geopolitical_risk_assessments (company VARCHAR(255),region VARCHAR(255),year INT,score INT); INSERT INTO geopolitical_risk_assessments (company,region,year,score) VALUES ('Raytheon Technologies','European Union',2021,80); | SELECT MAX(score) FROM geopolitical_risk_assessments WHERE company = 'Raytheon Technologies' AND region = 'European Union' AND year = 2021; |
Identify the number of digital divide initiatives in Latin America and the Caribbean, organized by year since 2015. | CREATE TABLE DigitalDivide (InitiativeID INT,InitiativeName TEXT,Country TEXT,Year INT,Organization TEXT); INSERT INTO DigitalDivide (InitiativeID,InitiativeName,Country,Year,Organization) VALUES (1,'Initiative X','Brazil',2017,'UNESCO'); INSERT INTO DigitalDivide (InitiativeID,InitiativeName,Country,Year,Organization) VALUES (2,'Initiative Y','Mexico',2016,'World Bank'); | SELECT Year, COUNT(*) FROM DigitalDivide WHERE Country IN ('Latin America', 'Caribbean') AND Year >= 2015 GROUP BY Year; |
List all cybersecurity policies that were last updated in '2019'. | CREATE TABLE policies (policy_id INT PRIMARY KEY,policy_name VARCHAR(100),last_updated DATE); INSERT INTO policies (policy_id,policy_name,last_updated) VALUES (1,'Acceptable Use Policy','2019-12-31'),(2,'Incident Response Policy','2021-02-14'); | SELECT policy_name, last_updated FROM policies WHERE last_updated LIKE '2019-%'; |
How many investments were made in total by a specific investor in Q3 2021? | CREATE TABLE investments (id INT,investor VARCHAR(20),date DATE); INSERT INTO investments (id,investor,date) VALUES (1,'Investor X','2021-07-15'),(2,'Investor Y','2021-08-01'),(3,'Investor X','2021-09-30'); | SELECT COUNT(*) FROM investments WHERE date BETWEEN '2021-07-01' AND '2021-09-30' GROUP BY investor; |
Insert a new record for a baseball match in Japan with 2000 tickets sold. | CREATE TABLE matches (match_id INT,sport VARCHAR(50),location VARCHAR(50),tickets_sold INT); | INSERT INTO matches (match_id, sport, location, tickets_sold) VALUES (4, 'Baseball', 'Japan', 2000); |
What is the average investigation length for each article topic in 'investigative_reports' table? | CREATE TABLE investigative_reports (article_id INT,article_topic VARCHAR(50),investigation_length INT,publication_date DATE); | SELECT article_topic, AVG(investigation_length) FROM investigative_reports GROUP BY article_topic; |
What is the average virtual tour engagement duration in Mexico City, Mexico? | CREATE TABLE virtual_tours (tour_id INT,hotel_name VARCHAR(255),city VARCHAR(255),country VARCHAR(255),duration INT); INSERT INTO virtual_tours (tour_id,hotel_name,city,country,duration) VALUES (1,'Hotel Four Seasons','Mexico City','Mexico',180),(2,'Hotel St. Regis','Mexico City','Mexico',210); | SELECT AVG(duration) FROM virtual_tours WHERE city = 'Mexico City' AND country = 'Mexico'; |
Insert a new station onto the monorail line with station_id 5 and station_name 'Chinatown' | CREATE TABLE monorail_stations (station_id INT,station_name VARCHAR(255)); INSERT INTO monorail_stations (station_id,station_name) VALUES (1,'Downtown'),(2,'Uptown'),(3,'Suburbia'),(4,'Airport'); | INSERT INTO monorail_stations (station_id, station_name) VALUES (5, 'Chinatown'); |
What is the total quantity of hair care products sold in India in the past quarter? | CREATE TABLE HairCareSales (product VARCHAR(255),country VARCHAR(255),date DATE,quantity INT); | SELECT SUM(quantity) FROM HairCareSales WHERE product LIKE 'Hair%' AND country = 'India' AND date >= DATEADD(quarter, -1, GETDATE()); |
How many indigenous food systems have adopted urban agriculture practices in South America? | CREATE TABLE indigenous_food_systems (id INT,name VARCHAR(255),uses_urban_agriculture BOOLEAN); INSERT INTO indigenous_food_systems (id,name,uses_urban_agriculture) VALUES (1,'System A',TRUE),(2,'System B',FALSE),(3,'System C',TRUE); | SELECT COUNT(*) FROM indigenous_food_systems WHERE uses_urban_agriculture = TRUE AND country = 'South America'; |
Find the number of electric vehicles in each city, grouped by vehicle type | CREATE TABLE electric_vehicles (id INT PRIMARY KEY,make VARCHAR(255),model VARCHAR(255),year INT,city VARCHAR(255),type VARCHAR(255)); | CREATE VIEW electric_vehicles_by_city AS SELECT city, type, COUNT(*) as num_vehicles FROM electric_vehicles GROUP BY city, type; |
What is the total number of visitors from the "Art Appreciation" program and the "Music and Dance" program? | CREATE TABLE ArtAppreciation(id INT,age INT,gender VARCHAR(10),visit_date DATE); CREATE TABLE MusicAndDance(id INT,age INT,gender VARCHAR(10),visit_date DATE); | SELECT COUNT(*) FROM ArtAppreciation UNION SELECT COUNT(*) FROM MusicAndDance; |
List all marine protected areas | CREATE TABLE marine_protected_areas (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),size FLOAT,year_established INT); INSERT INTO marine_protected_areas (id,name,location,size,year_established) VALUES (1,'Great Barrier Reef','Australia',344400,1975),(2,'Galapagos Marine Reserve','Ecuador',133000,1998); | SELECT * FROM marine_protected_areas; |
What is the total number of hours contributed by volunteers from Canada to arts and culture programs in the past 9 months? | CREATE TABLE volunteer_hours (id INT,volunteer_id INT,program_id INT,hours DECIMAL(10,2),contribution_date DATE); CREATE TABLE volunteers (id INT,country VARCHAR(50)); CREATE TABLE programs (id INT,focus_area VARCHAR(50)); INSERT INTO volunteer_hours (id,volunteer_id,program_id,hours,contribution_date) VALUES (1,1,1,3.0,'2021-04-01'); INSERT INTO volunteers (id,country) VALUES (1,'Canada'); INSERT INTO programs (id,focus_area) VALUES (1,'Arts and Culture'); | SELECT SUM(hours) FROM volunteer_hours JOIN volunteers ON volunteer_hours.volunteer_id = volunteers.id JOIN programs ON volunteer_hours.program_id = programs.id WHERE volunteers.country = 'Canada' AND programs.focus_area = 'arts and culture programs' AND contribution_date >= DATE_SUB(CURDATE(), INTERVAL 9 MONTH); |
How many ships were decommissioned between 2005 and 2010? | CREATE TABLE ships (id INT,name TEXT,type TEXT,year_built INT,decommission_year INT); INSERT INTO ships (id,name,type,year_built,decommission_year) VALUES (1,'Seabourn Pride','Passenger',1988,2011); | SELECT COUNT(*) FROM ships WHERE decommission_year BETWEEN 2005 AND 2010; |
What is the earliest date of a national security operation in the database? | CREATE TABLE national_security_ops (id INT,operation_date DATE); INSERT INTO national_security_ops (id,operation_date) VALUES (1,'2021-06-15'); INSERT INTO national_security_ops (id,operation_date) VALUES (2,'2022-02-03'); | SELECT MIN(operation_date) FROM national_security_ops; |
How many renewable energy projects are there in each country? | CREATE TABLE project_renewable (project_name TEXT,country TEXT); INSERT INTO project_renewable (project_name,country) VALUES ('Project A','Country A'),('Project B','Country A'),('Project C','Country B'),('Project D','Country B'),('Project E','Country C'); | SELECT country, COUNT(*) FROM project_renewable GROUP BY country; |
How many community development projects were completed in 'Asia' in each year? | CREATE TABLE Projects (id INT,location VARCHAR(50),year INT,sector VARCHAR(50),completed BOOLEAN); | SELECT year, COUNT(id) as num_projects FROM Projects WHERE location = 'Asia' AND completed = TRUE GROUP BY year; |
Find the total amount of CO2 and SO2 emissions for each month in 2020. | CREATE TABLE Environmental_Impact (Mine_ID INT,Pollutant VARCHAR(10),Amount FLOAT,Date DATE); INSERT INTO Environmental_Impact (Mine_ID,Pollutant,Amount,Date) VALUES (1,'CO2',1200,'2020-01-01'),(2,'SO2',800,'2020-01-02'),(1,'SO2',900,'2020-01-01'),(1,'CO2',1300,'2020-02-01'),(2,'SO2',750,'2020-02-02'); | SELECT EXTRACT(MONTH FROM Date) AS Month, SUM(CASE WHEN Pollutant IN ('CO2', 'SO2') THEN Amount ELSE 0 END) FROM Environmental_Impact WHERE Date BETWEEN '2020-01-01' AND '2020-12-31' GROUP BY EXTRACT(MONTH FROM Date); |
Find the customer with the most recent shipment date. | CREATE TABLE CustomerShipments(id INT,customer_name VARCHAR(50),shipment_date DATE); INSERT INTO CustomerShipments(id,customer_name,shipment_date) VALUES (1,'Anna Brown','2022-06-01'),(2,'Bob Johnson','2022-07-15'); | SELECT customer_name, MAX(shipment_date) FROM CustomerShipments; |
What was the average ticket price for events in the 'Theater' category? | CREATE TABLE events (id INT,category VARCHAR(10),tickets_sold INT,ticket_price DECIMAL(5,2)); INSERT INTO events (id,category,tickets_sold,ticket_price) VALUES (1,'Dance',200,20.00),(2,'Music',300,35.00),(3,'Theater',150,50.00); | SELECT AVG(ticket_price) FROM events WHERE category = 'Theater'; |
Which mental health conditions were treated most frequently in Australia during 2021? | CREATE TABLE patients (id INT,country VARCHAR(255)); CREATE TABLE treatments (id INT,patient_id INT,treatment_date DATE); CREATE TABLE conditions (id INT,patient_id INT,condition VARCHAR(255)); INSERT INTO patients (id,country) VALUES (1,'Australia'),(2,'Australia'),(3,'Australia'); INSERT INTO treatments (id,patient_id,treatment_date) VALUES (1,1,'2021-01-01'),(2,1,'2021-02-15'),(3,2,'2021-06-30'),(4,3,'2021-12-31'); INSERT INTO conditions (id,patient_id,condition) VALUES (1,1,'depression'),(2,1,'anxiety'),(3,2,'depression'),(4,3,'bipolar'); | SELECT conditions.condition, COUNT(conditions.condition) AS count FROM conditions JOIN patients ON conditions.patient_id = patients.id JOIN treatments ON patients.id = treatments.patient_id WHERE patients.country = 'Australia' AND treatments.treatment_date >= '2021-01-01' AND treatments.treatment_date < '2022-01-01' GROUP BY conditions.condition ORDER BY count DESC LIMIT 1; |
Create a view for athlete wellbeing programs by gender | CREATE TABLE athlete_wellbeing (id INT PRIMARY KEY,athlete_id INT,program_name VARCHAR(100),start_date DATE,end_date DATE); | CREATE VIEW athlete_wellbeing_by_gender AS SELECT athlete_wellbeing.*, fans.gender FROM athlete_wellbeing INNER JOIN fans ON athlete_wellbeing.athlete_id = fans.id; |
What is the minimum transaction amount in the Northwest region? | CREATE TABLE transactions (id INT,region VARCHAR(20),transaction_amount DECIMAL(10,2)); INSERT INTO transactions (id,region,transaction_amount) VALUES (1,'Northwest',50.00),(2,'Southwest',75.00),(3,'Northwest',45.00); | SELECT MIN(transaction_amount) FROM transactions WHERE region = 'Northwest'; |
How many clinical trials were successful in North America? | CREATE TABLE clinical_trials2 (trial_id INT,country TEXT,success BOOLEAN); INSERT INTO clinical_trials2 (trial_id,country,success) VALUES (1,'USA',TRUE),(2,'Canada',FALSE),(3,'Mexico',TRUE); | SELECT COUNT(*) as successful_trials FROM clinical_trials2 WHERE success = TRUE AND country IN ('USA', 'Canada', 'Mexico') AND region = 'North America'; |
What is the total production volume (in kg) for each chemical category in 2019? | CREATE TABLE chemical_categories (id INT PRIMARY KEY,category VARCHAR(255));CREATE TABLE chemicals (id INT,category_id INT,name VARCHAR(255),production_volume FLOAT,production_date DATE); INSERT INTO chemical_categories (id,category) VALUES (1,'Acids'),(2,'Bases'),(3,'Solvents'); INSERT INTO chemicals (id,category_id,name,production_volume,production_date) VALUES (1,1,'Hydrochloric Acid',150,'2019-01-01'),(2,1,'Sulfuric Acid',200,'2019-01-05'),(3,2,'Sodium Hydroxide',120,'2019-02-10'),(4,3,'Acetone',80,'2019-03-15'),(5,3,'Ethanol',100,'2019-04-20'); | SELECT c.category, SUM(ch.production_volume) FROM chemicals ch JOIN chemical_categories c ON ch.category_id = c.id WHERE YEAR(ch.production_date) = 2019 GROUP BY c.category; |
Delete the record with project ID 2 from the 'Sewer_System' table. | CREATE TABLE Sewer_System (project_id INT,project_name VARCHAR(100),start_date DATE); INSERT INTO Sewer_System (project_id,project_name,start_date) VALUES (2,'Sewer Line Replacement','2021-04-15'),(5,'Sewage Treatment Plant Upgrade','2022-01-02'); | DELETE FROM Sewer_System WHERE project_id = 2; |
What is the current landfill capacity in the state of New York? | CREATE TABLE landfill_capacity (state varchar(255),capacity float,current_capacity float); INSERT INTO landfill_capacity (state,capacity,current_capacity) VALUES ('New York',5000000,3000000); | SELECT current_capacity FROM landfill_capacity WHERE state = 'New York' |
What is the total number of employees working in mining sites located in California? | CREATE TABLE sites (site_id INT,site_name VARCHAR(100),state VARCHAR(50)); INSERT INTO sites (site_id,site_name,state) VALUES (1,'Golden Mining Site','California'); INSERT INTO sites (site_id,site_name,state) VALUES (2,'Silver Peak Mine','Nevada'); CREATE TABLE employees (employee_id INT,employee_name VARCHAR(100),site_id INT); INSERT INTO employees (employee_id,employee_name,site_id) VALUES (1,'John Doe',1); INSERT INTO employees (employee_id,employee_name,site_id) VALUES (2,'Jane Smith',1); INSERT INTO employees (employee_id,employee_name,site_id) VALUES (3,'Robert Johnson',2); | SELECT COUNT(*) FROM employees WHERE site_id IN (SELECT site_id FROM sites WHERE state = 'California'); |
How many public transportation trips were taken in NYC, Chicago, and LA in Q1 2022? | CREATE TABLE Trips (City TEXT,Quarter INT,Year INT,Trips INT); INSERT INTO Trips (City,Quarter,Year,Trips) VALUES ('NYC',1,2022,1500000),('Chicago',1,2022,1200000),('LA',1,2022,1800000); | SELECT SUM(Trips) FROM Trips WHERE City IN ('NYC', 'Chicago', 'LA') AND Quarter = 1 AND Year = 2022; |
What are the top 5 cities with the most users who clicked on sponsored content in the past month, for users in the age range of 18-24? | CREATE TABLE users (user_id INT,city VARCHAR(50),age INT); CREATE TABLE clicks (click_id INT,user_id INT,sponsored BOOLEAN); | SELECT u.city, COUNT(c.click_id) AS clicks FROM users u JOIN clicks c ON u.user_id = c.user_id WHERE u.age BETWEEN 18 AND 24 AND c.sponsored = TRUE GROUP BY u.city ORDER BY clicks DESC LIMIT 5; |
List the names and categories of all projects that were started in 2021 but not completed. | CREATE TABLE projects (id INT,name VARCHAR(255),category VARCHAR(255),year INT,status VARCHAR(255)); INSERT INTO projects (id,name,category,year,status) VALUES (7,'Wastewater Treatment Plant Upgrade','Water Supply',2021,'In Progress'); | SELECT name, category FROM projects WHERE year = 2021 AND status != 'Completed'; |
What is the distribution of case types (civil, criminal, etc.) for attorneys in the 'attorneys_cases' table, grouped by attorney race? | CREATE TABLE attorney_race (attorney_id INT,race VARCHAR(20)); CREATE TABLE attorneys_cases (case_id INT,attorney_id INT,case_type VARCHAR(10)); | SELECT a.race, c.case_type, COUNT(*) AS count FROM attorney_race a JOIN attorneys_cases c ON a.attorney_id = c.attorney_id GROUP BY a.race, c.case_type; |
What is the total number of volunteers from urban areas who have volunteered in the last 6 months? | CREATE TABLE volunteers (id INT,name VARCHAR(50),reg_date DATE,location VARCHAR(30)); INSERT INTO volunteers (id,name,reg_date,location) VALUES (1,'Alex','2023-02-01','urban'),(2,'Bella','2023-01-15','rural'),(3,'Charlie','2023-03-05','suburban'),(4,'Diana','2022-07-20','rural'),(5,'Eli','2022-09-01','urban'); | SELECT COUNT(*) FROM volunteers WHERE location = 'urban' AND reg_date >= DATEADD(month, -6, GETDATE()); |
Which cities have more than 500 green-certified buildings? | CREATE TABLE city (id INT,name VARCHAR(50)); CREATE TABLE building (id INT,city_id INT,green_certified BOOLEAN); | SELECT city.name FROM city INNER JOIN building ON city.id = building.city_id WHERE green_certified = TRUE GROUP BY city.name HAVING COUNT(building.id) > 500; |
What is the average age of employees in each mining operation? | CREATE TABLE mining_operations (operation_id INT,operation_name VARCHAR(50),employee_id INT,first_name VARCHAR(50),last_name VARCHAR(50),position VARCHAR(50),age INT); INSERT INTO mining_operations (operation_id,operation_name,employee_id,first_name,last_name,position,age) VALUES (1,'Operation A',1,'John','Doe','Engineer',35),(2,'Operation B',2,'Jane','Doe','Manager',45),(3,'Operation C',3,'Mike','Johnson','Operator',25); | SELECT operation_name, AVG(age) AS avg_age FROM mining_operations GROUP BY operation_name; |
Determine the number of Shariah-compliant loans issued per month, in 2021. | CREATE TABLE shariah_loans (id INT,client_name VARCHAR(50),issue_date DATE,amount FLOAT); | SELECT DATE_TRUNC('month', issue_date) as month, COUNT(*) as num_loans FROM shariah_loans WHERE issue_date >= '2021-01-01' AND issue_date < '2022-01-01' GROUP BY month; |
Update the volunteer record with the highest total hours to have a volunteer_type of 'long-term'. | CREATE TABLE volunteers (volunteer_id INT,total_hours INT,volunteer_type VARCHAR(20)); INSERT INTO volunteers (volunteer_id,total_hours,volunteer_type) VALUES (1,50,'short-term'),(2,150,'short-term'),(3,200,'short-term'); | UPDATE volunteers SET volunteer_type = 'long-term' WHERE total_hours = (SELECT MAX(total_hours) FROM volunteers); |
How many community education programs in the "RuralCommunities" view had more than 100 attendees? | CREATE VIEW RuralCommunities AS SELECT program_id,location,attendee_count FROM CommunityPrograms WHERE location LIKE 'Rural%'; INSERT INTO CommunityPrograms (program_id,location,attendee_count) VALUES (1,'RuralVillage',120),(2,'RuralTown',80),(3,'UrbanCity',200); | SELECT COUNT(*) FROM RuralCommunities WHERE attendee_count > 100; |
What is the average budget for a tourist visiting Southeast Asia? | CREATE TABLE southeast_asia_budgets (country VARCHAR(50),budget DECIMAL(5,2)); INSERT INTO southeast_asia_budgets (country,budget) VALUES ('Thailand',1200),('Vietnam',1000),('Cambodia',800),('Malaysia',1500),('Indonesia',1100),('Philippines',900); | SELECT AVG(budget) FROM southeast_asia_budgets; |
How many vulnerabilities have been found in the 'vulnerability_assessments' table for each severity level? | CREATE TABLE vulnerability_assessments (id INT,vulnerability VARCHAR(50),severity VARCHAR(10)); | SELECT severity, COUNT(*) FROM vulnerability_assessments GROUP BY severity; |
What is the percentage of the population in Australia that has access to clean water? | CREATE TABLE Countries (CountryName TEXT,PercentCleanWater FLOAT); INSERT INTO Countries (CountryName,PercentCleanWater) VALUES ('Australia',97.2),('Canada',99.8),('China',93.5); | SELECT PercentCleanWater FROM Countries WHERE CountryName = 'Australia'; |
List all military vehicles and their corresponding countries of origin. | CREATE TABLE MilitaryVehicles (id INT,name VARCHAR(100),country_of_origin VARCHAR(100)); INSERT INTO MilitaryVehicles (id,name,country_of_origin) VALUES (1,'Vehicle1','USA'); INSERT INTO MilitaryVehicles (id,name,country_of_origin) VALUES (2,'Vehicle2','Germany'); | SELECT name, country_of_origin FROM MilitaryVehicles; |
List all vessels that passed safety inspection in 2021 | CREATE TABLE IF NOT EXISTS vessel_safety (id INT PRIMARY KEY,vessel_name VARCHAR(255),safety_inspection_date DATE); INSERT INTO vessel_safety (id,vessel_name,safety_inspection_date) VALUES (1,'SS Great Britain','2021-03-15'),(2,'Queen Mary 2','2021-06-23'),(3,'Titanic','2021-09-11'); | SELECT vessel_name FROM vessel_safety WHERE YEAR(safety_inspection_date) = 2021; |
How many projects does each organization have in the climate mitigation category? | CREATE TABLE organizations (id INT PRIMARY KEY,name VARCHAR(100),category VARCHAR(50)); INSERT INTO organizations (id,name,category) VALUES (1,'Greenpeace','climate mitigation'); INSERT INTO organizations (id,name,category) VALUES (2,'World Wildlife Fund','climate adaptation'); INSERT INTO organizations (id,name,category) VALUES (3,'350.org','climate finance'); CREATE TABLE projects (id INT PRIMARY KEY,organization VARCHAR(100),category VARCHAR(50)); INSERT INTO projects (id,organization,category) VALUES (1,'Greenpeace','climate mitigation'); INSERT INTO projects (id,organization,category) VALUES (2,'Greenpeace','climate mitigation'); INSERT INTO projects (id,organization,category) VALUES (3,'World Wildlife Fund','climate adaptation'); | SELECT o.name, o.category, COUNT(p.id) as num_projects FROM organizations o JOIN projects p ON o.name = p.organization WHERE o.category = 'climate mitigation' GROUP BY o.name, o.category; |
What is the total number of deep-sea expeditions in the Atlantic and Pacific Oceans? | CREATE TABLE deep_sea_expeditions (expedition_name VARCHAR(255),ocean VARCHAR(255)); INSERT INTO deep_sea_expeditions (expedition_name,ocean) VALUES ('Expedition 1','Atlantic Ocean'),('Expedition 2','Pacific Ocean'); | SELECT SUM(count) FROM (SELECT ocean, COUNT(*) as count FROM deep_sea_expeditions GROUP BY ocean) as subquery; |
What is the maximum balance for each customer in the past month? | CREATE TABLE balances (balance_id INT,customer_id INT,balance DECIMAL(10,2),balance_date DATE); INSERT INTO balances VALUES (1,1,5000.00,'2022-02-01'); INSERT INTO balances VALUES (2,1,6000.00,'2022-02-15'); INSERT INTO balances VALUES (3,2,8000.00,'2022-02-03'); INSERT INTO balances VALUES (4,2,9000.00,'2022-02-28'); | SELECT customer_id, MAX(balance) as max_balance FROM balances WHERE balance_date >= DATEADD(month, -1, GETDATE()) GROUP BY customer_id; |
What is the total number of crimes and the crime type with the highest frequency in each borough? | CREATE TABLE Boroughs (BoroughID INT,BoroughName VARCHAR(255)); CREATE TABLE Crimes (CrimeID INT,CrimeType VARCHAR(255),BoroughID INT,CrimeDate DATE); | SELECT BoroughName, COUNT(CrimeID) as CrimesCount, CrimeType FROM Crimes c JOIN Boroughs b ON c.BoroughID = b.BoroughID GROUP BY BoroughName, CrimeType ORDER BY BoroughName, CrimesCount DESC; |
Show the total waste generation for each region | CREATE TABLE Manufacturers (manufacturer_id INT,manufacturer_name VARCHAR(50),region VARCHAR(50)); INSERT INTO Manufacturers (manufacturer_id,manufacturer_name,region) VALUES (1,'ManufacturerA','North America'),(2,'ManufacturerB','Europe'),(3,'ManufacturerC','Asia-Pacific'); CREATE TABLE WasteData (manufacturer_id INT,material VARCHAR(50),waste_quantity INT); INSERT INTO WasteData (manufacturer_id,material,waste_quantity) VALUES (1,'Material1',120),(1,'Material2',150),(2,'Material1',80),(2,'Material3',100),(3,'Material2',50),(3,'Material3',130); | SELECT m.region, SUM(w.waste_quantity) AS total_waste FROM Manufacturers m INNER JOIN WasteData w ON m.manufacturer_id = w.manufacturer_id GROUP BY m.region; |
What is the total number of containers shipped from Japan to South Korea in 2017? | CREATE TABLE trade_routes (id INT PRIMARY KEY,origin_country VARCHAR(50),destination_country VARCHAR(50),year INT); INSERT INTO trade_routes (id,origin_country,destination_country,year) VALUES (1,'Japan','South Korea',2017); CREATE TABLE shipments (id INT PRIMARY KEY,container_count INT,trade_route_id INT,FOREIGN KEY (trade_route_id) REFERENCES trade_routes(id)); | SELECT SUM(shipments.container_count) FROM shipments INNER JOIN trade_routes ON shipments.trade_route_id = trade_routes.id WHERE trade_routes.origin_country = 'Japan' AND trade_routes.destination_country = 'South Korea' AND trade_routes.year = 2017; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.