instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What was the total revenue for the state of California in Q3 2020?
CREATE TABLE sales (id INT,state VARCHAR(50),qty INT,revenue FLOAT,date DATE); INSERT INTO sales (id,state,qty,revenue,date) VALUES (1,'California',100,5000,'2020-07-01'); INSERT INTO sales (id,state,qty,revenue,date) VALUES (2,'California',200,8000,'2020-08-01'); INSERT INTO sales (id,state,qty,revenue,date) VALUES (3...
SELECT SUM(revenue) FROM sales WHERE state = 'California' AND date >= '2020-07-01' AND date <= '2020-09-30';
What is the number of movies released per year by a studio, such as 'Warner Bros. Pictures'?
CREATE TABLE movie_release_data (id INT,studio VARCHAR(255),release_year INT); INSERT INTO movie_release_data (id,studio,release_year) VALUES (1,'Warner Bros. Pictures',2000); INSERT INTO movie_release_data (id,studio,release_year) VALUES (2,'Warner Bros. Pictures',2002); INSERT INTO movie_release_data (id,studio,relea...
SELECT release_year, COUNT(*) as count FROM movie_release_data WHERE studio = 'Warner Bros. Pictures' GROUP BY release_year;
What is the maximum salary in the Sales department?
CREATE TABLE Employees (EmployeeID INT,Department VARCHAR(20),Salary FLOAT); INSERT INTO Employees (EmployeeID,Department,Salary) VALUES (1,'IT',75000.0),(2,'HR',65000.0),(3,'Sales',90000.0);
SELECT MAX(Salary) FROM Employees WHERE Department = 'Sales';
Find the earliest health equity metric by state.
CREATE TABLE HealthEquityMetrics (HEMId INT,Metric VARCHAR(255),State VARCHAR(50),MetricDate DATE); INSERT INTO HealthEquityMetrics (HEMId,Metric,State,MetricDate) VALUES (1,'Health Equity Index','California','2021-01-01'),(2,'Equity Score','Texas','2021-02-01'),(3,'Health Equity Report','Florida','2021-03-01'),(4,'Hea...
SELECT State, Metric, MetricDate FROM HealthEquityMetrics WHERE MetricDate = (SELECT MIN(MetricDate) FROM HealthEquityMetrics);
List consumer awareness campaigns related to ethical fashion by year.
CREATE TABLE consumer_awareness (id INT,campaign VARCHAR(255),year INT);
SELECT campaign, year FROM consumer_awareness ORDER BY year;
Which satellites were launched before 2010?
CREATE TABLE satellites (id INT,name VARCHAR(50),launch_year INT); INSERT INTO satellites (id,name,launch_year) VALUES (1,'Sat1',2005),(2,'Sat2',2012),(3,'Sat3',2008);
SELECT * FROM satellites WHERE launch_year < 2010;
List all the education projects funded by the EU in Jordan in 2019?
CREATE TABLE education_projects (project_name TEXT,funder TEXT,start_date DATE,end_date DATE,location TEXT); INSERT INTO education_projects (project_name,funder,start_date,end_date,location) VALUES ('Al-Zaatari Education Center','EU','2019-01-01','2019-12-31','Jordan'),('Azraq Learning Center','EU','2019-02-15','2019-1...
SELECT * FROM education_projects WHERE funder = 'EU' AND start_date BETWEEN '2019-01-01' AND '2019-12-31' AND location = 'Jordan';
What is the average fare for buses in the 'Southside' division?
CREATE TABLE buses (id INT,division VARCHAR(20),fare DECIMAL(5,2)); INSERT INTO buses (id,division,fare) VALUES (1,'Northside',2.50),(2,'Southside',3.25),(3,'Eastside',2.75),(4,'Westside',3.00);
SELECT AVG(fare) FROM buses WHERE division = 'Southside';
Update the ESG rating to 8.0 for the company with id 1 in the 'technology' sector.
CREATE TABLE companies (id INT,sector VARCHAR(20),ESG_rating FLOAT); INSERT INTO companies (id,sector,ESG_rating) VALUES (1,'technology',7.5),(2,'finance',8.2),(3,'technology',7.8);
UPDATE companies SET ESG_rating = 8.0 WHERE id = 1 AND sector = 'technology';
Insert a new ethical brand 'Green Vogue' into the 'Brands' table
CREATE TABLE Brands(id INT,name TEXT); INSERT INTO Brands(id,name) VALUES (1,'Eco Wear'),(2,'Natural Threads');
INSERT INTO Brands(id, name) VALUES (3, 'Green Vogue');
What is the average duration of pop songs on Apple Music from 2018?
CREATE TABLE songs (id INT,title VARCHAR(255),length INT,genre VARCHAR(255),platform VARCHAR(255)); INSERT INTO songs (id,title,length,genre,platform) VALUES (1,'Song 1',180,'Pop','Apple Music');
SELECT AVG(length) FROM songs WHERE genre = 'Pop' AND platform = 'Apple Music' AND YEAR(id) = 2018;
Identify wells with highest oil production in Q4 2021
CREATE TABLE if not exists fact_production (production_id INT PRIMARY KEY,well_id INT,date DATE,oil_volume DECIMAL(10,2),gas_volume DECIMAL(10,2)); CREATE TABLE if not exists dim_well (well_id INT PRIMARY KEY,well_name VARCHAR(255),location VARCHAR(255)); CREATE TABLE if not exists dim_date (date DATE PRIMARY KEY,year ...
SELECT dim_well.well_name, SUM(fact_production.oil_volume) AS total_oil_volume FROM fact_production INNER JOIN dim_well ON fact_production.well_id = dim_well.well_id INNER JOIN dim_date ON fact_production.date = dim_date.date WHERE dim_date.year = 2021 AND dim_date.quarter = 4 GROUP BY dim_well.well_name ORDER BY total...
Insert new multimodal routes in Paris
CREATE TABLE multimodal_routes (id INT,route_id INT,route_type VARCHAR(50),route_start_location VARCHAR(50),route_end_location VARCHAR(50));
INSERT INTO multimodal_routes (route_id, route_type, route_start_location, route_end_location) VALUES
List all properties in the CityOfSustainability schema with a rainwater harvesting system and their corresponding price, sorted by price in descending order.
CREATE TABLE CityOfSustainability.RainwaterHarvestingBuildings (id INT,price FLOAT); INSERT INTO CityOfSustainability.RainwaterHarvestingBuildings (id,price) VALUES (3,650000.0),(4,550000.0);
SELECT * FROM CityOfSustainability.RainwaterHarvestingBuildings ORDER BY price DESC;
How many emergency response units are there in the state of Texas that are ambulances?
CREATE TABLE EmergencyResponseUnits (id INT,state VARCHAR(20),unit_type VARCHAR(20),quantity INT);
SELECT SUM(quantity) FROM EmergencyResponseUnits WHERE state = 'Texas' AND unit_type = 'ambulance';
What is the percentage of patients diagnosed with cancer who are over the age of 65?
CREATE TABLE Patients (PatientID INT,Age INT,Gender TEXT,Diagnosis TEXT,State TEXT); INSERT INTO Patients (PatientID,Age,Gender,Diagnosis,State) VALUES (1,72,'Female','Cancer','California');
SELECT (COUNT(*) FILTER (WHERE Age > 65)) * 100.0 / COUNT(*) FROM Patients WHERE Diagnosis = 'Cancer';
What is the maximum environmental impact score for each mine type?
CREATE TABLE mines (id INT,name TEXT,type TEXT,environmental_impact INT); INSERT INTO mines (id,name,type,environmental_impact) VALUES (1,'Golden Mine','Gold',20),(2,'Silver Mine','Silver',15),(3,'Bronze Mine','Bronze',10),(4,'Platinum Mine','Platinum',30);
SELECT type, MAX(environmental_impact) as max_impact FROM mines GROUP BY type;
Which mobile subscribers have an active plan in the 'North' region and a device with iOS operating system?
CREATE TABLE mobile_subscribers (subscriber_id INT,region VARCHAR(20),plan_status VARCHAR(10),device_os VARCHAR(10)); INSERT INTO mobile_subscribers (subscriber_id,region,plan_status,device_os) VALUES (1,'North','active','iOS');
SELECT * FROM mobile_subscribers WHERE region = 'North' AND plan_status = 'active' AND device_os = 'iOS';
What are the most popular songs by genre?
CREATE TABLE Genres (genre_id INT,genre_name VARCHAR(255)); INSERT INTO Genres (genre_id,genre_name) VALUES (1,'Pop'),(2,'Rock'),(3,'Hip Hop'); CREATE TABLE Songs (song_id INT,genre_id INT,song_name VARCHAR(255),plays INT); INSERT INTO Songs (song_id,genre_id,song_name,plays) VALUES (1,1,'Song1',10000),(2,2,'Song2',150...
SELECT g.genre_name, s.song_name, SUM(s.plays) AS total_plays FROM Genres g INNER JOIN Songs s ON g.genre_id = s.genre_id GROUP BY g.genre_name, s.song_name ORDER BY total_plays DESC;
What is the percentage of citizens who are satisfied with public services in urban areas?
CREATE TABLE feedback (id INT,year INT,service TEXT,sentiment TEXT,city_type TEXT); INSERT INTO feedback (id,year,service,sentiment,city_type) VALUES (1,2021,'Healthcare','Positive','Urban'),(2,2022,'Healthcare','Neutral','Urban'); CREATE TABLE cities (id INT,name TEXT,population INT,type TEXT); INSERT INTO cities (id,...
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM feedback WHERE city_type = f.city_type)) AS percentage FROM feedback f WHERE f.sentiment = 'Positive' AND f.city_type = 'Urban';
Determine the average length of time it takes for a student to receive accommodations, grouped by the accommodation type.
CREATE TABLE Accommodation (AccID INT,AccName VARCHAR(50),StudentID INT,AccDate DATE,ApprovalDate DATE); INSERT INTO Accommodation (AccID,AccName,StudentID,AccDate,ApprovalDate) VALUES (1,'Sign Language Interpreter',1,'2021-01-01','2021-02-01'); INSERT INTO Accommodation (AccID,AccName,StudentID,AccDate,ApprovalDate) V...
SELECT AccName, AVG(DATEDIFF(DAY, AccDate, ApprovalDate)) AS AvgTime FROM Accommodation GROUP BY AccName;
What is the maximum and minimum feed cost for each fish species in the 'feeds' table?
CREATE TABLE feeds (id INT,fish_species TEXT,feed_cost FLOAT); INSERT INTO feeds (id,fish_species,feed_cost) VALUES (1,'Salmon',2.1); INSERT INTO feeds (id,fish_species,feed_cost) VALUES (2,'Tilapia',1.8); INSERT INTO feeds (id,fish_species,feed_cost) VALUES (3,'Salmon',2.2); INSERT INTO feeds (id,fish_species,feed_cos...
SELECT fish_species, MAX(feed_cost), MIN(feed_cost) FROM feeds GROUP BY fish_species;
What is the average energy efficiency (in kWh/m2/year) of residential buildings in Germany with a floor area between 80 and 120 m2, and how many of them have an energy efficiency rating of A or B?
CREATE TABLE germany_buildings (name TEXT,type TEXT,floor_area_m2 REAL,energy_efficiency_kwh_m2_year REAL,energy_efficiency_rating TEXT); INSERT INTO germany_buildings (name,type,floor_area_m2,energy_efficiency_kwh_m2_year,energy_efficiency_rating) VALUES ('Residential Building A','Residential',100,70,'A'),('Residentia...
SELECT AVG(energy_efficiency_kwh_m2_year) AS avg_efficiency, COUNT(*) FILTER (WHERE energy_efficiency_rating IN ('A', 'B')) AS num_buildings_rating_A_or_B FROM germany_buildings WHERE type = 'Residential' AND floor_area_m2 BETWEEN 80 AND 120;
What is the total sales volume for Vintage trends in Tokyo during 2020 from ethical sources?
CREATE TABLE Sales (sale_id INT,garment_id INT,location_id INT,sale_date DATE);CREATE TABLE Garments (garment_id INT,trend_id INT,fabric_source_id INT,size VARCHAR(50),style VARCHAR(255));CREATE TABLE FabricSources (source_id INT,fabric_type VARCHAR(255),country_of_origin VARCHAR(255),ethical_rating DECIMAL(3,2));CREAT...
SELECT SUM(sales_volume) FROM TokyoEthicalVintage WHERE sale_date BETWEEN '2020-01-01' AND '2020-12-31';
What is the total number of citizens registered to vote in each district in 'Voters' table?
CREATE TABLE Voters (VoterID INT,District VARCHAR(20),Registered BOOLEAN); INSERT INTO Voters (VoterID,District,Registered) VALUES (1,'DistrictA',TRUE),(2,'DistrictB',FALSE),(3,'DistrictA',TRUE);
SELECT District, COUNT(*) AS TotalRegistered FROM Voters WHERE Registered = TRUE GROUP BY District
What is the percentage of drought-affected areas in India in 2020?
CREATE TABLE drought_impact (country VARCHAR(20),year INT,pct_drought_area FLOAT); INSERT INTO drought_impact (country,year,pct_drought_area) VALUES ('India',2020,35.6);
SELECT pct_drought_area FROM drought_impact WHERE country = 'India' AND year = 2020;
What is the average time to market and total sales for each drug, including the drug name and its approval date, grouped by the therapeutic area it belongs to?
CREATE TABLE drugs (drug_id INT,name VARCHAR(255),approval_date DATE,company_id INT,therapeutic_area VARCHAR(255));CREATE TABLE sales (sale_id INT,drug_id INT,year INT,amount INT);
SELECT t.therapeutic_area, d.name as drug_name, d.approval_date, AVG(DATEDIFF(d.approval_date, d.development_start_date)) as avg_time_to_market, SUM(s.amount) as total_sales FROM drugs d JOIN sales s ON d.drug_id = s.drug_id JOIN (SELECT drug_id, AVG(DATEDIFF(approval_date, development_start_date)) as avg_time_to_marke...
What is the average funding amount for startups founded by people from the LGBTQ+ community in the blockchain sector?
CREATE TABLE startups(id INT,name TEXT,industry TEXT,foundation_date DATE,founder_lgbtq BOOLEAN,funding FLOAT); INSERT INTO startups(id,name,industry,foundation_date,founder_lgbtq,funding) VALUES (1,'BlockchainPride','Blockchain','2020-06-01',true,3000000);
SELECT AVG(funding) FROM startups WHERE industry = 'Blockchain' AND founder_lgbtq = true;
Update the score of a specific tennis match in the tennis_matches table
CREATE TABLE tennis_matches (id INT,team_1_id INT,team_2_id INT,score INT); INSERT INTO tennis_matches (id,team_1_id,team_2_id,score) VALUES (1,1,2,10),(2,2,3,15),(3,1,3,7);
UPDATE tennis_matches SET score = 12 WHERE id = 1;
What is the total amount of funding allocated for education in Texas for the current fiscal year, and how much has been spent so far?
CREATE TABLE education_funding (fiscal_year INT,state VARCHAR(255),allocation FLOAT,expenditure FLOAT); INSERT INTO education_funding (fiscal_year,state,allocation,expenditure) VALUES (2022,'Texas',10000.0,5000.0),(2022,'Texas',15000.0,8000.0),(2022,'Texas',20000.0,12000.0);
SELECT SUM(allocation) AS total_allocation, SUM(expenditure) AS total_expenditure FROM education_funding WHERE fiscal_year = 2022 AND state = 'Texas';
What is the total quantity of recycled materials used in product manufacturing per quarter?
CREATE TABLE products (product_id INT,product_name VARCHAR(255),recycled_material_quantity INT,manufacture_date DATE);
SELECT EXTRACT(QUARTER FROM manufacture_date) as quarter, SUM(recycled_material_quantity) as total_recycled_quantity FROM products GROUP BY quarter;
List mining sites in Zambia with EIA due dates in the next 6 months.
CREATE TABLE mining_sites (site_id INT,site_name VARCHAR(50),country VARCHAR(20)); INSERT INTO mining_sites (site_id,site_name,country) VALUES (1,'Mining Site A','Zambia'),(2,'Mining Site B','Zambia'),(3,'Mining Site C','Zambia'); CREATE TABLE eia_schedule (site_id INT,eia_date DATE); INSERT INTO eia_schedule (site_id,...
SELECT site_name FROM mining_sites INNER JOIN eia_schedule ON mining_sites.site_id = eia_schedule.site_id WHERE eia_schedule.eia_date BETWEEN DATE_ADD(CURDATE(), INTERVAL 6 MONTH) AND DATE_ADD(CURDATE(), INTERVAL 7 MONTH);
How many intelligence operations of type 'Infiltration' were conducted by countries in the African region in the past year?
CREATE TABLE operations (id INT,country VARCHAR(50),operation_type VARCHAR(50),operation_date DATE); INSERT INTO operations (id,country,operation_type,operation_date) VALUES (1,'Egypt','Infiltration','2021-02-15'); INSERT INTO operations (id,country,operation_type,operation_date) VALUES (2,'Algeria','Surveillance','202...
SELECT country, COUNT(*) as operation_count FROM operations WHERE operation_type = 'Infiltration' AND operation_date >= (SELECT DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR)) AND region = 'Africa' GROUP BY country;
Delete records from the 'climate_adaptation_measures' table where the 'start_date' is after 2025-12-31
CREATE TABLE climate_adaptation_measures (id INT,measure VARCHAR(255),start_date DATE,end_date DATE);
DELETE FROM climate_adaptation_measures WHERE start_date > '2025-12-31';
Identify the top 3 bioprocess engineering patents by patent_date.
CREATE SCHEMA if not exists bioprocess; USE bioprocess; CREATE TABLE if not exists patents (id INT PRIMARY KEY,name VARCHAR(255),patent_date DATE); INSERT INTO patents (id,name,patent_date) VALUES (1,'PatentA','2018-01-10'),(2,'PatentB','2019-05-23'),(3,'PatentC','2017-12-31'),(4,'PatentD','2020-11-15'),(5,'PatentE','2...
SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY patent_date DESC) as row_num FROM patents) as patents_ranked WHERE row_num <= 3;
What is the average manufacturing cost of aircrafts produced in Asia?
CREATE TABLE AircraftManufacturing (id INT,manufacturer VARCHAR(255),country VARCHAR(255),cost FLOAT); INSERT INTO AircraftManufacturing VALUES (1,'Boeing','USA',120000000),(2,'Airbus','Europe',100000000),(3,'COMAC','China',80000000),(4,'Mitsubishi Heavy Industries','Japan',90000000);
SELECT AVG(cost) FROM AircraftManufacturing WHERE country IN ('China', 'Japan');
How many volunteers engaged in community programs in the San Francisco region in Q2 of 2022?
CREATE TABLE Volunteers (VolunteerID INT,VolunteerName TEXT,City TEXT,Region TEXT,HoursSpent DECIMAL); INSERT INTO Volunteers (VolunteerID,VolunteerName,City,Region,HoursSpent) VALUES (1,'Alice Johnson','San Jose','San Francisco',20.00),(2,'Bob Brown','San Francisco','San Francisco',30.00);
SELECT COUNT(*) FROM Volunteers WHERE Region = 'San Francisco' AND QUARTER(VolunteerDate) = 2;
What is the maximum environmental impact score for mining operations in Year 2002?
CREATE TABLE consequence (id INT,mining_operation TEXT,year INT,score FLOAT); INSERT INTO consequence (id,mining_operation,year,score) VALUES (1,'Operation A',2001,98.6); INSERT INTO consequence (id,mining_operation,year,score) VALUES (2,'Operation B',2002,23.8);
SELECT MAX(score) FROM consequence WHERE year = 2002 AND mining_operation LIKE '%Mining%';
Update the accommodation type for student 6 to 'Speech-to-Text Software'
CREATE TABLE accommodations (id INT,student_id INT,accommodation_type VARCHAR(50),cost FLOAT,accommodation_date DATE); INSERT INTO accommodations (id,student_id,accommodation_type,cost,accommodation_date) VALUES (1,2,'Sign Language Interpreter',50.00,'2021-01-01'),(2,3,'Assistive Listening Devices',300.00,'2021-04-01')...
UPDATE accommodations SET accommodation_type = 'Speech-to-Text Software' WHERE student_id = 6;
What is the total cost of rural infrastructure projects that are related to 'Agriculture' in 'South America'?
CREATE TABLE Rural_Infrastructure(project_id INT,project_name VARCHAR(50),country VARCHAR(50),cost FLOAT,sector VARCHAR(50)); INSERT INTO Rural_Infrastructure(project_id,project_name,country,cost,sector) VALUES (1,'Road Construction','Argentina',1000000,'Agriculture'),(2,'Bridge Building','Brazil',1200000,'Transportati...
SELECT SUM(cost) as total_cost FROM Rural_Infrastructure WHERE country = 'South America' AND sector = 'Agriculture';
What is the total methane emission for each research station in the 'emissions' table, ordered by total methane emission in descending order for the year 2017?
CREATE TABLE emissions (station VARCHAR(255),year INT,methane_emission FLOAT); INSERT INTO emissions (station,year,methane_emission) VALUES ('Station A',2017,120.0),('Station B',2017,150.0),('Station C',2017,180.0),('Station D',2017,200.0);
SELECT station, SUM(methane_emission) as total_methane_emission FROM emissions WHERE year = 2017 GROUP BY station ORDER BY total_methane_emission DESC;
Update the aircraft_manufacturing table to set the status of all records with manufacturing_date on or after '2015-01-01' to 'Active'
CREATE TABLE aircraft_manufacturing (id INT,aircraft_name VARCHAR(255),manufacturer VARCHAR(255),manufacturing_date DATE,status VARCHAR(255));
UPDATE aircraft_manufacturing SET status = 'Active' WHERE manufacturing_date >= '2015-01-01';
What is the difference in game duration between consecutive sessions for each player, ordered by player and date?
CREATE TABLE PlayerSessions (PlayerID INT,SessionDate DATE,GameDuration FLOAT); INSERT INTO PlayerSessions (PlayerID,SessionDate,GameDuration) VALUES (1,'2022-05-01',345.6),(1,'2022-05-02',456.7),(2,'2022-05-01',234.5);
SELECT PlayerID, SessionDate, GameDuration, LEAD(GameDuration) OVER (PARTITION BY PlayerID ORDER BY SessionDate) - GameDuration AS GameDurationDifference FROM PlayerSessions ORDER BY PlayerID, SessionDate;
Determine the percentage of days in 'June 2021' with non-zero water usage for 'institutional' purposes in the 'water_usage' table
CREATE TABLE water_usage (id INT,usage FLOAT,purpose VARCHAR(20),date DATE); INSERT INTO water_usage (id,usage,purpose,date) VALUES (1,50,'institutional','2021-06-01'); INSERT INTO water_usage (id,usage,purpose,date) VALUES (2,0,'institutional','2021-06-02');
SELECT ROUND(100.0 * AVG(CASE WHEN usage > 0 THEN 1 ELSE 0 END), 2) as percentage FROM water_usage WHERE purpose = 'institutional' AND date BETWEEN '2021-06-01' AND '2021-06-30' GROUP BY date HAVING COUNT(*) = 30;
What is the total revenue generated by Music Festivals in California?
CREATE TABLE festivals (id INT,state VARCHAR(50),revenue FLOAT); INSERT INTO festivals (id,state,revenue) VALUES (1,'California',200000.0),(2,'Texas',150000.0);
SELECT SUM(revenue) FROM festivals WHERE state = 'California';
What is the average number of cases handled per attorney for attorneys in the 'Litigation' department?
CREATE TABLE attorneys (attorney_id INT,department VARCHAR(20)); CREATE TABLE cases (case_id INT,attorney_id INT); INSERT INTO attorneys (attorney_id,department) VALUES (1,'Litigation'),(2,'Litigation'),(3,'Corporate'); INSERT INTO cases (case_id,attorney_id) VALUES (1,1),(2,1),(3,2),(4,3);
SELECT AVG(total_cases) FROM (SELECT COUNT(*) AS total_cases FROM cases JOIN attorneys ON cases.attorney_id = attorneys.attorney_id WHERE attorneys.department = 'Litigation' GROUP BY cases.attorney_id) AS subquery;
List all mining sites and their respective environmental impact scores.
CREATE TABLE Mining_Sites (id INT,site_name VARCHAR(50),location VARCHAR(50),environmental_impact_score INT); INSERT INTO Mining_Sites (id,site_name,location,environmental_impact_score) VALUES (1,'Site A','USA',60),(2,'Site B','Canada',70),(3,'Site C','Mexico',50);
SELECT site_name, environmental_impact_score FROM Mining_Sites;
What is the average donation amount from donors in Canada?
CREATE TABLE donors (id INT,name TEXT,country TEXT,donation_amount DECIMAL); INSERT INTO donors (id,name,country,donation_amount) VALUES (1,'John Doe','Canada',100.00),(2,'Jane Smith','USA',50.00);
SELECT AVG(donation_amount) FROM donors WHERE country = 'Canada';
What is the maximum number of charging stations in the 'charging_stations' table, grouped by their 'region'?
CREATE TABLE charging_stations (id INT,station_name VARCHAR(255),region VARCHAR(255),num_stalls INT);
SELECT region, MAX(num_stalls) FROM charging_stations GROUP BY region;
Delete the records with a temperature above 30 degrees Celsius and humidity below 40% in field 3 during July 2021.
CREATE TABLE field_sensors (field_id INT,sensor_type VARCHAR(20),value FLOAT,timestamp TIMESTAMP); INSERT INTO field_sensors (field_id,sensor_type,value,timestamp) VALUES (3,'temperature',28.5,'2021-07-01 10:00:00'),(3,'humidity',35.0,'2021-07-01 10:00:00');
DELETE FROM field_sensors WHERE field_id = 3 AND sensor_type IN ('temperature', 'humidity') AND value > 30 AND value < 40 AND MONTH(timestamp) = 7 AND YEAR(timestamp) = 2021;
How many security incidents have been recorded for each type of asset in the 'incident_reports' table?
CREATE TABLE incident_reports (id INT,incident_type VARCHAR(50),asset_type VARCHAR(50)); INSERT INTO incident_reports (id,incident_type,asset_type) VALUES (1,'Malware','Workstation'),(2,'Phishing','Laptop'),(3,'Malware','Server'),(4,'Phishing','Mobile'),(5,'DDoS','Network');
SELECT asset_type, incident_type, COUNT(*) as count FROM incident_reports GROUP BY asset_type, incident_type;
What is the total number of policies issued per agent in the 'Western' region?
CREATE TABLE Agents (AgentID INT,AgentRegion VARCHAR(10)); INSERT INTO Agents (AgentID,AgentRegion) VALUES (1,'Eastern'),(2,'Western'),(3,'Eastern'); CREATE TABLE Policies (PolicyID INT,AgentID INT); INSERT INTO Policies (PolicyID,AgentID) VALUES (1,1),(2,1),(3,2),(4,3),(5,1);
SELECT Agents.AgentRegion, COUNT(Policies.PolicyID) AS TotalPolicies FROM Agents INNER JOIN Policies ON Agents.AgentID = Policies.AgentID WHERE Agents.AgentRegion = 'Western' GROUP BY Agents.AgentID;
What is the average diversity and inclusion training score for each gender in the HR department?
CREATE TABLE GenderScores(EmployeeID INT,Department VARCHAR(255),Gender VARCHAR(255),TrainingType VARCHAR(255),Score INT);
SELECT Department, Gender, AVG(CASE WHEN TrainingType = 'Diversity and Inclusion' THEN Score END) AS AverageScore FROM GenderScores WHERE Department = 'HR' GROUP BY Department, Gender;
Which aircraft models have the highest and lowest flight safety records in the aviation database?
CREATE TABLE aircraft_models (model_id INT,model_name VARCHAR(255),manufacturer VARCHAR(255),total_flights INT,total_incidents INT);
SELECT model_name, total_incidents/total_flights as safety_record FROM aircraft_models ORDER BY safety_record ASC LIMIT 1;SELECT model_name, total_incidents/total_flights as safety_record FROM aircraft_models ORDER BY safety_record DESC LIMIT 1;
What are the names of artists who have mastered traditional arts from different continents?
CREATE TABLE Artists (ArtistID int,ArtistName text,Specialization text,Continent text); INSERT INTO Artists (ArtistID,ArtistName,Specialization,Continent) VALUES (1,'Amina Ahmed','Indian Miniature Painting','Asia'),(2,'Bertina Lopes','Mozambican Modern Art','Africa'),(3,'Fernando de Szyszlo','Peruvian Abstract Art','So...
SELECT ArtistName FROM Artists WHERE Continent IN ('Asia', 'Africa', 'South America') GROUP BY ArtistName HAVING COUNT(DISTINCT Continent) = 3;
What is the total number of relief supplies distributed in Haiti and the Democratic Republic of the Congo, grouped by type?
CREATE TABLE relief_supplies (id INT,supply_type VARCHAR(255),country VARCHAR(255)); INSERT INTO relief_supplies (id,supply_type,country) VALUES (1,'Food','Haiti'),(2,'Water','Haiti'),(3,'Shelter','Haiti'),(4,'Medicine','Haiti'),(5,'Food','Democratic Republic of the Congo'),(6,'Water','Democratic Republic of the Congo'...
SELECT supply_type, COUNT(*) as total FROM relief_supplies WHERE country IN ('Haiti', 'Democratic Republic of the Congo') GROUP BY supply_type;
What is the average depth of all trenches in the 'Trenches' table?
CREATE TABLE Trenches (TrenchID INT PRIMARY KEY,TrenchName TEXT,MaxDepth FLOAT);
SELECT AVG(MaxDepth) FROM Trenches;
Identify vessels that docked in the Port of Oakland in Q1 2022 and their maximum cargo weight.
CREATE TABLE vessels (vessel_id INT,vessel_name TEXT,max_cargo_weight INT); INSERT INTO vessels VALUES (1,'Vessel C',15000),(2,'Vessel D',20000); CREATE TABLE port_visits (visit_id INT,vessel_id INT,port_id INT,visit_date DATE); INSERT INTO port_visits VALUES (1,1,7,'2022-01-15'),(2,2,7,'2022-01-20'); CREATE TABLE port...
SELECT vessels.vessel_name, MAX(vessels.max_cargo_weight) FROM vessels JOIN port_visits ON vessels.vessel_id = port_visits.vessel_id JOIN ports ON port_visits.port_id = ports.port_id WHERE ports.port_name = 'Port of Oakland' AND YEAR(port_visits.visit_date) = 2022 AND QUARTER(port_visits.visit_date) = 1 GROUP BY vessel...
How many volunteers participated in community education programs in 2020?
CREATE TABLE Community_Education_Program (Id INT,Program_Date DATE,Volunteers_Count INT);
SELECT SUM(Volunteers_Count) FROM Community_Education_Program WHERE YEAR(Program_Date) = 2020;
Which 'crops' were planted in 'winter' of '2022' in the 'planting_schedule' table?
CREATE TABLE planting_schedule (id INT,farm_id INT,crop VARCHAR(50),planting_date DATE);
SELECT crop FROM planting_schedule WHERE planting_date BETWEEN '2022-12-01' AND '2023-02-28';
What is the percentage of cases heard in each court type out of total cases?
CREATE TABLE court_cases (case_id INT,court_type VARCHAR(20)); INSERT INTO court_cases VALUES (1,'Community'),(2,'Community'),(3,'Traditional'),(4,'Traditional');
SELECT court_type, COUNT(*) * 100.0 / (SELECT COUNT(*) FROM court_cases) AS percentage FROM court_cases GROUP BY court_type;
Show the average number of hospital beds in rural hospitals with at least 100 beds, grouped by hospital location state.
CREATE TABLE hospitals (hospital_id INT,hospital_name TEXT,beds INT,rural BOOLEAN,state_id INT); INSERT INTO hospitals (hospital_id,hospital_name,beds,rural,state_id) VALUES (1,'Hospital A',100,true,1); CREATE TABLE states (state_id INT,state TEXT); INSERT INTO states (state_id,state) VALUES (1,'Alabama'),(2,'Alaska');
SELECT states.state, AVG(hospitals.beds) avg_beds FROM hospitals JOIN states ON hospitals.state_id = states.state_id WHERE hospitals.rural = true AND hospitals.beds >= 100 GROUP BY states.state;
What is the average fare amount for each route, considering only cash payments?
CREATE TABLE fare (fare_id INT,route_id INT,fare_amount DECIMAL(5,2),payment_type VARCHAR(50)); INSERT INTO fare (fare_id,route_id,fare_amount,payment_type) VALUES (1,1,2.50,'Cash'),(2,1,3.00,'Card'),(3,2,1.50,'Cash');
SELECT route_id, AVG(fare_amount) AS avg_fare_cash FROM fare WHERE payment_type = 'Cash' GROUP BY route_id;
What is the percentage of smokers in Europe by country?
CREATE TABLE Smokers (Country VARCHAR(50),Continent VARCHAR(50),Percentage_Smokers FLOAT); INSERT INTO Smokers (Country,Continent,Percentage_Smokers) VALUES ('Germany','Europe',29.2),('France','Europe',29.8);
SELECT Country, Percentage_Smokers FROM Smokers WHERE Continent = 'Europe';
What is the percentage of women in managerial positions in the Mining department?
CREATE TABLE Employees(id INT,name VARCHAR(50),department VARCHAR(50),position VARCHAR(50),salary FLOAT,full_time BOOLEAN,gender VARCHAR(50));
SELECT ROUND(COUNT(*) * 100.0 / (SELECT COUNT(*) FROM Employees WHERE department = 'Mining' AND full_time = TRUE AND gender = 'Female'), 2) AS Percentage FROM Employees WHERE department = 'Mining' AND full_time = TRUE AND position LIKE '%Manager%';
Find the number of genetic research participants by project.
CREATE TABLE research_participants (id INT,project_id INT,participant_id INT,date DATE);
SELECT project_id, COUNT(DISTINCT participant_id) FROM research_participants GROUP BY project_id;
How many green buildings are there in the city of London that were built before 2010?
CREATE TABLE green_buildings (id INT,name TEXT,city TEXT,build_date DATE); INSERT INTO green_buildings (id,name,city,build_date) VALUES (1,'Green Building 1','London','2008-01-01'); INSERT INTO green_buildings (id,name,city,build_date) VALUES (2,'Green Building 2','London','2011-01-01'); INSERT INTO green_buildings (id...
SELECT COUNT(*) FROM green_buildings WHERE city = 'London' AND build_date <= '2010-12-31';
What are the AI safety concerns raised in the past year, in the AI Safety database?
CREATE TABLE concerns (id INT,description VARCHAR(255),published_date DATE);
SELECT description FROM concerns WHERE YEAR(published_date) = YEAR(CURRENT_DATE());
What is the average water usage per mining operation in Canada, partitioned by the type of mine, for the year 2020?
CREATE TABLE mining_operations (id INT,mine_name TEXT,location TEXT,mine_type TEXT,water_usage FLOAT,year INT); INSERT INTO mining_operations (id,mine_name,location,mine_type,water_usage,year) VALUES (1,'Golden Mine','Canada','Open Pit',500000,2020),(2,'Silver Mine','Canada','Underground',300000,2020),(3,'Bronze Mine',...
SELECT mine_type, AVG(water_usage) as avg_water_usage FROM mining_operations WHERE location = 'Canada' AND year = 2020 GROUP BY mine_type;
What is the total funding received by startups founded by people from underrepresented communities?
CREATE TABLE company (name VARCHAR(255),founder_underrepresented BOOLEAN); INSERT INTO company (name,founder_underrepresented) VALUES ('CompanyA',FALSE),('CompanyB',TRUE),('CompanyC',TRUE),('CompanyD',FALSE); CREATE TABLE funding (company_name VARCHAR(255),amount INT); INSERT INTO funding (company_name,amount) VALUES (...
SELECT SUM(funding.amount) FROM funding INNER JOIN company ON funding.company_name = company.name WHERE company.founder_underrepresented = TRUE;
How many marine life research data entries are there for species that have a population less than or equal to 300?
CREATE TABLE marine_life_research(id INT,species VARCHAR(50),population INT); INSERT INTO marine_life_research(id,species,population) VALUES (1,'Shark',300),(2,'Dolphin',600),(3,'Tuna',550);
SELECT COUNT(*) FROM marine_life_research WHERE population <= 300;
How many of each product category are there in the inventory?
CREATE TABLE Products (product_id INT,category TEXT); INSERT INTO Products (product_id,category) VALUES (1,'Tops'),(2,'Pants'),(3,'Tops'),(4,'Shoes'); CREATE TABLE Inventory (product_id INT,quantity INT); INSERT INTO Inventory (product_id,quantity) VALUES (1,10),(2,20),(3,30),(4,40);
SELECT category, SUM(quantity) FROM Inventory INNER JOIN Products ON Inventory.product_id = Products.product_id GROUP BY category;
Which aquatic species have a biomass greater than any species in the Atlantic Ocean?
CREATE TABLE pacific_fish_stock (id INT,species VARCHAR(255),biomass INT); INSERT INTO pacific_fish_stock (id,species,biomass) VALUES (1,'Whale Shark',7000000),(2,'Blue Whale',12000000),(3,'Great White Shark',2000000);
SELECT species FROM pacific_fish_stock WHERE biomass > ALL (SELECT biomass FROM atlantic_fish_stock);
Add a record for a circular economy initiative in Berlin
CREATE TABLE circular_economy_initiatives (id INT PRIMARY KEY,location VARCHAR(50),initiative VARCHAR(100),start_date DATE,end_date DATE);
INSERT INTO circular_economy_initiatives (id, location, initiative, start_date, end_date) VALUES (1, 'Berlin', 'Waste-to-Energy Project', '2022-01-01', '2025-12-31');
What is the maximum satellite NDVI value recorded in Kenya in the past 3 months?
CREATE TABLE satellite_data (ndvi DECIMAL(3,2),reading_date DATE,location TEXT); INSERT INTO satellite_data (ndvi,reading_date,location) VALUES (0.72,'2021-07-01','Kenya'),(0.75,'2021-07-02','Kenya'),(0.68,'2021-04-01','Kenya');
SELECT MAX(ndvi) FROM satellite_data WHERE location = 'Kenya' AND reading_date > DATE_SUB(CURDATE(), INTERVAL 3 MONTH);
How many users have a membership type starting with the letter 'P'?
CREATE TABLE memberships (id INT,member_type VARCHAR(20)); INSERT INTO memberships (id,member_type) VALUES (1,'Basic'),(2,'Premium'),(3,'Elite'),(4,'Platinum');
SELECT COUNT(*) as num_users FROM memberships WHERE member_type LIKE 'P%';
What is the average CO2 emission of the factories in the 'ethical_fashion' schema, partitioned by material type?
CREATE SCHEMA ethical_fashion; CREATE TABLE factories (factory_id INT,material VARCHAR(255),co2_emission FLOAT); INSERT INTO factories VALUES (1,'cotton',12.5),(2,'cotton',13.0),(3,'polyester',15.5),(4,'polyester',14.8),(5,'wool',10.9),(6,'wool',11.3);
SELECT material, AVG(co2_emission) OVER (PARTITION BY material) FROM ethical_fashion.factories;
What was the total number of volunteers and total volunteer hours for each gender in 2022?
CREATE TABLE Volunteers (VolunteerID int,VolunteerName varchar(50),VolunteerDate date,VolunteerHours decimal(10,2),Gender varchar(10)); INSERT INTO Volunteers (VolunteerID,VolunteerName,VolunteerDate,VolunteerHours,Gender) VALUES (1,'Sophia Lee','2022-02-01',25.00,'Female'),(2,'Daniel Kim','2022-03-15',30.00,'Male'),(3...
SELECT Gender, COUNT(DISTINCT VolunteerID) as TotalVolunteers, SUM(VolunteerHours) as TotalVolunteerHours FROM Volunteers WHERE YEAR(VolunteerDate) = 2022 GROUP BY Gender;
How many climate mitigation projects were completed in Latin America and the Caribbean?
CREATE TABLE climate_projects (id INT,region VARCHAR(50),type VARCHAR(50),status VARCHAR(50)); INSERT INTO climate_projects (id,region,type,status) VALUES (1,'South America','climate mitigation','completed'),(2,'Central America','climate adaptation','in progress'),(3,'Caribbean','climate mitigation','completed');
SELECT COUNT(*) FROM climate_projects WHERE region IN ('South America', 'Central America', 'Caribbean') AND type = 'climate mitigation' AND status = 'completed';
How many sustainable building projects were completed in the state of California in 2021?
CREATE TABLE sustainable_building_projects (project_id INT,project_name VARCHAR(100),state VARCHAR(50),completion_year INT); INSERT INTO sustainable_building_projects (project_id,project_name,state,completion_year) VALUES (1,'GreenTowers','California',2021),(2,'EcoHQ','Texas',2020),(3,'SolarVilla','California',2019);
SELECT COUNT(*) FROM sustainable_building_projects WHERE state = 'California' AND completion_year = 2021;
Create a view of satellites launched by the European Union
CREATE TABLE satellite_deployment (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255),launch_date DATE);
CREATE VIEW eu_satellites AS SELECT * FROM satellite_deployment WHERE country = 'European Union';
What is the average credit score of clients in the Islamic Financial Education program?
CREATE TABLE islamic_financial_education (client_id INT,program_name VARCHAR(30),credit_score INT); INSERT INTO islamic_financial_education (client_id,program_name,credit_score) VALUES (201,'Islamic Financial Education',700),(202,'Financial Wellbeing',650),(203,'Islamic Financial Education',720),(204,'Financial Capabil...
SELECT AVG(credit_score) FROM islamic_financial_education WHERE program_name = 'Islamic Financial Education';
List all disaster response teams that worked in 'Afghanistan' and 'Pakistan' from 'disaster_response' table.
CREATE TABLE disaster_response(id INT,team_name VARCHAR(255),location VARCHAR(255)); INSERT INTO disaster_response(id,team_name,location) VALUES ('DR001','Team A','Afghanistan'),('DR002','Team B','Pakistan'),('DR003','Team C','Nepal');
SELECT DISTINCT team_name FROM disaster_response WHERE location IN ('Afghanistan', 'Pakistan');
What is the average response time for emergency calls in the last month?
CREATE TABLE emergencies (eid INT,committed_date TEXT,response_time INT); INSERT INTO emergencies VALUES (1,'2022-01-05',8); INSERT INTO emergencies VALUES (2,'2022-02-10',10); INSERT INTO emergencies VALUES (3,'2022-03-01',5); INSERT INTO emergencies VALUES (4,'2022-03-15',7);
SELECT AVG(response_time) FROM emergencies WHERE committed_date >= DATEADD(month, -1, GETDATE());
How many green buildings are located in each state?
CREATE TABLE GreenBuildings (id INT,name TEXT,location TEXT); INSERT INTO GreenBuildings (id,name,location) VALUES (1,'EcoTower','NY'),(2,'GreenSpire','CA'),(3,'GreenVista','FL'),(4,'SustainableCenter','NY'),(5,'GreenPlaza','CA');
SELECT SUBSTRING(location, 1, 2) AS State, COUNT(*) FROM GreenBuildings GROUP BY State;
Rank engineers in the 'SouthWest' region by the number of projects they have, in descending order, and show only those with more than 5 projects.
CREATE TABLE Engineers (ID INT,Name VARCHAR(255),Region VARCHAR(255),Projects INT,Cost DECIMAL(10,2)); INSERT INTO Engineers VALUES (1,'John Doe','WestCoast',5,15000.00),(2,'Jane Smith','EastCoast',3,12000.00),(3,'Mike Johnson','SouthWest',7,20000.00),(4,'Sara Connor','SouthWest',6,18000.00);
SELECT ID, Name, Region, Projects, RANK() OVER (PARTITION BY Region ORDER BY Projects DESC) AS Rank FROM Engineers WHERE Region = 'SouthWest' AND Projects > 5 ORDER BY Region, Rank;
Insert new records for two suppliers, one from 'Country D' and another from 'Country E', both providing parts to factories with Industry 4.0 practices.
CREATE TABLE Suppliers (ID INT,Country VARCHAR(20),Industry_4_0 BOOLEAN); INSERT INTO Suppliers (ID,Country,Industry_4_0) VALUES (1,'Country A',TRUE); INSERT INTO Suppliers (ID,Country,Industry_4_0) VALUES (2,'Country B',FALSE);
INSERT INTO Suppliers (ID, Country, Industry_4_0) VALUES (3, 'Country D', TRUE), (4, 'Country E', TRUE);
Find the average labor cost per state from the construction_labor table
CREATE TABLE construction_labor (state VARCHAR(2),labor_cost NUMERIC); INSERT INTO construction_labor (state,labor_cost) VALUES ('WA',45.5),('OR',38.3),('CA',52.1);
SELECT state, AVG(labor_cost) FROM construction_labor GROUP BY state;
How many renewable energy power plants are there in California?
CREATE TABLE power_plants_CA (state VARCHAR(255),source_type VARCHAR(255),count INT); INSERT INTO power_plants_CA (state,source_type,count) VALUES ('California','Wind',20),('California','Solar',30),('California','Hydro',15);
SELECT SUM(count) FROM power_plants_CA WHERE state = 'California';
Display the percentage of shared bikes in each city out of total transportation
CREATE TABLE city_transportation (city VARCHAR(50),shared_bikes INT,public_transportation INT,total_transportation INT); INSERT INTO city_transportation (city,shared_bikes,public_transportation,total_transportation) VALUES ('New York',800,500000,508000),('Los Angeles',600,300000,306000),('Chicago',700,400000,407000);
SELECT city, (shared_bikes / total_transportation) * 100 as percentage_shared_bikes FROM city_transportation;
How many players from 'North America' have played 'Virtual Racers' for more than 2 hours?
CREATE TABLE Player_Details (Player_ID INT,Player_Name VARCHAR(50),Country VARCHAR(50),Playtime INT,Game_Name VARCHAR(50)); INSERT INTO Player_Details (Player_ID,Player_Name,Country,Playtime,Game_Name) VALUES (1,'James Carter','USA',240,'Virtual Racers'),(2,'Sophia Brown','Canada',120,'Virtual Racers'),(3,'Roberto Garc...
SELECT COUNT(Player_ID) FROM Player_Details WHERE Game_Name = 'Virtual Racers' AND Country = 'North America' AND Playtime > 2 * 60;
What is the number of hospitals in each rural county?
CREATE TABLE hospitals (id INT,name TEXT,county TEXT,num_beds INT); INSERT INTO hospitals (id,name,county,num_beds) VALUES (1,'Rural General Hospital','County A',200),(2,'Rural District Hospital','County B',150);
SELECT county, COUNT(*) as hospital_count FROM hospitals GROUP BY county;
What is the average number of crimes committed in each city?
CREATE TABLE City (id INT,name VARCHAR(50),population INT,founded DATE); CREATE TABLE Crime (id INT,city_id INT,type VARCHAR(50),year INT,count INT); INSERT INTO City (id,name,population,founded) VALUES (1,'New York',8500000,'1624-09-17'); INSERT INTO City (id,name,population,founded) VALUES (2,'Los Angeles',4000000,'1...
SELECT City.name, AVG(Crime.count) AS avg_crime_count FROM City INNER JOIN Crime ON City.id = Crime.city_id GROUP BY City.name;
How many total donations were made in Q4 2020?
CREATE TABLE Donations (donation_id INT,donor_id INT,donation_date DATE,amount DECIMAL(10,2)); INSERT INTO Donations (donation_id,donor_id,donation_date,amount) VALUES (1,1,'2020-10-01',50.00),(2,2,'2020-11-01',75.00),(3,3,'2020-12-01',100.00),(4,1,'2020-11-15',25.00),(5,4,'2020-10-15',150.00),(6,5,'2020-12-15',200.00)...
SELECT COUNT(*) FROM Donations WHERE QUARTER(donation_date) = 4 AND YEAR(donation_date) = 2020;
What is the total amount of waste generated by the chemical manufacturing plants in New York in the year 2019?
CREATE TABLE waste_generation (id INT,plant_id INT,generation_date DATE,waste_amount FLOAT); CREATE TABLE manufacturing_plants (id INT,plant_name VARCHAR(100),state VARCHAR(50)); INSERT INTO manufacturing_plants (id,plant_name,state) VALUES (1,'New York Plant 1','New York'),(2,'New York Plant 2','New York'); INSERT INT...
SELECT SUM(waste_amount) FROM waste_generation JOIN manufacturing_plants ON waste_generation.plant_id = manufacturing_plants.id WHERE manufacturing_plants.state = 'New York' AND EXTRACT(YEAR FROM generation_date) = 2019;
What is the total number of healthcare facilities in rural areas, compared to urban areas?
CREATE TABLE healthcare_facilities (id INT,name VARCHAR(50),area VARCHAR(10)); INSERT INTO healthcare_facilities (id,name,area) VALUES (1,'Hospital A','Rural'),(2,'Clinic B','Urban');
SELECT SUM(CASE WHEN area = 'Rural' THEN 1 ELSE 0 END) AS rural_facilities, SUM(CASE WHEN area = 'Urban' THEN 1 ELSE 0 END) AS urban_facilities FROM healthcare_facilities;
What are the safety ratings for all hybrid vehicles?
CREATE TABLE Vehicles (VehicleID int,VehicleType varchar(20),SafetyRating float); INSERT INTO Vehicles (VehicleID,VehicleType,SafetyRating) VALUES (1,'Electric',4.8),(2,'Gasoline',4.5),(3,'Hybrid',4.6),(4,'Hybrid',4.7),(5,'Electric',4.9);
SELECT VehicleType, SafetyRating FROM Vehicles WHERE VehicleType = 'Hybrid';
Display the top 3 countries with the highest landfill capacity in 2021, along with their capacities.
CREATE TABLE landfill (id INT,country VARCHAR(50),capacity INT,year INT); INSERT INTO landfill (id,country,capacity,year) VALUES (1,'China',1200000,2021),(2,'India',800000,2021),(3,'USA',700000,2021);
SELECT country, capacity FROM (SELECT country, capacity, ROW_NUMBER() OVER (ORDER BY capacity DESC) as rank FROM landfill WHERE year = 2021) AS subquery WHERE rank <= 3;
How many satellites have been launched by each country?
CREATE TABLE SatelliteLaunches (LaunchID INT,SatelliteID INT,Country VARCHAR(50),LaunchDate DATETIME); INSERT INTO SatelliteLaunches (LaunchID,SatelliteID,Country,LaunchDate) VALUES (1,1,'USA','2022-01-01'); INSERT INTO SatelliteLaunches (LaunchID,SatelliteID,Country,LaunchDate) VALUES (2,2,'France','2022-02-15');
SELECT Country, COUNT(*) as NumSatellites FROM SatelliteLaunches GROUP BY Country;
How many new artists were signed each month in 2022 by record labels in the USA?
CREATE TABLE RecordLabels (LabelName TEXT,Country TEXT,Month TEXT(2),Year INTEGER,NewArtists INTEGER); INSERT INTO RecordLabels (LabelName,Country,Month,Year,NewArtists) VALUES ('Columbia Records','USA','01',2022,15),('Sony Music','USA','02',2022,12),('Warner Music','USA','03',2022,18),('Atlantic Records','USA','04',20...
SELECT Month, COUNT(NewArtists) as NumOfNewArtists FROM RecordLabels WHERE Country = 'USA' AND Year = 2022 GROUP BY Month;