instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
Calculate the total assets of socially responsible lending institutions in South America with a ROA greater than 5%.
|
CREATE TABLE socially_responsible_lending (id INT,institution_name VARCHAR(255),country VARCHAR(255),assets FLOAT,ROA FLOAT); INSERT INTO socially_responsible_lending (id,institution_name,country,assets,ROA) VALUES (1,'Green Lending Brazil','Brazil',1500000.0,0.06),(2,'Sustainable Finance Argentina','Argentina',2000000.0,0.05),(3,'Eco Lending Chile','Chile',1000000.0,0.07);
|
SELECT SUM(assets) FROM socially_responsible_lending WHERE country LIKE 'South America' AND ROA > 0.05;
|
Determine the maximum number of AI safety research papers published in a single year
|
CREATE TABLE research_papers (id INT,publication_year INT,topic VARCHAR(255)); INSERT INTO research_papers (id,publication_year,topic) VALUES (1,2012,'AI Safety'),(2,2013,'Explainable AI'),(3,2018,'Algorithmic Fairness'),(4,2019,'Creative AI'),(5,2020,'AI Safety'),(6,2021,'AI Safety'),(7,2021,'AI Safety'),(8,2021,'AI Safety');
|
SELECT MAX(publication_year) FROM research_papers WHERE topic = 'AI Safety';
|
What is the total revenue generated from the sale of fair trade certified products?
|
CREATE TABLE Sales (ProductID int,Price decimal,FairTrade boolean);
|
SELECT SUM(Price) FROM Sales WHERE FairTrade = true;
|
How many water treatment plants in the state of New York have been operational for more than 20 years?
|
CREATE TABLE plants (plant_id INT,state VARCHAR(20),operational_date DATE); INSERT INTO plants (plant_id,state,operational_date) VALUES (1,'New York','2001-01-01'),(2,'New York','2011-01-01'),(3,'California','1991-01-01');
|
SELECT COUNT(*) FROM plants WHERE state = 'New York' AND operational_date < DATE_SUB(CURDATE(), INTERVAL 20 YEAR);
|
Delete all records of unions that focus on 'Defense' and have less than 250,000 members.
|
CREATE TABLE unions (id INT,name TEXT,domain TEXT,members INT); INSERT INTO unions (id,name,domain,members) VALUES (1,'International Association of Machinists and Aerospace Workers','Aerospace,Defense,Machinists',350000); INSERT INTO unions (id,name,domain,members) VALUES (2,'National Association of Government Employees','Government,Defense',200000);
|
DELETE FROM unions WHERE domain = 'Defense' AND members < 250000;
|
Insert new records into 'conservation_initiatives' table
|
CREATE TABLE conservation_initiatives (id INT PRIMARY KEY,region VARCHAR(20),initiative TEXT);
|
INSERT INTO conservation_initiatives (id, region, initiative) VALUES (1, 'Central', 'Rainwater Harvesting'), (2, 'Great Lakes', 'Smart Irrigation Systems'), (3, 'Plains', 'Greywater Recycling');
|
How many mental health parity violations were reported in California and Texas in 2020 and 2021?
|
CREATE TABLE MentalHealthParityViolations (Id INT,State VARCHAR(2),Year INT,ViolationCount INT); INSERT INTO MentalHealthParityViolations (Id,State,Year,ViolationCount) VALUES (1,'CA',2020,120),(2,'TX',2020,150),(3,'CA',2021,145),(4,'TX',2021,175),(5,'NY',2020,105),(6,'FL',2021,130);
|
SELECT State, SUM(ViolationCount) as TotalViolations FROM MentalHealthParityViolations WHERE State IN ('CA', 'TX') AND Year BETWEEN 2020 AND 2021 GROUP BY State;
|
What is the average weight of packages shipped to Texas from warehouse 1?
|
CREATE TABLE warehouse (id INT,location VARCHAR(255)); INSERT INTO warehouse (id,location) VALUES (1,'Chicago'),(2,'Houston'); CREATE TABLE packages (id INT,warehouse_id INT,weight FLOAT,destination VARCHAR(255)); INSERT INTO packages (id,warehouse_id,weight,destination) VALUES (1,1,50.3,'Texas'),(2,1,30.1,'California'),(3,2,70.0,'Texas');
|
SELECT AVG(weight) FROM packages WHERE warehouse_id = 1 AND destination = 'Texas';
|
What is the average water consumption per capita in New South Wales?
|
CREATE TABLE population (id INT,state VARCHAR(20),population INT); INSERT INTO population (id,state,population) VALUES (1,'New South Wales',8000000),(2,'New South Wales',8500000),(3,'New South Wales',9000000); CREATE TABLE water_consumption (id INT,state VARCHAR(20),consumption FLOAT); INSERT INTO water_consumption (id,state,consumption) VALUES (1,'New South Wales',300000000),(2,'New South Wales',325000000),(3,'New South Wales',350000000);
|
SELECT AVG(consumption / population) FROM water_consumption, population WHERE water_consumption.state = population.state AND state = 'New South Wales';
|
What is the average number of home runs hit by the top 3 home run hitters in the 2022 MLB season?
|
CREATE TABLE mlb_homeruns (player_id INT,player_name TEXT,team_id INT,league TEXT,homeruns INT); INSERT INTO mlb_homeruns (player_id,player_name,team_id,league,homeruns) VALUES (1,'Aaron Judge',19,'MLB',62),(2,'Paul Goldschmidt',14,'MLB',35);
|
SELECT AVG(homeruns) AS avg_homeruns FROM (SELECT homeruns FROM mlb_homeruns ORDER BY homeruns DESC LIMIT 3) AS top_3_hitters;
|
What are the patient demographics and their respective mental health conditions?
|
CREATE TABLE Patients (PatientID INT,Age INT,Gender VARCHAR(10)); CREATE TABLE MentalHealthConditions (ConditionID INT,PatientID INT,Condition VARCHAR(50));
|
SELECT Patients.Age, Patients.Gender, MentalHealthConditions.Condition FROM Patients INNER JOIN MentalHealthConditions ON Patients.PatientID = MentalHealthConditions.PatientID;
|
What is the maximum mental health score by patient's health equity metric score?
|
CREATE TABLE HealthEquityMetrics (MetricID INT,Metric VARCHAR(50)); CREATE TABLE MentalHealthScores (MH_ID INT,MetricID INT,MentalHealthScore INT); INSERT INTO HealthEquityMetrics (MetricID,Metric) VALUES (1,'Low'),(2,'Medium'),(3,'High'); INSERT INTO MentalHealthScores (MH_ID,MetricID,MentalHealthScore) VALUES (1,1,85),(2,1,90),(3,2,75),(4,2,70),(5,3,80),(6,3,85),(7,1,65),(8,1,70),(9,2,80),(10,2,85);
|
SELECT m.Metric, MAX(mhs.MentalHealthScore) as Max_Score FROM MentalHealthScores mhs JOIN HealthEquityMetrics m ON mhs.MetricID = m.MetricID GROUP BY m.Metric;
|
What is the number of streams per day for the "electronic" genre in the North American region for the year 2020?
|
CREATE TABLE DailyStreams(id INT,genre VARCHAR(10),region VARCHAR(10),streams INT,date DATE);
|
SELECT date, AVG(CAST(streams AS FLOAT)/COUNT(date)) AS streams_per_day FROM DailyStreams WHERE genre = 'electronic' AND region = 'North American' AND year = 2020 GROUP BY date;
|
What is the average depth (in meters) for 'Shark' species?
|
CREATE TABLE marine_species (species_id INT,species_name VARCHAR(50),avg_depth FLOAT); INSERT INTO marine_species (species_id,species_name,avg_depth) VALUES (1,'Shark',500),(2,'Clownfish',10);
|
SELECT AVG(avg_depth) FROM marine_species WHERE species_name = 'Shark';
|
How many disability accommodations were provided per month in 2022?
|
CREATE TABLE DisabilityAccommodations (AccommodationID INT,DisabilityType VARCHAR(50),AccommodationDate DATE); INSERT INTO DisabilityAccommodations VALUES (1,'Mobility Impairment','2022-01-01'),(2,'Visual Impairment','2022-01-05'),(3,'Hearing Impairment','2022-01-10'),(4,'Mobility Impairment','2022-02-15'),(5,'Learning Disability','2022-03-01');
|
SELECT DATE_TRUNC('month', AccommodationDate) as Month, COUNT(*) as NumAccommodations FROM DisabilityAccommodations WHERE YEAR(AccommodationDate) = 2022 GROUP BY Month ORDER BY Month;
|
What is the minimum orbital speed required for a satellite to maintain orbit around Earth?
|
CREATE TABLE orbital_speed (id INT,satellite_name VARCHAR(50),orbital_speed FLOAT); INSERT INTO orbital_speed (id,satellite_name,orbital_speed) VALUES (1,'ISS',7662),(2,'GPS',14000),(3,'Starlink',9000);
|
SELECT MIN(orbital_speed) FROM orbital_speed;
|
What is the average construction cost for projects in the water supply domain?
|
CREATE TABLE Projects (id INT,name VARCHAR(100),domain VARCHAR(50)); INSERT INTO Projects (id,name,domain) VALUES (1,'Dam Construction','Water Supply'),(2,'Road Pavement','Transportation'),(3,'Building Foundation','Construction');
|
SELECT AVG(construction_cost) FROM Projects WHERE domain = 'Water Supply';
|
Provide a cross-tabulation of energy efficiency and carbon pricing by region
|
CREATE TABLE energy_efficiency (region VARCHAR(20),efficiency INT);CREATE TABLE carbon_pricing (region VARCHAR(20),price DECIMAL(5,2));
|
SELECT e.region, e.efficiency, c.price FROM energy_efficiency e JOIN carbon_pricing c ON e.region = c.region;
|
Update the position of the employee with ID 2 in the "employee_records" table
|
CREATE TABLE employee_records (employee_id INT PRIMARY KEY,name TEXT,position TEXT,leaving_date DATE); INSERT INTO employee_records (employee_id,name,position,leaving_date) VALUES (1,'John Doe','CTO','2018-01-01'); INSERT INTO employee_records (employee_id,name,position,leaving_date) VALUES (2,'Jane Smith','COO','2019-05-15'); INSERT INTO employee_records (employee_id,name,position,leaving_date) VALUES (3,'Alice Johnson','Data Analyst','2020-03-20');
|
UPDATE employee_records SET position = 'VP of Operations' WHERE employee_id = 2;
|
What is the average time taken to provide aid to people in need in Brazil and Argentina?
|
CREATE TABLE aid_delivery_times (id INT,country VARCHAR(20),person_id INT,aid_date DATE,delivery_time INT);
|
SELECT country, AVG(delivery_time) as avg_delivery_time FROM aid_delivery_times GROUP BY country;
|
Find the average temperature for all crops in April
|
CREATE TABLE crop_temperature (crop_name VARCHAR(50),measurement_date DATE,temperature DECIMAL(5,2));
|
SELECT AVG(temperature) FROM crop_temperature WHERE EXTRACT(MONTH FROM measurement_date) = 4;
|
What is the average number of daily posts, per content creator, containing the hashtag "#climatechange" in the past year, broken down by month?
|
CREATE TABLE content_creators (creator_id INT,creator_name VARCHAR(255));CREATE TABLE posts (post_id INT,creator_id INT,post_date DATE,post_text TEXT);CREATE TABLE hashtags (hashtag_id INT,hashtag_name VARCHAR(255));CREATE TABLE post_hashtags (post_id INT,hashtag_id INT);
|
SELECT EXTRACT(MONTH FROM p.post_date) AS month, AVG(COUNT(p.post_id)) as avg_posts FROM content_creators cc JOIN posts p ON cc.creator_id = p.creator_id JOIN post_hashtags ph ON p.post_id = ph.post_id JOIN hashtags h ON ph.hashtag_id = h.hashtag_id WHERE h.hashtag_name = '#climatechange' AND p.post_date >= (CURRENT_DATE - INTERVAL '1 year') GROUP BY month;
|
Get the number of renewable energy projects in each state of the United States
|
CREATE TABLE projects (project_id INT,project_name VARCHAR(255),project_type VARCHAR(255),state VARCHAR(255),installed_capacity FLOAT);
|
SELECT state, COUNT(*) as num_projects FROM projects WHERE state IN (SELECT state FROM (SELECT DISTINCT state FROM projects WHERE state = 'United States') as temp) GROUP BY state;
|
What is the minimum number of days served in jail for offenders who were released?
|
CREATE TABLE offenders (id INT,days_in_jail INT,release_date DATE); INSERT INTO offenders (id,days_in_jail,release_date) VALUES (1,30,'2021-03-23'),(2,60,'2021-04-15');
|
SELECT MIN(days_in_jail) FROM offenders WHERE release_date IS NOT NULL;
|
What is the distribution of cultural competency scores for healthcare providers in each region, and how many providers are in each region?
|
CREATE TABLE healthcare_providers_competency (id INT,name VARCHAR(50),region VARCHAR(20),cultural_competency_score INT); INSERT INTO healthcare_providers_competency (id,name,region,cultural_competency_score) VALUES (1,'Dr. Jane Doe','Northeast',85),(2,'Dr. John Smith','Southeast',90),(3,'Dr. Maria Garcia','Southwest',95);
|
SELECT region, AVG(cultural_competency_score) as avg_score, COUNT(*) as provider_count FROM healthcare_providers_competency GROUP BY region;
|
What is the maximum solar capacity (MW) added in Mexico each year?
|
CREATE TABLE solar_capacity (id INT,project TEXT,country TEXT,capacity FLOAT,year INT); INSERT INTO solar_capacity (id,project,country,capacity,year) VALUES (1,'Aguascalientes Solar Park','Mexico',36.5,2018),(2,'Puerto Libertad Solar Park','Mexico',45.7,2019);
|
SELECT year, MAX(capacity) FROM solar_capacity WHERE country = 'Mexico' GROUP BY year;
|
What is the geopolitical risk assessment for country Y?
|
CREATE TABLE geopolitical_risk (country VARCHAR,risk_level VARCHAR,assessment_date DATE);
|
SELECT risk_level FROM geopolitical_risk WHERE country = 'Country Y';
|
What is the total number of products sourced from organic farming, grouped by country of origin, in descending order?
|
CREATE TABLE countries (country_id INT,country_name VARCHAR(50)); CREATE TABLE sourcing (sourcing_id INT,country_id INT,product_id INT,is_organic BOOLEAN);
|
SELECT s.country_id, c.country_name, COUNT(s.product_id) as organic_product_count FROM sourcing s JOIN countries c ON s.country_id = c.country_id WHERE s.is_organic = true GROUP BY s.country_id, c.country_name ORDER BY organic_product_count DESC;
|
What is the total amount of climate finance provided by France and Germany between 2015 and 2020?
|
CREATE TABLE climate_finance (country VARCHAR(255),year INT,amount DECIMAL(10,2)); INSERT INTO climate_finance (country,year,amount) VALUES ('France',2015,100.0),('France',2016,110.0),('France',2017,120.0),('France',2018,130.0),('France',2019,140.0),('France',2020,150.0),('Germany',2015,200.0),('Germany',2016,220.0),('Germany',2017,240.0),('Germany',2018,260.0),('Germany',2019,280.0),('Germany',2020,300.0);
|
SELECT SUM(amount) FROM climate_finance WHERE country IN ('France', 'Germany') AND year BETWEEN 2015 AND 2020;
|
Update the name of the 'Coastal Flood Protection' project to 'Coastal Flood Resilience' in the climate_projects table.
|
CREATE TABLE climate_projects (id INT PRIMARY KEY,title VARCHAR(255),description TEXT,start_date DATE,end_date DATE); INSERT INTO climate_projects (id,title,description,start_date,end_date) VALUES (1,'Coastal Flood Protection','Construction of a coastal flood protection system.','2020-01-01','2021-12-31');
|
UPDATE climate_projects SET title = 'Coastal Flood Resilience' WHERE title = 'Coastal Flood Protection';
|
List all threat intelligence data with a threat level of 'High' for the past 6 months.
|
CREATE TABLE Intelligence (IntelligenceID INT,IntelligenceType VARCHAR(50),IntelligenceData VARCHAR(255),IntelligenceDate DATE,ThreatLevel VARCHAR(50),PRIMARY KEY (IntelligenceID));
|
SELECT Intelligence.IntelligenceType, Intelligence.IntelligenceData, Intelligence.IntelligenceDate, Intelligence.ThreatLevel FROM Intelligence WHERE Intelligence.ThreatLevel = 'High' AND Intelligence.IntelligenceDate >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH);
|
What is the species name, population, and management location for species with a population over 800?
|
CREATE TABLE Species (id INT PRIMARY KEY,name VARCHAR(255),population INT); CREATE TABLE ResourceManagement (id INT PRIMARY KEY,location VARCHAR(255),manager VARCHAR(255));
|
SELECT Species.name, Species.population, ResourceManagement.location FROM Species INNER JOIN ResourceManagement ON 1=1 WHERE Species.population > 800;
|
How many decentralized applications are associated with the 'HIPAA' regulatory framework?
|
CREATE TABLE decentralized_applications (app_id serial,app_name varchar(20),regulatory_framework varchar(20)); INSERT INTO decentralized_applications (app_id,app_name,regulatory_framework) VALUES (1,'AppA','GDPR'),(2,'AppB','HIPAA'),(3,'AppC','GDPR'),(4,'AppD','GDPR');
|
SELECT COUNT(*) FROM decentralized_applications WHERE regulatory_framework = 'HIPAA';
|
What is the average water waste per household in New York City in 2021?
|
CREATE TABLE wastewater_treatment (household_id INT,city VARCHAR(30),year INT,waste_amount FLOAT);
|
SELECT AVG(waste_amount) FROM wastewater_treatment WHERE city='New York City' AND year=2021;
|
What was the total donation amount for the year 2020 in the 'Great Lakes' region?
|
CREATE TABLE Donations (donation_id INT,region VARCHAR(20),amount DECIMAL(10,2),donation_year INT); INSERT INTO Donations (donation_id,region,amount,donation_year) VALUES (1,'Great Lakes',5000.00,2020),(2,'Southeast',3000.00,2020);
|
SELECT SUM(amount) FROM Donations WHERE region = 'Great Lakes' AND donation_year = 2020;
|
What is the total installed capacity of wind energy in Germany?
|
CREATE TABLE energy_sources (country VARCHAR(255),source_type VARCHAR(255),capacity INT); INSERT INTO energy_sources (country,source_type,capacity) VALUES ('Germany','Wind',62874);
|
SELECT SUM(capacity) FROM energy_sources WHERE country = 'Germany' AND source_type = 'Wind';
|
Find the number of unique users who have streamed songs from artists in both 'Rock' and 'Jazz' genres?
|
CREATE TABLE Streams (StreamID INT,UserID INT,ArtistID INT); INSERT INTO Streams (StreamID,UserID,ArtistID) VALUES (1,101,1),(2,101,2),(3,102,3),(4,102,4),(5,103,1),(6,103,3);
|
SELECT COUNT(DISTINCT UserID) AS UniqueUsers FROM (SELECT UserID FROM Streams JOIN Artists ON Streams.ArtistID = Artists.ArtistID WHERE Genre IN ('Rock', 'Jazz') GROUP BY UserID HAVING COUNT(DISTINCT Genre) = 2);
|
What is the combined water consumption by the residential and agricultural sectors in 2018 and 2019?
|
CREATE TABLE sector_18_19_consumption (year INT,sector TEXT,consumption FLOAT); INSERT INTO sector_18_19_consumption (year,sector,consumption) VALUES (2018,'residential',123.5),(2018,'agricultural',234.6),(2019,'residential',345.7),(2019,'agricultural',456.8);
|
SELECT consumption FROM sector_18_19_consumption WHERE sector IN ('residential', 'agricultural') AND year IN (2018, 2019)
|
Find the difference in the number of policies between 'California' and 'Texas'.
|
CREATE TABLE Policies (PolicyNumber INT,PolicyholderID INT,PolicyState VARCHAR(20)); INSERT INTO Policies (PolicyNumber,PolicyholderID,PolicyState) VALUES (1001,3,'California'),(1002,4,'California'),(1003,5,'Texas'),(1004,6,'Texas');
|
SELECT (COUNT(CASE WHEN PolicyState = 'California' THEN 1 END) - COUNT(CASE WHEN PolicyState = 'Texas' THEN 1 END)) AS PolicyDifference FROM Policies;
|
Display the recycling rates for each material type in the landfill for 2019 and 2020, along with the average recycling rate.
|
CREATE TABLE Landfill (Location VARCHAR(50),Material VARCHAR(50),Quantity INT,Year INT); INSERT INTO Landfill (Location,Material,Quantity,Year) VALUES ('LandfillA','Plastic',1000,2019),('LandfillA','Glass',1500,2019),('LandfillA','Plastic',1200,2020),('LandfillA','Glass',1800,2020);
|
SELECT Material, AVG(RecyclingRate) FROM (SELECT Material, Year, Quantity, (Quantity / (Quantity + LandfillCapacity)) * 100 AS RecyclingRate FROM Landfill) AS LandfillData GROUP BY Material;
|
What is the average ticket price for musicals and operas in New York?
|
CREATE TABLE Events (city VARCHAR(20),category VARCHAR(20),price DECIMAL(5,2)); INSERT INTO Events (city,category,price) VALUES ('New York','Musical',120.50),('New York','Musical',150.00),('New York','Opera',200.50),('Chicago','Musical',90.00);
|
SELECT AVG(price) FROM Events WHERE city = 'New York' AND category IN ('Musical', 'Opera');
|
Find the average market price of Holmium for the first quarter of each year from 2020 to 2022.
|
CREATE TABLE HolmiumMarketPrices (quarter VARCHAR(10),year INT,price DECIMAL(5,2)); INSERT INTO HolmiumMarketPrices (quarter,year,price) VALUES ('Q1',2020,110.00),('Q1',2020,112.50),('Q1',2021,120.00),('Q1',2021,122.50),('Q1',2022,130.00),('Q1',2022,132.50);
|
SELECT AVG(price) FROM HolmiumMarketPrices WHERE year IN (2020, 2021, 2022) AND quarter = 'Q1';
|
How many fish farms in Asia have a water pH level between 7.0 and 8.0, and stock more than 5000 individuals?
|
CREATE TABLE fish_farms (id INT,name VARCHAR(255),region VARCHAR(255),water_ph FLOAT,stock_count INT); INSERT INTO fish_farms (id,name,region,water_ph,stock_count) VALUES (1,'Farm D','Asia',7.4,6000),(2,'Farm E','Asia',7.8,4500),(3,'Farm F','Asia',8.1,5200);
|
SELECT COUNT(*) FROM fish_farms WHERE region = 'Asia' AND water_ph >= 7.0 AND water_ph <= 8.0 AND stock_count > 5000;
|
What is the total amount donated to each organization and the number of unique donors who have donated to each organization?
|
CREATE TABLE Organizations (org_id INT,org_name TEXT); CREATE TABLE Donors (donor_id INT,donor_name TEXT,org_id INT,donation_amount DECIMAL(10,2));
|
SELECT O.org_name, SUM(D.donation_amount) as total_donations, COUNT(DISTINCT D.donor_id) as total_donors FROM Organizations O INNER JOIN Donors D ON O.org_id = D.org_id GROUP BY O.org_name;
|
Insert new program with budget
|
CREATE TABLE Programs (Id INT,ProgramName VARCHAR(50),Budget DECIMAL(10,2),StartDate DATE,EndDate DATE);
|
INSERT INTO Programs (Id, ProgramName, Budget, StartDate, EndDate) VALUES (3, 'Arts', 7000.00, '2022-01-01', '2022-12-31');
|
What is the total biomass of salmon farmed in Norway and Chile?
|
CREATE TABLE Farm(id INT,country VARCHAR(20),biomass FLOAT); INSERT INTO Farm(id,country,biomass) VALUES (1,'Norway',350000.0),(2,'Chile',420000.0);
|
SELECT SUM(biomass) FROM Farm WHERE country IN ('Norway', 'Chile') AND species = 'Salmon';
|
Count the number of mobile and broadband subscribers for each network type in each country.
|
CREATE TABLE network_type_broadband (network_type VARCHAR(20)); INSERT INTO network_type_broadband (network_type) VALUES ('Fiber'),('Cable'),('DSL'); CREATE TABLE mobile_subscribers (subscriber_id INT,name VARCHAR(50),country VARCHAR(50),network_type VARCHAR(20)); CREATE TABLE broadband_subscribers (subscriber_id INT,name VARCHAR(50),country VARCHAR(50),network_type VARCHAR(20)); INSERT INTO mobile_subscribers (subscriber_id,name,country,network_type) VALUES (1,'John Doe','USA','5G'); INSERT INTO broadband_subscribers (subscriber_id,name,country,network_type) VALUES (2,'Jane Doe','Canada','Fiber');
|
SELECT mobile_subscribers.country, mobile_subscribers.network_type, COUNT(mobile_subscribers.subscriber_id) + COUNT(broadband_subscribers.subscriber_id) AS total_subscribers FROM mobile_subscribers JOIN broadband_subscribers ON mobile_subscribers.country = broadband_subscribers.country JOIN network_type_broadband ON mobile_subscribers.network_type = network_type_broadband.network_type WHERE mobile_subscribers.network_type = broadband_subscribers.network_type GROUP BY mobile_subscribers.country, mobile_subscribers.network_type;
|
What is the maximum ocean acidity level recorded in the Atlantic Ocean?
|
CREATE TABLE ocean_acidity_2 (region TEXT,acidity NUMERIC); INSERT INTO ocean_acidity_2 (region,acidity) VALUES ('Atlantic Ocean','8.4'); INSERT INTO ocean_acidity_2 (region,acidity) VALUES ('Atlantic Ocean','8.35');
|
SELECT MAX(acidity) FROM ocean_acidity_2 WHERE region = 'Atlantic Ocean';
|
List all Green building projects in the Asian region and their respective costs.
|
CREATE TABLE green_building_projects (project_id INT,project_name VARCHAR(50),region VARCHAR(20),cost DECIMAL(10,2)); INSERT INTO green_building_projects (project_id,project_name,region,cost) VALUES (1,'Green Office','Asia',15000000.00),(2,'Sustainable Apartments','Asia',12000000.00),(3,'Eco-friendly Mall','Europe',18000000.00);
|
SELECT project_name, cost FROM green_building_projects WHERE region = 'Asia';
|
Find the number of impact investments made by each investor in 2020.
|
CREATE TABLE Investments (InvestmentID int,InvestorName varchar(50),InvestmentType varchar(50),Sector varchar(50),InvestmentAmount numeric(18,2),InvestmentDate date); INSERT INTO Investments (InvestmentID,InvestorName,InvestmentType,Sector,InvestmentAmount,InvestmentDate) VALUES (1,'Investor1','Impact Investment','Technology',10000,'2020-01-01'),(2,'Investor2','Impact Investment','Finance',15000,'2019-01-01'),(3,'Investor1','Impact Investment','Renewable Energy',12000,'2020-01-01'),(4,'Investor3','Impact Investment','Healthcare',14000,'2020-01-01');
|
SELECT InvestorName, COUNT(*) FROM Investments WHERE YEAR(InvestmentDate) = 2020 AND InvestmentType = 'Impact Investment' GROUP BY InvestorName;
|
How many unique artifacts were found at each excavation site, excluding sites with no artifacts?
|
CREATE TABLE ExcavationSites (SiteID INT,SiteName VARCHAR(100),ArtifactID INT); INSERT INTO ExcavationSites (SiteID,SiteName,ArtifactID) VALUES (1,'Site A',1),(1,'Site A',2),(2,'Site B',3),(3,'Site C',NULL),(4,'Site D',5),(5,'Site E',6); CREATE TABLE Artifacts (ArtifactID INT,Name VARCHAR(100),CreationDate DATETIME) INSERT INTO Artifacts (ArtifactID,Name,CreationDate) VALUES (1,'Artifact 1','2022-01-01'),(2,'Artifact 2','2022-01-01'),(3,'Artifact 3','2022-01-01'),(4,'Artifact 4','2022-01-01'),(5,'Artifact 5','2022-01-01'),(6,'Artifact 6','2022-01-01');
|
SELECT SiteName, COUNT(DISTINCT ArtifactID) as UniqueArtifactCount FROM ExcavationSites JOIN Artifacts ON ExcavationSites.ArtifactID = Artifacts.ArtifactID WHERE ExcavationSites.ArtifactID IS NOT NULL GROUP BY SiteName;
|
Retrieve the maximum and minimum last maintenance dates for all machines
|
CREATE TABLE machines (id INT PRIMARY KEY,name VARCHAR(255),type VARCHAR(255),status VARCHAR(255),last_maintenance_date DATE); INSERT INTO machines (id,name,type,status,last_maintenance_date) VALUES (1,'Machine A','CNC','Operational','2021-01-01'),(2,'Machine B','Robotic Arm','Under Maintenance','2022-05-15'),(3,'Machine C','CNC','Operational','2021-10-05'),(4,'Machine D','Robotic Arm','Operational','2022-02-03'),(5,'Machine E','Conveyor Belt','Operational','2021-06-12');
|
SELECT MAX(last_maintenance_date) AS max_date, MIN(last_maintenance_date) AS min_date FROM machines;
|
Which countries have launched the most satellites and have more than 5 successful space missions?
|
CREATE TABLE Satellite_Launches (country VARCHAR(50),satellite_count INT,successful_missions INT); INSERT INTO Satellite_Launches (country,satellite_count,successful_missions) VALUES ('USA',100,90),('Russia',80,75),('China',60,55);
|
SELECT country FROM Satellite_Launches WHERE satellite_count > 50 AND successful_missions > 5 GROUP BY country ORDER BY satellite_count DESC;
|
Create a table for diversity and inclusion metrics
|
CREATE TABLE DiversityInclusion (EmployeeID INT PRIMARY KEY,Gender VARCHAR(10),Ethnicity VARCHAR(20),Disability VARCHAR(10),Veteran VARCHAR(10),HireDate DATE);
|
CREATE TABLE DiversityInclusion (EmployeeID INT PRIMARY KEY, Gender VARCHAR(10), Ethnicity VARCHAR(20), Disability VARCHAR(10), Veteran VARCHAR(10), HireDate DATE);
|
Identify astronauts from India who have participated in more than 1 mission.
|
CREATE TABLE Astronauts (AstronautID INT,FirstName VARCHAR(50),LastName VARCHAR(50),Nationality VARCHAR(50),Missions INT); INSERT INTO Astronauts (AstronautID,FirstName,LastName,Nationality,Missions) VALUES (2,'Rakesh','Sharma','India',1);
|
SELECT AstronautID, FirstName, LastName FROM Astronauts WHERE Nationality = 'India' AND Missions > 1;
|
What is the average sale price for each city?
|
CREATE TABLE Dispensaries (id INT,name TEXT,location TEXT,sale_price DECIMAL(5,2)); INSERT INTO Dispensaries (id,name,location,sale_price) VALUES (1,'Cloud Nine','Denver',15.00),(2,'Euphoria','Boulder',12.50),(3,'Heavenly Buds','Colorado Springs',14.00); CREATE TABLE Sales (dispensary_id INT,sale_date DATE); INSERT INTO Sales (dispensary_id,sale_date) VALUES (1,'2022-01-01'),(1,'2022-01-02'),(2,'2022-01-01'),(2,'2022-01-02'),(3,'2022-01-01'),(3,'2022-01-02');
|
SELECT location, AVG(sale_price) AS avg_sale_price FROM Dispensaries d JOIN Sales s ON d.id = s.dispensary_id GROUP BY location;
|
What is the total number of factories in the 'renewable energy' sector?
|
CREATE TABLE factories_ext_2 (id INT,name VARCHAR(50),country VARCHAR(50),sector VARCHAR(50),is_renewable BOOLEAN); INSERT INTO factories_ext_2 (id,name,country,sector,is_renewable) VALUES (4,'Hydro Factory','Brazil','renewable energy',TRUE),(5,'Nuclear Factory','France','non-renewable energy',FALSE);
|
SELECT COUNT(*) FROM factories_ext_2 WHERE sector = 'renewable energy' AND is_renewable = TRUE;
|
What are the top 5 cities with the most female readership in 'the_news' newspaper?
|
CREATE TABLE cities (city VARCHAR(255),gender VARCHAR(255),readers INT); INSERT INTO cities VALUES ('CityA','Female',20000),('CityB','Male',30000);
|
SELECT city, SUM(readers) AS total_readers FROM cities WHERE gender = 'Female' GROUP BY city ORDER BY total_readers DESC LIMIT 5;
|
What is the minimum installed capacity of renewable energy sources in each country?
|
CREATE TABLE renewable_energy (id INT,country VARCHAR(255),source VARCHAR(255),installed_capacity INT); INSERT INTO renewable_energy (id,country,source,installed_capacity) VALUES (1,'Germany','Solar',500),(2,'France','Wind',600),(3,'Spain','Hydro',700),(4,'Italy','Geothermal',800);
|
SELECT country, MIN(installed_capacity) FROM renewable_energy GROUP BY country;
|
What is the total revenue for products that are both cruelty-free and vegan?
|
CREATE TABLE products (product_id INT,is_vegan BOOLEAN,is_cruelty_free BOOLEAN,price DECIMAL(10,2)); INSERT INTO products (product_id,is_vegan,is_cruelty_free,price) VALUES (1,true,true,19.99),(2,false,false,24.99),(3,true,true,14.99); CREATE TABLE purchases (purchase_id INT,product_id INT,purchase_date DATE,quantity INT); INSERT INTO purchases (purchase_id,product_id,purchase_date,quantity) VALUES (1,1,'2022-01-01',2),(2,2,'2022-01-05',1),(3,1,'2022-02-01',1);
|
SELECT SUM(price * quantity) AS total_revenue FROM products INNER JOIN purchases ON products.product_id = purchases.product_id WHERE is_vegan = true AND is_cruelty_free = true;
|
Update the exhibition 'Art of the Indigenous' to extend its duration until the end of 2024.
|
CREATE TABLE Exhibitions (exhibition_id INT,exhibition_name VARCHAR(50),start_date DATE,end_date DATE); INSERT INTO Exhibitions (exhibition_id,exhibition_name,start_date,end_date) VALUES (1,'Art of the Indigenous','2023-01-01','2023-12-31');
|
UPDATE Exhibitions SET end_date = '2024-12-31' WHERE exhibition_name = 'Art of the Indigenous';
|
What is the distribution of digital assets by country in the 'digital_assets_by_country' table?
|
CREATE TABLE digital_assets_by_country (asset_id INT,country TEXT,asset_count INT); INSERT INTO digital_assets_by_country (asset_id,country,asset_count) VALUES (1,'US',100),(2,'US',75),(3,'UK',50),(4,'DE',125),(5,'FR',150),(6,'JP',75),(7,'CN',100);
|
SELECT country, SUM(asset_count) FROM digital_assets_by_country GROUP BY country;
|
Which marine species were found in 'Antarctica' or 'Africa' in 2020?
|
CREATE TABLE Species_2 (id INT,name VARCHAR(255),region VARCHAR(255),year INT); INSERT INTO Species_2 (id,name,region,year) VALUES (1,'Penguin','Antarctica',2020); INSERT INTO Species_2 (id,name,region,year) VALUES (2,'Shark','Africa',2020); INSERT INTO Species_2 (id,name,region,year) VALUES (3,'Whale','Africa',2020);
|
SELECT name FROM Species_2 WHERE region = 'Antarctica' UNION SELECT name FROM Species_2 WHERE region = 'Africa';
|
What is the minimum age of female players?
|
CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10),Country VARCHAR(50)); INSERT INTO Players (PlayerID,Age,Gender,Country) VALUES (1,25,'Male','USA'); INSERT INTO Players (PlayerID,Age,Gender,Country) VALUES (2,30,'Female','Canada');
|
SELECT MIN(Players.Age) FROM Players WHERE Players.Gender = 'Female';
|
What is the number of volunteers who have volunteered in each program in the last 3 months?
|
CREATE TABLE Volunteers (VolunteerID INT,VolunteerName TEXT,ProgramID INT,VolunteerDate DATE); INSERT INTO Volunteers (VolunteerID,VolunteerName,ProgramID,VolunteerDate) VALUES (20,'Amy Wong',1,'2022-06-01'),(21,'Brian Lee',2,'2022-06-15'),(22,'Catherine Choi',3,'2022-07-01'),(23,'Daniel Kim',4,'2022-07-15'),(24,'Emily Chen',1,'2022-07-01');
|
SELECT ProgramID, COUNT(DISTINCT VolunteerID) OVER (PARTITION BY ProgramID ORDER BY VolunteerDate ROWS BETWEEN 3 PRECEDING AND CURRENT ROW) AS VolunteerCountInLast3Months FROM Volunteers;
|
Which news topics received the most engagement in the Southern region?
|
CREATE TABLE engagement (id INT,article_id INT,region VARCHAR(20),views INT,likes INT); INSERT INTO engagement (id,article_id,region,views,likes) VALUES (1,1,'Southern',50,30),(2,2,'Northern',60,40),(3,3,'Western',45,25),(4,1,'Southern',75,55); CREATE TABLE articles (id INT,title VARCHAR(50),category VARCHAR(20)); INSERT INTO articles (id,title,category) VALUES (1,'Oil Prices Rising','politics'),(2,'Government Corruption','politics'),(3,'Baseball Game','sports');
|
SELECT articles.category, SUM(engagement.views + engagement.likes) AS total_engagement FROM articles INNER JOIN engagement ON articles.id = engagement.article_id WHERE engagement.region = 'Southern' GROUP BY articles.category ORDER BY total_engagement DESC;
|
What is the latest AI integration and automation level for suppliers from India in the textile industry?
|
CREATE TABLE suppliers (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255),industry VARCHAR(255)); INSERT INTO suppliers (id,name,country,industry) VALUES (3,'Eco-Threads','India','Textile'); CREATE TABLE industry_4_0 (id INT PRIMARY KEY,supplier_id INT,automation_level DECIMAL(10,2),ai_integration BOOLEAN); INSERT INTO industry_4_0 (id,supplier_id,automation_level,ai_integration) VALUES (3,3,0.88,true);
|
SELECT i.ai_integration, i.automation_level FROM industry_4_0 i INNER JOIN suppliers s ON i.supplier_id = s.id WHERE s.country = 'India' AND s.industry = 'Textile' AND i.id IN (SELECT MAX(id) FROM industry_4_0 GROUP BY supplier_id);
|
What is the total climate finance provided to Small Island Developing States (SIDS) for climate adaptation projects in 2019?
|
CREATE TABLE climate_finance (year INT,region VARCHAR(50),funding_type VARCHAR(50),amount INT);
|
SELECT SUM(amount) FROM climate_finance WHERE year = 2019 AND region = 'Small Island Developing States' AND funding_type = 'climate adaptation';
|
Delete all records from the 'weapons' table where the 'name' is 'Mig-29'
|
CREATE TABLE weapons (id INT PRIMARY KEY,name VARCHAR(255),origin VARCHAR(255)); INSERT INTO weapons (id,name,origin) VALUES (1,'AK-47','Russia'),(2,'RPG-7','Russia'),(3,'Mig-29','Russia');
|
DELETE FROM weapons WHERE name = 'Mig-29';
|
List the names and genders of players who have participated in esports events, and the number of events they have participated in, sorted by the number of events in descending order.
|
CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10));CREATE TABLE EsportsEvents (EventID INT,PlayerID INT,EventType VARCHAR(20));
|
SELECT Players.Name, Players.Gender, COUNT(EsportsEvents.EventID) FROM Players INNER JOIN EsportsEvents ON Players.PlayerID = EsportsEvents.PlayerID GROUP BY Players.Name, Players.Gender ORDER BY COUNT(EsportsEvents.EventID) DESC;
|
What is the total energy efficiency savings for the 'energy_efficiency' schema?
|
CREATE TABLE energy_efficiency.savings (saving_id int,project varchar(50),savings int); INSERT INTO energy_efficiency.savings (saving_id,project,savings) VALUES (1,'Project G',150),(2,'Project H',200),(3,'Project I',180);
|
SELECT SUM(savings) FROM energy_efficiency.savings;
|
Total number of passengers using public transportation in Seoul per day
|
CREATE TABLE seoul_public_transport (transport_id INT,transport_type STRING,passenger_count INT,ride_date DATE);
|
SELECT ride_date, SUM(passenger_count) AS total_passengers FROM seoul_public_transport GROUP BY ride_date;
|
What is the average sustainable material cost per country?
|
CREATE TABLE sustainable_materials (material_id INT,country VARCHAR(255),cost DECIMAL(10,2)); INSERT INTO sustainable_materials (material_id,country,cost) VALUES (1,'Nepal',5.50),(2,'India',4.25),(3,'Bangladesh',6.00);
|
SELECT country, AVG(cost) as avg_cost FROM sustainable_materials GROUP BY country;
|
List the types of military technology used by Russia and India, and the number of each type.
|
CREATE TABLE military_technology (id INT,country TEXT,technology_type TEXT,quantity INT); INSERT INTO military_technology (id,country,technology_type,quantity) VALUES (1,'Russia','Missiles',1000),(2,'India','Missiles',800),(3,'Russia','Drones',1500),(4,'India','Drones',1200);
|
SELECT m.country, m.technology_type, m.quantity FROM military_technology m WHERE m.country IN ('Russia', 'India') GROUP BY m.technology_type;
|
Identify all products that were sold in a sustainable package before being discontinued.
|
CREATE TABLE products (id INT,name TEXT,discontinued DATE,sustainable_package BOOLEAN,sustainable_package_date DATE);
|
SELECT name FROM products WHERE discontinued IS NOT NULL AND sustainable_package = TRUE AND sustainable_package_date < discontinued;
|
What is the number of users who have engaged with virtual tours for hotels in Asia?
|
CREATE TABLE virtual_tours (tour_id INT,hotel_id INT,country TEXT,user_count INT); INSERT INTO virtual_tours (tour_id,hotel_id,country,user_count) VALUES (1,1,'Japan',50),(2,1,'China',30),(3,2,'USA',20); INSERT INTO virtual_tours (tour_id,hotel_id,country,user_count) VALUES (4,3,'India',15);
|
SELECT SUM(user_count) FROM virtual_tours WHERE country LIKE 'Asia%';
|
What is the average price of products supplied by each supplier?
|
CREATE TABLE products (id INT,name VARCHAR(255),price DECIMAL(10,2),supplier_id INT);
|
SELECT supplier_id, AVG(price) FROM products GROUP BY supplier_id;
|
What is the environmental impact score of each chemical, sorted by the score in ascending order?
|
CREATE TABLE Chemicals (ChemicalID INT,ChemicalName TEXT,EnvironmentalImpactScore DECIMAL(5,2)); INSERT INTO Chemicals (ChemicalID,ChemicalName,EnvironmentalImpactScore) VALUES (1,'Chemical A',25.3),(2,'Chemical B',15.6),(3,'Chemical C',35.7),(4,'Chemical D',45.8);
|
SELECT ChemicalName, EnvironmentalImpactScore FROM Chemicals ORDER BY EnvironmentalImpactScore ASC;
|
How many students have participated in open pedagogy projects in each discipline?
|
CREATE TABLE projects (project_id INT,project_name VARCHAR(50),discipline VARCHAR(20),project_type VARCHAR(20),open_pedagogy BOOLEAN,student_id INT); INSERT INTO projects (project_id,project_name,discipline,project_type,open_pedagogy,student_id) VALUES (1,'Project X','History','Group',TRUE,1001),(2,'Project Y','Science','Individual',FALSE,1002),(3,'Project Z','Math','Group',TRUE,1003);
|
SELECT discipline, COUNT(DISTINCT student_id) FROM projects WHERE open_pedagogy = TRUE GROUP BY discipline;
|
What is the status of biosensor technology development records for 'BioSensor-A'?
|
CREATE TABLE biosensor_tech_development (id INT,tech_type TEXT,status TEXT,date_created DATE);
|
SELECT status FROM biosensor_tech_development WHERE tech_type = 'BioSensor-A';
|
What is the number of professional development courses completed by teachers in each department?
|
CREATE TABLE teachers (teacher_id INT,department_id INT,name VARCHAR(20),professional_development_course INT); INSERT INTO teachers (teacher_id,department_id,name,professional_development_course) VALUES (1,1,'James',3),(2,1,'Emily',2),(3,2,'Michael',1),(4,2,'Olivia',4); CREATE TABLE departments (department_id INT,name VARCHAR(20)); INSERT INTO departments (department_id,name) VALUES (1,'English'),(2,'Math');
|
SELECT t.department_id, d.name, COUNT(t.professional_development_course) as courses_completed FROM teachers t JOIN departments d ON t.department_id = d.department_id GROUP BY t.department_id, d.name;
|
What is the total capacity of vessels in the vessels table that were built after 2015?
|
CREATE TABLE vessels (id INT,name VARCHAR(255),country VARCHAR(255),capacity INT,year_built INT); INSERT INTO vessels (id,name,country,capacity,year_built) VALUES (1,'Vessel1','China',10000,2016),(2,'Vessel2','Japan',12000,2018),(3,'Vessel3','South Korea',8000,2013);
|
SELECT SUM(capacity) as total_capacity_after_2015 FROM vessels WHERE year_built > 2015;
|
What is the total amount of climate finance committed by each country in 2020?
|
CREATE TABLE climate_finance (country VARCHAR(50),amount NUMERIC,year INT); INSERT INTO climate_finance (country,amount,year) VALUES ('USA',10000000,2020),('China',12000000,2020),('India',8000000,2020);
|
SELECT country, SUM(amount) as total_finance FROM climate_finance WHERE year = 2020 GROUP BY country;
|
What is the total budget for each department in the year 2021?
|
CREATE TABLE Departments (DepartmentID INT,Name TEXT,Budget DECIMAL);
|
SELECT D.Name as DepartmentName, SUM(D.Budget) as TotalBudget2021 FROM Departments D WHERE YEAR(D.StartDate) = 2021 GROUP BY D.DepartmentID, D.Name;
|
Identify the chemical with the highest safety incident count in the past year.
|
CREATE TABLE Chemicals (Chemical_ID INT,Chemical_Name TEXT,Safety_Incidents_Past_Year INT); INSERT INTO Chemicals (Chemical_ID,Chemical_Name,Safety_Incidents_Past_Year) VALUES (1,'Chemical A',4),(2,'Chemical B',7),(3,'Chemical C',2);
|
SELECT Chemical_Name, MAX(Safety_Incidents_Past_Year) as Highest_Incident_Count FROM Chemicals;
|
Delete records of spacecraft with a mass greater than 5000 kg from the 'Spacecrafts' table.
|
CREATE TABLE Spacecrafts (Spacecraft_ID INT,Name VARCHAR(255),Manufacturer VARCHAR(255),Mass FLOAT); INSERT INTO Spacecrafts (Spacecraft_ID,Name,Manufacturer,Mass) VALUES (1,'Galactic Explorer','Galactic Instruments',4500.2),(2,'Nebula One','AstroTech',2000.5),(3,'Stellar Voyager','Cosmos Inc',6000.0);
|
DELETE FROM Spacecrafts WHERE Mass > 5000;
|
What is the maximum funding amount received by Indigenous founders in the Renewable Energy sector?
|
CREATE TABLE InvestmentRounds (id INT,founder_id INT,funding_amount INT); INSERT INTO InvestmentRounds VALUES (1,3,7000000); CREATE TABLE Founders (id INT,name TEXT,ethnicity TEXT,industry TEXT); INSERT INTO Founders VALUES (3,'Aaliyah','Indigenous','Renewable Energy');
|
SELECT MAX(InvestmentRounds.funding_amount) FROM InvestmentRounds JOIN Founders ON InvestmentRounds.founder_id = Founders.id WHERE Founders.ethnicity = 'Indigenous' AND Founders.industry = 'Renewable Energy';
|
List all the animals in the 'animal_population' table that were relocated due to habitat loss.
|
CREATE TABLE animal_relocation (species VARCHAR(50),relocation_reason VARCHAR(50));
|
SELECT a.species FROM animal_population a JOIN animal_relocation r ON a.species = r.species WHERE r.relocation_reason = 'habitat loss';
|
Delete all policies that expired before 2021-01-01 for policyholders from Florida.
|
CREATE TABLE policies (id INT,policyholder_id INT,policy_type TEXT,issue_date DATE,expiry_date DATE); INSERT INTO policies (id,policyholder_id,policy_type,issue_date,expiry_date) VALUES (1,3,'Life','2021-01-01','2022-01-01'),(2,4,'Health','2021-02-01','2022-02-01'),(3,5,'Auto','2021-03-01','2022-03-01'); CREATE TABLE policyholders (id INT,name TEXT,state TEXT,policy_type TEXT); INSERT INTO policyholders (id,name,state,policy_type) VALUES (3,'Alex Brown','Florida','Life'),(4,'Bob Johnson','California','Health'),(5,'Claire Williams','Texas','Auto');
|
DELETE FROM policies WHERE policies.id IN (SELECT policies.id FROM policies JOIN policyholders ON policies.policyholder_id = policyholders.id WHERE policyholders.state = 'Florida' AND policies.expiry_date < '2021-01-01');
|
How many news articles were published by companies based in Spain?
|
CREATE TABLE media_companies (company_id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255),type VARCHAR(255)); CREATE VIEW spanish_companies AS SELECT company_id,name FROM media_companies WHERE country = 'Spain';
|
SELECT COUNT(*) FROM content WHERE company_id IN (SELECT company_id FROM spanish_companies);
|
What is the maximum number of court appearances required for a single criminal case in Texas?
|
CREATE TABLE court_appearances (id INT,case_id INT,appearance_date DATE,court_location VARCHAR(50)); INSERT INTO court_appearances (id,case_id,appearance_date,court_location) VALUES (1,1001,'2019-01-01','Houston'),(2,1001,'2019-02-01','Houston'),(3,1002,'2019-03-01','Dallas');
|
SELECT MAX(id) FROM court_appearances WHERE case_id = 1001;
|
What is the total number of broadband and mobile subscribers for each technology category?
|
CREATE TABLE subscribers(id INT,technology VARCHAR(20),type VARCHAR(10)); INSERT INTO subscribers(id,technology,type) VALUES (1,'4G','mobile'),(2,'5G','mobile'),(3,'ADSL','broadband'),(4,'FTTH','broadband');
|
SELECT technology, type, COUNT(*) AS total FROM subscribers GROUP BY technology, type;
|
What is the minimum yield of 'rice' in 'region2'?
|
CREATE TABLE farm (id INT,region VARCHAR(20),crop VARCHAR(20),yield INT); INSERT INTO farm (id,region,crop,yield) VALUES (1,'region2','rice',40),(2,'region2','corn',60);
|
SELECT MIN(yield) FROM farm WHERE region = 'region2' AND crop = 'rice';
|
What are the names of the movies and their genres for movies produced in France?
|
CREATE TABLE movie (id INT,title VARCHAR(255),genre VARCHAR(255),country VARCHAR(255)); INSERT INTO movie (id,title,genre,country) VALUES (1,'Movie1','Comedy','Spain'),(2,'Movie2','Drama','France'),(3,'Movie3','Action','Spain');
|
SELECT title, genre FROM movie WHERE country = 'France';
|
How many volunteers joined in the last 3 months?
|
CREATE TABLE volunteers (volunteer_id INT,volunteer_name TEXT,join_date DATE); INSERT INTO volunteers (volunteer_id,volunteer_name,join_date) VALUES (3,'Charlie','2022-04-10'),(4,'Dana White','2022-03-15');
|
SELECT COUNT(volunteer_id) FROM volunteers WHERE join_date BETWEEN (CURRENT_DATE - INTERVAL '3 months') AND CURRENT_DATE;
|
What is the average number of submitted freedom of information requests per month in 'foi_requests' table?
|
CREATE TABLE foi_requests (request_date DATE,request_type VARCHAR(255)); INSERT INTO foi_requests (request_date,request_type) VALUES ('2022-01-01','submitted'),('2022-01-15','submitted'),('2022-02-03','submitted');
|
SELECT AVG(count) FROM (SELECT EXTRACT(MONTH FROM request_date) AS month, COUNT(*) AS count FROM foi_requests WHERE request_type = 'submitted' GROUP BY EXTRACT(MONTH FROM request_date)) AS subquery;
|
What is the average age of patients who received medication from doctors named "Mohammed" or "Fatima"?
|
CREATE TABLE doctors (doctor_id INT,name TEXT,age INT); INSERT INTO doctors (doctor_id,name,age) VALUES (1,'Mohammed',45),(2,'Fatima',50),(3,'James',35); CREATE TABLE patients (patient_id INT,doctor_id INT,age INT); INSERT INTO patients (patient_id,doctor_id,age) VALUES (1,1,25),(2,1,30),(3,2,45),(4,2,50),(5,3,20);
|
SELECT AVG(patients.age) FROM patients JOIN doctors ON patients.doctor_id = doctors.doctor_id WHERE doctors.name IN ('Mohammed', 'Fatima');
|
What is the total waste generation in the first half of 2021?
|
CREATE TABLE waste_generation (waste_type TEXT,amount INTEGER,date DATE); INSERT INTO waste_generation (waste_type,amount,date) VALUES ('plastic',300,'2021-01-01'),('paper',250,'2021-01-01'),('glass',150,'2021-01-01');
|
SELECT SUM(amount) FROM waste_generation WHERE date >= '2021-01-01' AND date <= '2021-06-30';
|
What is the total value of military contracts negotiated by Northrop Grumman with the German government from 2015 to 2021?
|
CREATE TABLE military_contracts (contractor VARCHAR(255),country VARCHAR(255),contract_amount DECIMAL(10,2),negotiation_date DATE); INSERT INTO military_contracts (contractor,country,contract_amount,negotiation_date) VALUES ('Northrop Grumman','Germany',5000000,'2015-02-14'),('Northrop Grumman','Germany',7000000,'2017-11-05'),('Northrop Grumman','Germany',8000000,'2021-04-20');
|
SELECT SUM(contract_amount) FROM military_contracts WHERE contractor = 'Northrop Grumman' AND country = 'Germany' AND YEAR(negotiation_date) BETWEEN 2015 AND 2021;
|
What is the total number of military innovation projects completed in the last 5 years?
|
CREATE TABLE military_innovation (project_year INT,project_status VARCHAR(255));
|
SELECT SUM(project_status) FROM military_innovation WHERE project_year >= YEAR(CURRENT_DATE) - 5 AND project_status = 'completed';
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.