instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
What are the names and launch dates of satellites launched by ISRO or CNES before 2010?
|
CREATE TABLE Satellites (Satellite_ID INT,Satellite_Name VARCHAR(50),Agency VARCHAR(50),Launch_Date DATETIME); INSERT INTO Satellites (Satellite_ID,Satellite_Name,Agency,Launch_Date) VALUES (1,'Cartosat-1','ISRO','2005-05-05'),(2,'SPOT-5','CNES','2002-05-03');
|
SELECT Satellite_Name, Launch_Date FROM Satellites WHERE Agency IN ('ISRO', 'CNES') AND Launch_Date < '2010-01-01';
|
List the defense projects and their respective start and end dates, along with the contract negotiation status, that have a geopolitical risk score above 7, ordered by the geopolitical risk score in descending order.
|
CREATE TABLE DefenseProjects (project_id INT,project_name VARCHAR(50),start_date DATE,end_date DATE,negotiation_status VARCHAR(50),geopolitical_risk_score INT); INSERT INTO DefenseProjects (project_id,project_name,start_date,end_date,negotiation_status,geopolitical_risk_score) VALUES (1,'Project A','2019-01-01','2021-12-31','In Progress',6),(2,'Project B','2018-06-15','2023-05-01','Completed',9),(3,'Project C','2020-07-22','2024-06-30','Planning',4);
|
SELECT project_name, start_date, end_date, negotiation_status, geopolitical_risk_score FROM DefenseProjects WHERE geopolitical_risk_score > 7 ORDER BY geopolitical_risk_score DESC;
|
What is the average life expectancy for residents in rural communities in each state, ordered from highest to lowest?
|
CREATE SCHEMA RuralHealth; USE RuralHealth; CREATE TABLE States (StateName VARCHAR(50),StateAbbreviation VARCHAR(10)); CREATE TABLE Communities (CommunityID INT,CommunityName VARCHAR(50),StateAbbreviation VARCHAR(10),Rural BOOLEAN,AverageLifeExpectancy FLOAT); INSERT INTO States (StateName,StateAbbreviation) VALUES ('Alabama','AL'),('Alaska','AK'); INSERT INTO Communities (CommunityID,CommunityName,StateAbbreviation,Rural,AverageLifeExpectancy) VALUES (1,'CommunityA','AL',TRUE,78.0),(2,'CommunityB','AK',TRUE,80.0);
|
SELECT StateAbbreviation, AVG(AverageLifeExpectancy) as AvgLifeExpectancy FROM Communities WHERE Rural = TRUE GROUP BY StateAbbreviation ORDER BY AvgLifeExpectancy DESC;
|
List regions with average vessel speed above 12 knots.
|
CREATE TABLE Vessel_Performance (Vessel_ID INT,Speed FLOAT,Region VARCHAR(255)); INSERT INTO Vessel_Performance (Vessel_ID,Speed,Region) VALUES (1,14.5,'Pacific'),(2,10.2,'Atlantic'),(3,13.1,'Pacific'),(4,11.9,'Atlantic'),(5,9.8,'Indian'),(6,15.2,'Pacific'),(7,12.3,'Arctic');
|
SELECT Region FROM Vessel_Performance WHERE Speed > 12 GROUP BY Region HAVING AVG(Speed) > 12;
|
What is the number of users who favor each genre?
|
CREATE TABLE users (id INT,name VARCHAR(50),favorite_genre VARCHAR(50)); INSERT INTO users (id,name,favorite_genre) VALUES (1,'Alice','Pop'),(2,'Bob','Rock'),(3,'Charlie','Rock'),(4,'David','Jazz'),(5,'Eve','Pop'),(6,'Frank','Country'),(7,'Grace','Country'),(8,'Harry','R&B'),(9,'Ivy','Pop'),(10,'Jack','Jazz');
|
SELECT favorite_genre, COUNT(*) as genre_count FROM users GROUP BY favorite_genre;
|
What is the minimum rating of movies produced in India and released after 2015?
|
CREATE TABLE Movies (id INT,title VARCHAR(100),rating FLOAT,production_country VARCHAR(50),release_year INT); INSERT INTO Movies (id,title,rating,production_country,release_year) VALUES (1,'Movie1',7.5,'India',2016),(2,'Movie2',8.2,'India',2018),(3,'Movie3',6.8,'India',2017),(4,'Movie4',5.0,'India',2019);
|
SELECT MIN(rating) FROM Movies WHERE production_country = 'India' AND release_year > 2015;
|
What are the names and locations of factories that produce Chemical G?
|
CREATE TABLE factories (factory_id INT,name TEXT,location TEXT); INSERT INTO factories (factory_id,name,location) VALUES (1,'Factory A','New York'),(2,'Factory B','Texas'),(3,'Factory C','Florida'); CREATE TABLE productions (factory_id INT,chemical TEXT); INSERT INTO productions (factory_id,chemical) VALUES (1,'Chemical A'),(2,'Chemical B'),(3,'Chemical G');
|
SELECT f.name, f.location FROM factories f JOIN productions p ON f.factory_id = p.factory_id WHERE p.chemical = 'Chemical G';
|
What is the average water consumption per capita in the cities of Accra and Kumasi for the year 2019?
|
CREATE TABLE ghana_population (id INT,city VARCHAR(50),population INT,year INT); INSERT INTO ghana_population (id,city,population,year) VALUES (1,'Accra',2500000,2019); INSERT INTO ghana_population (id,city,population,year) VALUES (2,'Kumasi',2000000,2019); CREATE TABLE ghana_water_consumption (id INT,city VARCHAR(50),water_consumption FLOAT,year INT); INSERT INTO ghana_water_consumption (id,city,water_consumption,year) VALUES (1,'Accra',50000000,2019); INSERT INTO ghana_water_consumption (id,city,water_consumption,year) VALUES (2,'Kumasi',40000000,2019);
|
SELECT AVG(gwc.water_consumption / gp.population) FROM ghana_water_consumption gwc INNER JOIN ghana_population gp ON gwc.city = gp.city WHERE gwc.year = 2019;
|
What is the average fare per trip segment for the top 10 most frequently traveled segments?
|
CREATE TABLE trip_segments (segment_id INT,route_id INT,fare DECIMAL(5,2),passenger_count INT); INSERT INTO trip_segments (segment_id,route_id,fare,passenger_count) VALUES (1,101,2.50,1000),(2,101,2.00,1200),(3,102,3.00,800),(4,103,1.50,1500),(5,104,4.00,600);
|
SELECT AVG(fare) FROM (SELECT fare, ROW_NUMBER() OVER (ORDER BY passenger_count DESC) rn FROM trip_segments) t WHERE rn <= 10;
|
What is the total billing amount for cases with a duration of less than or equal to 30 days?
|
CREATE TABLE Cases (CaseID int,AttorneyID int,DurationDays int); INSERT INTO Cases (CaseID,AttorneyID,DurationDays) VALUES (1,1,45),(2,2,20),(3,3,32); CREATE TABLE CaseBilling (CaseID int,BillingAmount decimal(10,2)); INSERT INTO CaseBilling (CaseID,BillingAmount) VALUES (1,4500.00),(2,2000.00),(3,3200.00);
|
SELECT SUM(BillingAmount) AS TotalBillingAmount FROM CaseBilling JOIN Cases ON CaseBilling.CaseID = Cases.CaseID WHERE DurationDays <= 30;
|
What are the total tons of gold mined by region in Q3 2021?
|
CREATE TABLE gold_mines (region VARCHAR(50),tons FLOAT,date DATE); INSERT INTO gold_mines (region,tons,date) VALUES ('North',120,'2021-07-01'),('South',150,'2021-07-01'),('East',90,'2021-07-01'),('West',130,'2021-08-01'),('Central',160,'2021-08-01'),('North',100,'2021-08-01'),('South',140,'2021-09-01'),('East',170,'2021-09-01'),('West',110,'2021-09-01');
|
SELECT region, SUM(tons) as total_tons FROM gold_mines WHERE YEAR(date) = 2021 AND QUARTER(date) = 3 GROUP BY region;
|
What is the average trip duration in days for German tourists visiting Japan?
|
CREATE TABLE tourism_stats (id INT PRIMARY KEY,country VARCHAR(255),destination VARCHAR(255),duration INT); INSERT INTO tourism_stats (id,country,destination,duration) VALUES (1,'Germany','Japan',10);
|
SELECT AVG(duration) FROM tourism_stats WHERE country = 'Germany' AND destination = 'Japan';
|
What is the average waste quantity for paper generated by educational institutions?
|
CREATE TABLE WasteGenerators (GeneratorID INT,GeneratorType VARCHAR(50),WasteType VARCHAR(50),WasteQuantity FLOAT,Location VARCHAR(50)); INSERT INTO WasteGenerators (GeneratorID,GeneratorType,WasteType,WasteQuantity,Location) VALUES (2,'Educational Institution','Paper Waste',500,'San Francisco');
|
SELECT GeneratorType, AVG(WasteQuantity) as AvgWasteQuantity FROM WasteGenerators WHERE WasteType = 'Paper Waste' AND GeneratorType = 'Educational Institution' GROUP BY GeneratorType;
|
Calculate the total budget for community education programs
|
CREATE TABLE budgets (id INT,category VARCHAR(255),amount INT); INSERT INTO budgets (id,category,amount) VALUES (1,'Habitat Restoration',30000),(2,'Habitat Maintenance',20000),(3,'Community Education',25000);
|
SELECT SUM(amount) as total_budget FROM budgets WHERE category = 'Community Education';
|
What is the average environmental impact score for production lines in Germany?
|
CREATE TABLE production_lines (line_id INT,line_name VARCHAR(50),country VARCHAR(50),environmental_impact_score DECIMAL(5,2)); INSERT INTO production_lines (line_id,line_name,country,environmental_impact_score) VALUES (1,'Line A','Germany',75.2),(2,'Line B','Germany',82.5),(3,'Line C','USA',60.0);
|
SELECT AVG(environmental_impact_score) FROM production_lines WHERE country = 'Germany';
|
What is the total number of mobile and broadband subscribers in each state?
|
CREATE TABLE mobile_subscribers (subscriber_id INT,subscriber_type VARCHAR(10),state VARCHAR(20)); INSERT INTO mobile_subscribers (subscriber_id,subscriber_type,state) VALUES (1,'mobile','WA'),(2,'mobile','NY'),(3,'broadband','WA'),(4,'mobile','CA'),(5,'broadband','NY');
|
SELECT state, COUNT(*) as total_subscribers FROM mobile_subscribers GROUP BY state;
|
Calculate the total number of climate mitigation projects in Oceania, excluding Australia and New Zealand.
|
CREATE TABLE climate_mitigation_projects (id INT PRIMARY KEY,project_type VARCHAR(50),country VARCHAR(50),year INT);
|
SELECT COUNT(*) AS total_projects FROM climate_mitigation_projects cmp WHERE country NOT IN ('Australia', 'New Zealand') AND country LIKE 'Oceania%';
|
What is the total billing amount for cases with outcome 'settled'?
|
CREATE TABLE cases (case_id INT,case_outcome TEXT,total_billing FLOAT); INSERT INTO cases (case_id,case_outcome,total_billing) VALUES (1,'settled',2000.00),(2,'won',3000.00),(3,'lost',1500.00);
|
SELECT SUM(total_billing) FROM cases WHERE case_outcome = 'settled';
|
What is the average monthly balance for each customer's account, partitioned by account type?
|
CREATE TABLE accounts (customer_id INT,account_type VARCHAR(20),balance DECIMAL(10,2));
|
SELECT account_type, AVG(balance) OVER (PARTITION BY account_type) FROM accounts;
|
Determine the percentage change in water consumption for the city of Atlanta between the years 2020 and 2021.
|
CREATE TABLE water_consumption (city VARCHAR(50),consumption FLOAT,year INT); INSERT INTO water_consumption (city,consumption,year) VALUES ('Atlanta',4500.5,2020),('Atlanta',4700.2,2021);
|
SELECT (SUM(consumption) * 100.0 / (SELECT SUM(consumption) FROM water_consumption WHERE city = 'Atlanta' AND year = 2020) - 100.0) AS pct_change FROM water_consumption WHERE city = 'Atlanta' AND year = 2021;
|
Find the total number of animals in African and North American regions
|
CREATE TABLE regions (id INT,region_name VARCHAR(255)); INSERT INTO regions (id,region_name) VALUES (1,'Asia'),(2,'Africa'),(3,'North America'); CREATE TABLE animal_location (id INT,animal_id INT,region_id INT); INSERT INTO animal_location (id,animal_id,region_id) VALUES (1,1,1),(2,2,2),(3,3,3); CREATE TABLE animals (id INT,animal_name VARCHAR(255),region_id INT); INSERT INTO animals (id,animal_name,region_id) VALUES (1,'Tiger',1),(2,'Elephant',2),(3,'Crane',3);
|
SELECT r.region_name, COUNT(a.id) as animal_count FROM regions r INNER JOIN animal_location al ON r.id = al.region_id INNER JOIN animals a ON al.animal_id = a.id WHERE r.region_name IN ('Africa', 'North America') GROUP BY r.region_name;
|
Count the number of Boeing aircraft.
|
CREATE TABLE AircraftManufacturing (aircraft_id INT,manufacturer VARCHAR(50),country VARCHAR(50)); INSERT INTO AircraftManufacturing (aircraft_id,manufacturer,country) VALUES (1,'Boeing','USA'),(2,'Airbus','Europe');
|
SELECT COUNT(*) FROM AircraftManufacturing WHERE manufacturer = 'Boeing';
|
What was the total budget for education programs in Q1 2023?
|
CREATE TABLE Programs (id INT,program_id INT,program_name VARCHAR(100),budget DECIMAL(10,2),start_date DATE,end_date DATE); INSERT INTO Programs (id,program_id,program_name,budget,start_date,end_date) VALUES (1,301,'Elementary Education',12000.00,'2023-01-01','2023-03-31'); INSERT INTO Programs (id,program_id,program_name,budget,start_date,end_date) VALUES (2,302,'High School Scholarships',15000.00,'2023-01-01','2023-03-31');
|
SELECT SUM(budget) FROM Programs WHERE program_id BETWEEN 301 AND 310 AND start_date <= '2023-03-31' AND end_date >= '2023-01-01';
|
What is the policy number, policyholder name, and issue date for policies issued in California?
|
CREATE TABLE policies (policy_number INT,policyholder_name TEXT,issue_date DATE,state TEXT); INSERT INTO policies (policy_number,policyholder_name,issue_date,state) VALUES (12345,'John Doe','2021-06-01','California');
|
SELECT policy_number, policyholder_name, issue_date FROM policies WHERE state = 'California';
|
What is the average carbon sequestration in coniferous forests?
|
CREATE TABLE coniferous_forests (id INT,carbon_sequestration FLOAT); INSERT INTO coniferous_forests VALUES (1,45.67),(2,56.78),(3,67.89);
|
SELECT AVG(carbon_sequestration) FROM coniferous_forests;
|
What is the average water temperature change per hour for each aquafarm in the Arctic region?
|
CREATE TABLE aquafarms (id INT,name TEXT,location TEXT); INSERT INTO aquafarms (id,name,location) VALUES (1,'Farm A','Pacific'),(2,'Farm B','Atlantic'),(5,'Farm E','Arctic'); CREATE TABLE temperature_data (aquafarm_id INT,timestamp TIMESTAMP,temperature FLOAT);
|
SELECT aquafarm_id, AVG(temp_diff) AS avg_temp_change, EXTRACT(HOUR FROM timestamp) AS hour FROM (SELECT aquafarm_id, temperature, LAG(temperature) OVER (PARTITION BY aquafarm_id ORDER BY timestamp) AS prev_temperature, (temperature - COALESCE(prev_temperature, temperature)) AS temp_diff FROM temperature_data) temperature_changes JOIN aquafarms ON temperature_changes.aquafarm_id = aquafarms.id WHERE location LIKE 'Arctic%' GROUP BY aquafarm_id, hour;
|
What was the total revenue from the 'Dance Recital' event?
|
CREATE TABLE Events (event_id INT,event_name VARCHAR(50),revenue INT); INSERT INTO Events (event_id,event_name,revenue) VALUES (2,'Dance Recital',12000);
|
SELECT revenue FROM Events WHERE event_name = 'Dance Recital';
|
What is the average daily oil production in Alaska, in barrels, for the last 3 months?
|
CREATE TABLE OilProduction (ProductionID INT,Location VARCHAR(20),ProductionDate DATE,OilProduction INT); INSERT INTO OilProduction (ProductionID,Location,ProductionDate,OilProduction) VALUES (1,'Alaska','2022-01-01',15000),(2,'Alaska','2022-01-02',16000),(3,'Alaska','2022-01-03',14000);
|
SELECT AVG(OilProduction) FROM OilProduction WHERE Location = 'Alaska' AND ProductionDate >= DATEADD(month, -3, GETDATE());
|
What is the average manufacturing time for each garment type in East Asia?
|
CREATE TABLE garment_manufacturing (garment_id INT,garment_type VARCHAR(50),region VARCHAR(50),manufacturing_time INT); CREATE TABLE garments (garment_id INT,garment_name VARCHAR(50));
|
SELECT garment_type, AVG(manufacturing_time) FROM garment_manufacturing JOIN garments ON garment_manufacturing.garment_id = garments.garment_id WHERE region = 'East Asia' GROUP BY garment_type;
|
Find the top 5 hotels with the highest CO2 emission?
|
CREATE TABLE Hotels (id INT,name TEXT,country TEXT,type TEXT,co2_emission INT); INSERT INTO Hotels (id,name,country,type,co2_emission) VALUES (1,'Eco Hotel','France','Eco',50);
|
SELECT name, SUM(co2_emission) AS total_emission FROM Hotels GROUP BY name ORDER BY total_emission DESC LIMIT 5;
|
What is the total revenue for each event in the 'concerts' table?
|
CREATE TABLE concerts (event_id INT,event_name VARCHAR(50),location VARCHAR(50),date DATE,ticket_price DECIMAL(5,2),num_tickets INT);
|
SELECT event_name, SUM(ticket_price * num_tickets) as total_revenue FROM concerts GROUP BY event_name;
|
Which smart city initiatives have been implemented in the top 5 most populous cities?
|
CREATE TABLE City (city_id INT,city_name VARCHAR(50),city_population INT); CREATE TABLE Initiative (initiative_id INT,initiative_name VARCHAR(50),city_id INT);
|
SELECT City.city_name, Initiative.initiative_name FROM City JOIN Initiative ON City.city_id = Initiative.city_id WHERE City.city_population IN (SELECT city_population FROM City ORDER BY city_population DESC LIMIT 5);
|
Number of eco-friendly hotels in each country?
|
CREATE TABLE eco_hotels_extended (hotel_id INT,name TEXT,country TEXT); INSERT INTO eco_hotels_extended (hotel_id,name,country) VALUES (1,'Le Hameau de la Vallée','France'),(2,'Hotel Eco Vie','France'),(3,'Eco Resort','Italy'),(4,'Green Hotel','Spain');
|
SELECT country, COUNT(*) FROM eco_hotels_extended GROUP BY country;
|
What is the total number of military technology patents filed by each country in the last 5 years, and what are the names of those technologies?
|
CREATE TABLE military_tech_patents (id INT,country VARCHAR(50),tech VARCHAR(50),year INT,patent_number INT); INSERT INTO military_tech_patents (id,country,tech,year,patent_number) VALUES (1,'USA','Drones',2017,100),(2,'USA','Cybersecurity',2017,101),(3,'USA','Artificial Intelligence',2017,102),(4,'China','Drones',2017,200),(5,'China','Cybersecurity',2017,201),(6,'China','Artificial Intelligence',2017,202),(7,'Russia','Drones',2017,300),(8,'Russia','Cybersecurity',2017,301),(9,'Russia','Artificial Intelligence',2017,302);
|
SELECT country, tech, SUM(patent_number) as total_patents FROM military_tech_patents WHERE year BETWEEN 2017 AND 2021 GROUP BY country, tech;
|
Delete the record for Site C from the environmental impact table.
|
CREATE TABLE environmental_impact (site_id INT,site_name TEXT,ei_score FLOAT); INSERT INTO environmental_impact (site_id,site_name,ei_score) VALUES (1,'Site A',75),(3,'Site C',60);
|
DELETE FROM environmental_impact WHERE site_id = 3;
|
Insert data into the "satellites" table for a satellite named "Hubble Space Telescope", launched on 1990-04-24, from USA, with function "Astronomy".
|
CREATE TABLE satellites (name TEXT,launch_date DATE,country TEXT,function TEXT);
|
INSERT INTO satellites (name, launch_date, country, function) VALUES ('Hubble Space Telescope', '1990-04-24', 'USA', 'Astronomy');
|
What is the rating of the product with the lowest product_id?
|
CREATE TABLE products (product_id INT,rating FLOAT); INSERT INTO products (product_id,rating) VALUES (1,4.5),(2,4.8),(3,3.2);
|
SELECT rating FROM products ORDER BY product_id LIMIT 1;
|
What is the maximum number of mental health parity violations in a single region?
|
CREATE TABLE mental_health_parity (violation_id INT,violation_date DATE,region VARCHAR(255)); INSERT INTO mental_health_parity (violation_id,violation_date,region) VALUES (1,'2021-01-01','Northeast'),(2,'2021-02-01','Southeast'),(3,'2021-03-01','Northeast');
|
SELECT region, MAX(violation_count) FROM (SELECT region, COUNT(violation_id) AS violation_count FROM mental_health_parity GROUP BY region) AS subquery GROUP BY region;
|
How many vehicles are assigned to route 505?
|
CREATE TABLE routes (route_id INT,name VARCHAR(255)); INSERT INTO routes (route_id,name) VALUES (505,'Route 505'); CREATE TABLE vehicles (vehicle_id INT,route_id INT,model VARCHAR(255)); INSERT INTO vehicles (vehicle_id,route_id,model) VALUES (1001,505,'Bus A'),(1002,505,'Bus B');
|
SELECT COUNT(*) FROM vehicles WHERE route_id = 505;
|
What is the maximum duration of a workout for each member?
|
CREATE TABLE Workouts (Id INT,MemberId INT,Duration INT,Date DATE); INSERT INTO Workouts (Id,MemberId,Duration,Date) VALUES (1,1,60,'2022-01-01'),(2,1,45,'2022-01-02'),(3,2,90,'2022-01-01'),(4,2,75,'2022-01-03'),(5,3,120,'2022-01-01');
|
SELECT MemberId, MAX(Duration) FROM Workouts GROUP BY MemberId;
|
What was the average price per gram of cannabis flower at each dispensary in Q1 2022?
|
CREATE TABLE flower_prices (dispensary_id INT,sale_date DATE,price DECIMAL(10,2)); INSERT INTO flower_prices (dispensary_id,sale_date,price) VALUES (1,'2022-01-01',12),(1,'2022-01-15',10),(1,'2022-02-05',14),(2,'2022-01-03',15),(2,'2022-01-31',11),(2,'2022-02-20',13);
|
SELECT d.name, AVG(fp.price / fs.weight) as avg_price_per_gram FROM flower_sales fs JOIN flower_prices fp ON fs.dispensary_id = fp.dispensary_id AND fs.sale_date = fp.sale_date JOIN dispensaries d ON fs.dispensary_id = d.id WHERE fs.sale_date BETWEEN '2022-01-01' AND '2022-03-31' GROUP BY d.name;
|
What is the average ocean acidity in the 'Southern Ocean' over the last 5 years?
|
CREATE TABLE ocean_acidity (id INTEGER,location TEXT,acidity FLOAT,date DATE);
|
SELECT AVG(acidity) FROM ocean_acidity WHERE location = 'Southern Ocean' AND date >= DATEADD(year, -5, CURRENT_DATE);
|
What is the number of community education programs conducted by each organization in the Antarctic conservation programs?
|
CREATE TABLE antarctic_education_programs (organization VARCHAR(50),program_date DATE); INSERT INTO antarctic_education_programs (organization,program_date) VALUES ('Organization A','2020-01-01'),('Organization B','2019-12-15'),('Organization A','2018-06-20');
|
SELECT organization, COUNT(*) FROM antarctic_education_programs GROUP BY organization;
|
What is the average number of professional development courses completed by teachers in each region?
|
CREATE TABLE teachers (id INT,region TEXT,courses_completed INT);
|
SELECT region, AVG(courses_completed) FROM teachers GROUP BY region;
|
What is the most popular color of sustainable fashion products?
|
CREATE TABLE sales (id INT,product_type VARCHAR(20),color VARCHAR(20),revenue DECIMAL); INSERT INTO sales (id,product_type,color,revenue) VALUES (1,'sustainable','green',100.00),(2,'regular','blue',200.00),(3,'sustainable','green',300.00),(4,'regular','red',400.00),(5,'sustainable','blue',500.00);
|
SELECT color, COUNT(*) FROM sales WHERE product_type = 'sustainable' GROUP BY color ORDER BY COUNT(*) DESC LIMIT 1;
|
Determine the daily oil production for a specific platform in Q2 2020
|
CREATE TABLE daily_oil_production (platform_id INT,production_date DATE,oil_production FLOAT); INSERT INTO daily_oil_production (platform_id,production_date,oil_production) VALUES (1,'2020-04-01',50),(1,'2020-04-02',60),(1,'2020-04-03',70),(1,'2020-05-01',80),(1,'2020-05-02',90),(1,'2020-05-03',100);
|
SELECT production_date, oil_production FROM daily_oil_production WHERE platform_id = 1 AND YEAR(production_date) = 2020 AND MONTH(production_date) BETWEEN 2 AND 5;
|
What is the total number of students in each program?
|
CREATE TABLE students (student_id INT,program VARCHAR(20)); INSERT INTO students (student_id,program) VALUES (1,'remote_learning'),(2,'remote_learning'),(3,'in_person'),(4,'in_person');
|
SELECT program, COUNT(*) FROM students GROUP BY program;
|
What is the latest light_level reading from the greenhouse_sensors table?
|
CREATE TABLE greenhouse_sensors (id INT,sensor_type VARCHAR(20),temperature DECIMAL(5,2),humidity DECIMAL(5,2),light_level INT,timestamp TIMESTAMP); INSERT INTO greenhouse_sensors (id,sensor_type,temperature,humidity,light_level,timestamp) VALUES (1,'temperature',22.5,60,500,'2022-01-01 10:00:00'),(2,'humidity',65,22.5,300,'2022-01-01 10:00:00'),(3,'light',NULL,NULL,600,'2022-01-01 11:00:00');
|
SELECT MAX(timestamp), light_level FROM greenhouse_sensors WHERE sensor_type = 'light' AND light_level IS NOT NULL;
|
What is the average rating of eco-friendly skincare products?
|
CREATE TABLE cosmetics (product_id INT,product_name VARCHAR(100),rating DECIMAL(2,1),is_eco_friendly BOOLEAN,product_type VARCHAR(50));
|
SELECT AVG(rating) FROM cosmetics WHERE is_eco_friendly = TRUE AND product_type = 'skincare';
|
What is the average response time for citizen feedback records in the state of Florida?
|
CREATE TABLE citizen_feedback_records (state VARCHAR(20),response_time INT); INSERT INTO citizen_feedback_records (state,response_time) VALUES ('Florida',48); INSERT INTO citizen_feedback_records (state,response_time) VALUES ('Florida',52); INSERT INTO citizen_feedback_records (state,response_time) VALUES ('Texas',40); INSERT INTO citizen_feedback_records (state,response_time) VALUES ('Texas',45);
|
SELECT AVG(response_time) FROM citizen_feedback_records WHERE state = 'Florida';
|
Get the number of players who have adopted VR technology from each country.
|
CREATE TABLE Players (PlayerID INT PRIMARY KEY,PlayerName VARCHAR(100),Country VARCHAR(50),VRAdoption BOOLEAN); INSERT INTO Players VALUES (1,'Lea','France',TRUE);
|
SELECT Country, COUNT(*) as NumPlayers FROM Players WHERE VRAdoption = TRUE GROUP BY Country;
|
Show the total amount of raw materials imported and exported by each country in the manufacturing domain.
|
CREATE TABLE imports (id INT,country VARCHAR(20),material VARCHAR(30),quantity INT); CREATE TABLE exports (id INT,country VARCHAR(20),material VARCHAR(30),quantity INT); INSERT INTO imports (id,country,material,quantity) VALUES (1,'USA','Steel',5000),(2,'USA','Aluminum',7000),(3,'China','Steel',8000),(4,'China','Aluminum',9000); INSERT INTO exports (id,country,material,quantity) VALUES (1,'USA','Steel',4000),(2,'USA','Aluminum',6000),(3,'China','Steel',7000),(4,'China','Aluminum',8000);
|
SELECT i.country, SUM(i.quantity) AS total_imported, SUM(e.quantity) AS total_exported FROM imports i INNER JOIN exports e ON i.country = e.country GROUP BY i.country;
|
What are the clinical trial outcomes for drugs in the neurology department?
|
CREATE TABLE clinical_trials (id INT,drug_id INT,trial_name VARCHAR(50),outcome VARCHAR(50)); INSERT INTO clinical_trials (id,drug_id,trial_name,outcome) VALUES (1,1,'TrialA','Success'),(2,1,'TrialB','Failure'),(3,2,'TrialC','Success'),(4,3,'TrialD','Success');
|
SELECT ct.drug_id, ct.trial_name, ct.outcome FROM clinical_trials ct WHERE ct.drug_id IN (SELECT id FROM drugs WHERE department = 'Neurology');
|
What is the name of the capital city of South Africa and its population?
|
CREATE TABLE Cities (CityID int,CityName varchar(255),Country varchar(255),Population int); INSERT INTO Cities (CityID,CityName,Country,Population) VALUES (1,'Pretoria','South Africa',2000000);
|
SELECT CityName, Population FROM Cities WHERE Country = 'South Africa' AND CityName = 'Pretoria';
|
What is the average number of fouls committed by players from Argentina in the 'World Cup'?
|
CREATE TABLE players (player_id INT,name TEXT,country TEXT); INSERT INTO players (player_id,name,country) VALUES (1,'Messi','Argentina'),(2,'Di Maria','Argentina'),(3,'Kane','England'); CREATE TABLE fouls (foul_id INT,player_id INT,fouls INT); INSERT INTO fouls (foul_id,player_id,fouls) VALUES (1,1,2),(2,1,3),(3,2,1),(4,3,5); CREATE TABLE games (game_id INT,player_id INT,tournament TEXT); INSERT INTO games (game_id,player_id,tournament) VALUES (1,1,'World Cup'),(2,1,'World Cup'),(3,2,'World Cup'),(4,3,'World Cup');
|
SELECT AVG(fouls) FROM fouls JOIN games ON fouls.player_id = games.player_id JOIN players ON fouls.player_id = players.player_id WHERE players.country = 'Argentina' AND games.tournament = 'World Cup';
|
What is the maximum financial wellbeing score in Canada?
|
CREATE TABLE if not exists financial_wellbeing (id INT,user_id INT,country VARCHAR(255),score INT); INSERT INTO financial_wellbeing (id,user_id,country,score) VALUES (1,1,'Canada',70),(2,2,'USA',80),(3,3,'Canada',90);
|
SELECT MAX(score) FROM financial_wellbeing WHERE country = 'Canada';
|
What is the total weight of materials used in each production facility for the past year?
|
CREATE TABLE Facility_Materials (facility_id INT,source_date DATE,material_weight FLOAT);
|
SELECT Facility_Materials.facility_id, SUM(Facility_Materials.material_weight) as total_weight FROM Facility_Materials WHERE source_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY Facility_Materials.facility_id;
|
What is the maximum water consumption per day in the wastewater treatment plant located in Miami?
|
CREATE TABLE WastewaterTreatmentData (plant_location VARCHAR(20),water_consumption_per_day FLOAT); INSERT INTO WastewaterTreatmentData (plant_location,water_consumption_per_day) VALUES ('Miami',5000000),('Tampa',4000000);
|
SELECT MAX(water_consumption_per_day) FROM WastewaterTreatmentData WHERE plant_location = 'Miami';
|
What is the total number of public parks in urban areas?
|
CREATE TABLE Parks (ID INT,Area VARCHAR(50),Type VARCHAR(50)); INSERT INTO Parks VALUES (1,'Urban','Public'),(2,'Rural','Community'),(3,'Urban','Private');
|
SELECT COUNT(*) FROM Parks WHERE Area = 'Urban' AND Type = 'Public';
|
How many donors are there in each age group (5-year intervals)?
|
CREATE TABLE donors (id INT,age INT); INSERT INTO donors (id,age) VALUES (1,32),(2,45),(3,28),(4,52),(5,18),(6,23),(7,48),(8,37),(9,57),(10,21);
|
SELECT FLOOR(age/5)*5 as age_group, COUNT(*) as num_donors FROM donors GROUP BY age_group;
|
List all peacekeeping operations led by ASEAN member countries since 2000, with their start and end dates and the number of personnel involved, ordered by the most recent operations.
|
CREATE TABLE PeacekeepingOperations (leader VARCHAR(255),operation VARCHAR(255),start_date DATE,end_date DATE,personnel INT); INSERT INTO PeacekeepingOperations (leader,operation,start_date,end_date,personnel) VALUES ('Indonesia','Aceh Monitoring Mission','2005-12-15','2006-12-15',500); INSERT INTO PeacekeepingOperations (leader,operation,start_date,end_date,personnel) VALUES ('Malaysia','UNAMID','2007-07-31','2021-06-30',3000);
|
SELECT leader, operation, start_date, end_date, personnel, ROW_NUMBER() OVER (PARTITION BY leader ORDER BY start_date DESC) as operation_rank FROM PeacekeepingOperations WHERE leader LIKE 'ASEAN%' AND start_date >= '2000-01-01' ORDER BY start_date DESC;
|
What is the number of circular economy initiatives for each country in Europe in 2020?
|
CREATE TABLE circular_economy (country VARCHAR(50),year INT,initiatives INT); INSERT INTO circular_economy (country,year,initiatives) VALUES ('France',2020,12),('Germany',2020,15),('Italy',2020,18),('Spain',2020,10),('United Kingdom',2020,20);
|
SELECT country, initiatives FROM circular_economy WHERE year = 2020;
|
Delete all records from the 'training_programs' table for the 'IT' department
|
CREATE TABLE training_programs (id INT,department VARCHAR(20),program VARCHAR(50),date DATE,completed BOOLEAN); INSERT INTO training_programs (id,department,program,date,completed) VALUES (1,'IT','Python','2022-01-01',true);
|
DELETE FROM training_programs WHERE department = 'IT';
|
What are the names of all marine species and their respective families with a population greater than 1000?
|
CREATE TABLE Species (id INT PRIMARY KEY,name VARCHAR(255),family VARCHAR(255),population INT);
|
SELECT name, family FROM Species WHERE population > 1000;
|
What is the total number of accidents in the diamond mines in the last 5 years?
|
CREATE TABLE Accidents (MineID INT,MineType VARCHAR(15),AccidentDate DATE);
|
SELECT COUNT(*) FROM Accidents WHERE MineType = 'Diamond' AND AccidentDate >= DATEADD(year, -5, GETDATE());
|
List the names of all Green Building certifications established between 2000 and 2010, in ascending order.
|
CREATE SCHEMA green_buildings; CREATE TABLE certifications (certification_name VARCHAR(255),year_established INT); INSERT INTO certifications (certification_name,year_established) VALUES ('LEED',2000),('BREEAM',1998),('Green Star',2008),('WELL',2014);
|
SELECT certification_name FROM green_buildings.certifications WHERE year_established >= 2000 AND year_established <= 2010 ORDER BY certification_name;
|
Calculate the average energy savings (in kWh) for each technology type, per year in the 'energy_savings' table
|
CREATE TABLE energy_savings (id INT,building_id INT,technology VARCHAR(50),energy_savings_kwh FLOAT,saving_date DATE);
|
SELECT technology, EXTRACT(YEAR FROM saving_date) as year, AVG(energy_savings_kwh) as avg_savings FROM energy_savings GROUP BY technology, year;
|
Who are the top 5 donors by total donation amount to the 'animal_welfare' cause?
|
CREATE TABLE donor (id INT,name VARCHAR(255)); CREATE TABLE donation (id INT,donor_id INT,cause VARCHAR(255),amount DECIMAL(10,2)); INSERT INTO donor (id,name) VALUES (1,'Jane Doe'),(2,'John Smith'),(3,'Mary Johnson'); INSERT INTO donation (id,donor_id,cause,amount) VALUES (1,1,'animal_welfare',500),(2,1,'climate_change',300),(3,2,'animal_welfare',1000),(4,3,'climate_change',200);
|
SELECT donor_id, SUM(amount) as total_donations FROM donation WHERE cause = 'animal_welfare' GROUP BY donor_id ORDER BY total_donations DESC LIMIT 5;
|
Find the number of unique artists who have performed in each country, excluding artists who have performed in only one city.
|
CREATE TABLE concerts (id INT,country VARCHAR(255),city VARCHAR(255),artist_name VARCHAR(255),tier VARCHAR(255),price DECIMAL(10,2),num_tickets INT); CREATE VIEW artist_countries AS SELECT artist_name,country FROM concerts;
|
SELECT country, COUNT(DISTINCT artist_name) AS num_artists FROM artist_countries GROUP BY country HAVING COUNT(DISTINCT city) > 1;
|
What is the average safety score for chemical production plants located in California, ordered by the score in descending order?
|
CREATE TABLE plants (id INT,name TEXT,location TEXT,safety_score FLOAT); INSERT INTO plants (id,name,location,safety_score) VALUES (1,'ABC Plant','California',85.6),(2,'XYZ Plant','California',92.3);
|
SELECT AVG(safety_score) AS avg_safety_score FROM plants WHERE location = 'California' ORDER BY safety_score DESC;
|
List all transactions involving sustainable tourism activities in Canada.
|
CREATE TABLE transactions (transaction_id INT,activity_type TEXT,country TEXT); INSERT INTO transactions (transaction_id,activity_type,country) VALUES (1,'Sustainable Transportation','Canada'),(2,'Eco-Friendly Accommodation','Canada'),(3,'Cultural Heritage Preservation','USA');
|
SELECT * FROM transactions WHERE activity_type LIKE '%sustainable%' AND country = 'Canada';
|
What is the minimum ESG score for companies in the 'technology' sector?
|
CREATE TABLE companies (id INT,sector VARCHAR(20),ESG_score FLOAT); INSERT INTO companies (id,sector,ESG_score) VALUES (1,'technology',78.3),(2,'finance',65.2),(3,'technology',74.5);
|
SELECT MIN(ESG_score) FROM companies WHERE sector = 'technology';
|
Insert a new record for a player from 'Brazil' who uses Oculus and prefers PC gaming.
|
CREATE TABLE Players (PlayerID INT,Country VARCHAR(20),VRPlatform VARCHAR(10),PrefersPC BOOLEAN);
|
INSERT INTO Players (PlayerID, Country, VRPlatform, PrefersPC) VALUES (3, 'Brazil', 'Oculus', TRUE);
|
What is the total donation amount by age group?
|
CREATE TABLE donor (did INT,age INT,total_donation DECIMAL(10,2)); INSERT INTO donor (did,age,total_donation) VALUES (1,30,1500),(2,45,1200),(3,22,800),(4,50,1700),(5,28,900);
|
SELECT age_group, SUM(total_donation) as total_donation FROM (SELECT CASE WHEN age < 30 THEN '18-30' WHEN age < 50 THEN '31-50' ELSE '51+' END as age_group, total_donation FROM donor) t GROUP BY age_group;
|
What is the total number of employees for each mining company?
|
CREATE TABLE MiningCompanies (CompanyID INT,CompanyName VARCHAR(255)); INSERT INTO MiningCompanies (CompanyID,CompanyName) VALUES (1,'ABC Mining'); INSERT INTO MiningCompanies (CompanyID,CompanyName) VALUES (2,'XYZ Excavation'); CREATE TABLE Employees (EmployeeID INT,CompanyID INT,FirstName VARCHAR(255),LastName VARCHAR(255)); INSERT INTO Employees (EmployeeID,CompanyID,FirstName,LastName) VALUES (1,1,'John','Doe'); INSERT INTO Employees (EmployeeID,CompanyID,FirstName,LastName) VALUES (2,1,'Jane','Doe'); INSERT INTO Employees (EmployeeID,CompanyID,FirstName,LastName) VALUES (3,2,'Mike','Smith');
|
SELECT e.CompanyID, COUNT(e.EmployeeID) as TotalEmployees FROM Employees e GROUP BY e.CompanyID;
|
Delete all records from the 'athlete_wellbeing' table where the wellbeing_program is 'Meditation'
|
CREATE TABLE athlete_wellbeing (athlete_id INT,wellbeing_program VARCHAR(20)); INSERT INTO athlete_wellbeing (athlete_id,wellbeing_program) VALUES (1,'Yoga'),(2,'Meditation'),(3,'Stretching');
|
DELETE FROM athlete_wellbeing WHERE wellbeing_program = 'Meditation';
|
List the names and treatment start dates of patients who have been treated with Cognitive Behavioral Therapy (CBT) or Dialectical Behavior Therapy (DBT)
|
CREATE TABLE patients (patient_id INT,name VARCHAR(50),age INT,state VARCHAR(50)); CREATE TABLE therapy_sessions (session_id INT,patient_id INT,therapist_id INT,session_date DATE,therapy_type VARCHAR(50)); INSERT INTO patients VALUES (1,'John Doe',35,'California'); INSERT INTO patients VALUES (2,'Jane Smith',28,'California'); INSERT INTO therapy_sessions VALUES (1,1,101,'2022-01-01','CBT'); INSERT INTO therapy_sessions VALUES (2,2,102,'2022-02-01','DBT');
|
SELECT patients.name, therapy_sessions.session_date FROM patients JOIN therapy_sessions ON patients.patient_id = therapy_sessions.patient_id WHERE therapy_sessions.therapy_type IN ('CBT', 'DBT');
|
What is the total fare collected for trains in the 'west' region in the last month?
|
CREATE TABLE Trains (id INT,region VARCHAR(10),fare_collected DECIMAL(5,2)); INSERT INTO Trains (id,region,fare_collected) VALUES (1,'west',200.00),(2,'west',300.00),(3,'east',150.00);
|
SELECT SUM(Trains.fare_collected) FROM Trains WHERE Trains.region = 'west' AND Trains.fare_collected > 0 AND Trains.fare_collected IS NOT NULL AND Trains.fare_collected <> '';
|
What is the average investment in climate adaptation per project in Asia?
|
CREATE TABLE climate_investment (id INT,country VARCHAR(50),type VARCHAR(50),investment FLOAT); INSERT INTO climate_investment (id,country,type,investment) VALUES (1,'China','climate adaptation',500000.00),(2,'India','climate mitigation',750000.00),(3,'Indonesia','climate adaptation',600000.00);
|
SELECT AVG(investment) FROM climate_investment WHERE country IN ('China', 'India', 'Indonesia', 'Japan', 'Vietnam') AND type = 'climate adaptation';
|
Delete records of wastewater treatment plants with a "PlantID" greater than 1000.
|
CREATE TABLE WastewaterTreatmentPlants (PlantID INT,PlantName VARCHAR(50),Location VARCHAR(50),Capacity FLOAT); INSERT INTO WastewaterTreatmentPlants (PlantID,PlantName,Location,Capacity) VALUES (1,'PlantA','LocationA',500.5),(2,'PlantB','LocationB',600.2),(1001,'PlantX','LocationX',800.0);
|
DELETE FROM WastewaterTreatmentPlants WHERE PlantID > 1000;
|
Show the 3-month moving average of production for each site.
|
CREATE TABLE Site_Production (Site_ID INT,Production_Date DATE,Production_Quantity INT); INSERT INTO Site_Production (Site_ID,Production_Date,Production_Quantity) VALUES (1,'2022-01-01',500),(1,'2022-02-01',550),(1,'2022-03-01',600),(2,'2022-01-01',800),(2,'2022-02-01',850),(2,'2022-03-01',900);
|
SELECT Site_ID, AVG(Production_Quantity) OVER (PARTITION BY Site_ID ORDER BY Production_Date ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) as Three_Month_Moving_Avg FROM Site_Production;
|
Which countries have been involved in the most defense diplomacy events in the last 7 years, along with the number of events?
|
CREATE TABLE DefenseDiplomacy (ID INT,EventName TEXT,EventDate DATE,Country TEXT,ParticipatingCountries TEXT); INSERT INTO DefenseDiplomacy VALUES (1,'Event 1','2016-01-01','USA','Canada,Mexico'); CREATE VIEW DiplomacyCountries AS SELECT Country FROM DefenseDiplomacy WHERE Country IN ('USA','Canada','Mexico','Brazil','Argentina');
|
SELECT dc.Country, COUNT(*) as DiplomacyCount FROM DefenseDiplomacy d JOIN DiplomacyCountries dc ON d.Country = dc.Country WHERE d.EventDate BETWEEN DATEADD(year, -7, GETDATE()) AND GETDATE() GROUP BY dc.Country ORDER BY DiplomacyCount DESC;
|
What is the minimum workplace safety fine issued by OSHA in each region?
|
CREATE TABLE osha_fines (fine_id INT,region TEXT,amount INT); INSERT INTO osha_fines (fine_id,region,amount) VALUES (1,'Northeast',5000),(2,'West Coast',10000),(3,'South',7500);
|
SELECT region, MIN(amount) OVER (PARTITION BY region) FROM osha_fines;
|
Which countries have more than 3 heritage sites?
|
CREATE TABLE HeritageSites (SiteID int,SiteName varchar(50),Country varchar(50)); INSERT INTO HeritageSites (SiteID,SiteName,Country) VALUES (1,'Giza Pyramids','Egypt'),(2,'African Renaissance Monument','Senegal'),(3,'Taj Mahal','India'),(4,'Angkor Wat','Cambodia'),(5,'Machu Picchu','Peru'),(6,'Petra','Jordan'),(7,'Colosseum','Italy');
|
SELECT Country, COUNT(*) FROM HeritageSites GROUP BY Country HAVING COUNT(*) > 3;
|
What is the total number of volunteer hours contributed by volunteers from the USA and Canada in Q3 2021?
|
CREATE TABLE Volunteers (id INT,name TEXT,country TEXT,hours FLOAT,quarter TEXT,year INT); INSERT INTO Volunteers (id,name,country,hours,quarter,year) VALUES (1,'Alice','USA',5.0,'Q3',2021),(2,'Bob','Canada',7.5,'Q3',2021);
|
SELECT SUM(hours) FROM Volunteers WHERE country IN ('USA', 'Canada') AND quarter = 'Q3' AND year = 2021;
|
List all suppliers and their average delivery time for components, arranged alphabetically by supplier name.
|
CREATE TABLE suppliers (supplier_id INT,supplier_name VARCHAR(50)); INSERT INTO suppliers (supplier_id,supplier_name) VALUES (1,'ABC Supplies'),(2,'XYZ Components'),(3,'Green Solutions'); CREATE TABLE deliveries (delivery_id INT,supplier_id INT,component_quantity INT,delivery_time INT); INSERT INTO deliveries (delivery_id,supplier_id,component_quantity,delivery_time) VALUES (1,1,200,3),(2,1,300,2),(3,2,150,4),(4,2,450,5),(5,3,50,1),(6,3,100,3);
|
SELECT supplier_name, AVG(delivery_time) as avg_delivery_time FROM deliveries JOIN suppliers ON deliveries.supplier_id = suppliers.supplier_id GROUP BY supplier_name ORDER BY supplier_name;
|
Update the 'end_date' value for the record with 'project_id' = 2 in the 'infrastructure_development' table to '2023-12-31'
|
CREATE TABLE infrastructure_development (project_id INT,location VARCHAR(30),start_date DATE,end_date DATE,cost INT); INSERT INTO infrastructure_development (project_id,location,start_date,end_date,cost) VALUES (1,'North Sea','2017-01-01','2021-12-31',300000000); INSERT INTO infrastructure_development (project_id,location,start_date,end_date,cost) VALUES (2,'Gulf of Mexico','2019-06-15','2022-12-31',400000000);
|
UPDATE infrastructure_development SET end_date = '2023-12-31' WHERE project_id = 2;
|
What is the total number of volunteers in the 'volunteer_program' table, grouped by age range (18-30, 31-40, 41-50)?
|
CREATE TABLE volunteer_program (id INT,name VARCHAR(50),age INT,location VARCHAR(30)); INSERT INTO volunteer_program (id,name,age,location) VALUES (1,'John Doe',25,'New York'),(2,'Jane Smith',32,'California'),(3,'Alice Johnson',22,'Texas');
|
SELECT CASE WHEN age BETWEEN 18 AND 30 THEN '18-30' WHEN age BETWEEN 31 AND 40 THEN '31-40' WHEN age BETWEEN 41 AND 50 THEN '41-50' ELSE '50+' END AS age_range, COUNT(*) FROM volunteer_program GROUP BY age_range;
|
Find the percentage of tourists who visited the United States in 2019
|
CREATE TABLE tourism_stats (destination VARCHAR(255),year INT,visitors INT); INSERT INTO tourism_stats (destination,year,visitors) VALUES ('United States',2019,30000000);
|
SELECT (visitors / (SELECT SUM(visitors) FROM tourism_stats) * 100) AS percentage FROM tourism_stats WHERE destination = 'United States' AND year = 2019;
|
What is the maximum billing amount for cases handled by attorneys who identify as female?
|
CREATE TABLE Attorneys (AttorneyID INT,Gender VARCHAR(10),BillingAmount DECIMAL); INSERT INTO Attorneys (AttorneyID,Gender,BillingAmount) VALUES (1,'Female',2500.00),(2,'Male',1800.00),(3,'Female',3200.00);
|
SELECT MAX(BillingAmount) FROM Attorneys WHERE Gender = 'Female';
|
What is the sum of all production budgets for films by female directors?
|
CREATE TABLE Films (film_id INT,title VARCHAR(255),release_date DATE,production_budget INT,director_gender VARCHAR(10)); INSERT INTO Films (film_id,title,release_date,production_budget,director_gender) VALUES (1,'Movie1','2000-01-01',5000000,'female'),(2,'Movie2','2005-01-01',7000000,'male'),(3,'Movie3','2010-01-01',3000000,'non-binary');
|
SELECT SUM(production_budget) FROM Films WHERE director_gender = 'female';
|
What are the top 5 most common types of malware, and how many instances of each type were detected in the last 90 days?
|
CREATE TABLE malware_types (type_id INT,type_name VARCHAR(100));CREATE TABLE malware_instances (instance_id INT,type_id INT,instance_date DATE);
|
SELECT mt.type_name, COUNT(mi.instance_id) as total_instances FROM malware_types mt JOIN malware_instances mi ON mt.type_id = mi.type_id WHERE mi.instance_date >= NOW() - INTERVAL 90 DAY GROUP BY mt.type_name ORDER BY total_instances DESC LIMIT 5;
|
What is the average carbon footprint of virtual tours in Paris?
|
CREATE TABLE virtual_tours (tour_id INT,name TEXT,city TEXT,carbon_footprint FLOAT); INSERT INTO virtual_tours (tour_id,name,city,carbon_footprint) VALUES (1,'Tour A','Paris',5.6),(2,'Tour B','Paris',4.9),(3,'Tour C','Paris',6.3);
|
SELECT AVG(carbon_footprint) FROM virtual_tours WHERE city = 'Paris';
|
How many attendees were from California for the 'Dance' program?
|
CREATE TABLE programs (program_id INT,program_name VARCHAR(255)); INSERT INTO programs (program_id,program_name) VALUES (1,'Artistic Expression'),(2,'Dance'); CREATE TABLE attendee_demographics (attendee_id INT,program_id INT,state VARCHAR(2)); INSERT INTO attendee_demographics (attendee_id,program_id,state) VALUES (1,1,'NY'),(2,1,'CA'),(3,1,'NY'),(4,2,'CA'),(5,2,'CA'),(6,2,'TX');
|
SELECT COUNT(*) as num_ca_attendees FROM attendee_demographics WHERE state = 'CA' AND program_id = (SELECT program_id FROM programs WHERE program_name = 'Dance');
|
Which artists have performed at music festivals in both the USA and Canada?
|
CREATE TABLE artist_festivals (artist_id INT,festival_name VARCHAR(30),festival_country VARCHAR(20)); INSERT INTO artist_festivals (artist_id,festival_name,festival_country) VALUES (1,'Coachella','USA'),(2,'Osheaga','Canada'),(3,'Bonnaroo','USA'),(4,'WayHome','Canada');
|
SELECT artist_id FROM artist_festivals WHERE festival_country IN ('USA', 'Canada') GROUP BY artist_id HAVING COUNT(DISTINCT festival_country) = 2;
|
What is the average yield of 'rice' per state?
|
CREATE TABLE states (id INT PRIMARY KEY,name TEXT,region TEXT); INSERT INTO states (id,name,region) VALUES (1,'Alabama','South'); CREATE TABLE crops (id INT PRIMARY KEY,state_id INT,crop TEXT,yield REAL); INSERT INTO crops (id,state_id,crop,yield) VALUES (1,1,'rice',2.5);
|
SELECT state_id, AVG(yield) FROM crops WHERE crop = 'rice' GROUP BY state_id;
|
How many volunteers engaged in 'program_x' in the 'q2' and 'q3' quarters?
|
CREATE TABLE Volunteers (id INT,program_name VARCHAR(20),volunteer_hours INT,volunteer_date DATE); INSERT INTO Volunteers (id,program_name,volunteer_hours,volunteer_date) VALUES (1,'program_x',5,'2022-04-01'); INSERT INTO Volunteers (id,program_name,volunteer_hours,volunteer_date) VALUES (2,'program_y',3,'2022-04-10'); INSERT INTO Volunteers (id,program_name,volunteer_hours,volunteer_date) VALUES (3,'program_x',7,'2022-07-01');
|
SELECT COUNT(*) FROM Volunteers WHERE program_name = 'program_x' AND (QUARTER(volunteer_date) = 2 OR QUARTER(volunteer_date) = 3);
|
List the bottom 2 mental health providers with the lowest health equity metric scores, along with their corresponding scores.
|
CREATE TABLE MentalHealthProviders (ProviderID INT,HealthEquityMetricScore INT); INSERT INTO MentalHealthProviders (ProviderID,HealthEquityMetricScore) VALUES (1,80),(2,85),(3,70),(4,90),(5,95),(6,88),(7,89);
|
SELECT ProviderID, HealthEquityMetricScore FROM (SELECT ProviderID, HealthEquityMetricScore, ROW_NUMBER() OVER (ORDER BY HealthEquityMetricScore ASC) as Rank FROM MentalHealthProviders) as RankedData WHERE Rank <= 2;
|
Select all data from 'TopGames'
|
CREATE TABLE GameDesign (GameID INT PRIMARY KEY,GameName VARCHAR(50),Genre VARCHAR(50),Platform VARCHAR(50)); INSERT INTO GameDesign (GameID,GameName,Genre,Platform) VALUES (1,'Fortnite','Battle Royale','PC'),(2,'Among Us','Party','Mobile'); CREATE VIEW TopGames AS SELECT * FROM GameDesign WHERE Platform = 'PC';
|
SELECT * FROM TopGames;
|
What was the total waste generation by material type in 2018, 2019, and 2020?
|
CREATE TABLE waste_generation_by_material(year INT,material VARCHAR(255),amount INT); INSERT INTO waste_generation_by_material VALUES (2018,'Paper',400),(2018,'Plastic',200),(2018,'Glass',300),(2019,'Paper',420),(2019,'Plastic',210),(2019,'Glass',310),(2020,'Paper',450),(2020,'Plastic',230),(2020,'Glass',330);
|
SELECT material, year, SUM(amount) FROM waste_generation_by_material GROUP BY material, year;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.