instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
What is the number of events attended by each audience member, ordered by the number of events?
|
CREATE SCHEMA if not exists arts_culture;CREATE TABLE if not exists arts_culture.audiences (audience_id INT PRIMARY KEY,name VARCHAR(255));CREATE TABLE if not exists arts_culture.events (event_id INT PRIMARY KEY,name VARCHAR(255),audience_id INT,FOREIGN KEY (audience_id) REFERENCES arts_culture.audiences(audience_id));INSERT INTO arts_culture.audiences (audience_id,name) VALUES (1,'John Doe'),(2,'Jane Smith'),(3,'Jim Brown');INSERT INTO arts_culture.events (event_id,name,audience_id) VALUES (1,'Art Exhibition',1),(2,'Theater Performance',1),(3,'Music Concert',2);
|
SELECT a.name as audience_name, COUNT(e.event_id) as attended_events FROM arts_culture.audiences a JOIN arts_culture.events e ON a.audience_id = e.audience_id GROUP BY a.name ORDER BY attended_events DESC;
|
What is the maximum age of patients who were diagnosed with Hypertension?
|
CREATE TABLE Rural_Patients (Patient_ID INT,Age INT,Gender VARCHAR(10),Diagnosis VARCHAR(20)); INSERT INTO Rural_Patients (Patient_ID,Age,Gender,Diagnosis) VALUES (1,35,'Male','Hypertension'); INSERT INTO Rural_Patients (Patient_ID,Age,Gender,Diagnosis) VALUES (2,42,'Female','Asthma'); CREATE TABLE Hypertension_Diagnosis (Diagnosis VARCHAR(20),Diagnosis_Date DATE); INSERT INTO Hypertension_Diagnosis (Diagnosis,Diagnosis_Date) VALUES ('Hypertension','2020-01-01');
|
SELECT MAX(Rural_Patients.Age) FROM Rural_Patients INNER JOIN Hypertension_Diagnosis ON Rural_Patients.Diagnosis = Hypertension_Diagnosis.Diagnosis;
|
What is the percentage of students who prefer open pedagogy in each school district?
|
CREATE TABLE student_preference (student_id INT,district_id INT,preference VARCHAR(10)); INSERT INTO student_preference (student_id,district_id,preference) VALUES (1,101,'open'),(2,101,'traditional'),(3,102,'open'),(4,102,'open'),(5,103,'traditional');
|
SELECT district_id, 100.0 * SUM(CASE WHEN preference = 'open' THEN 1 ELSE 0 END) / COUNT(*) AS pct_open FROM student_preference GROUP BY district_id;
|
What is the average length of all artist statements in the database?
|
CREATE TABLE artist_statements (statement_length INTEGER); INSERT INTO artist_statements (statement_length) VALUES (50),(100),(150);
|
SELECT AVG(statement_length) FROM artist_statements;
|
What is the maximum number of cases mediated by a single mediator in a year?
|
CREATE TABLE mediators (id INT,name VARCHAR(255),cases_mediated INT,year INT); INSERT INTO mediators (id,name,cases_mediated,year) VALUES (1,'Alex',22,2020),(2,'Taylor',30,2020),(3,'Jamie',40,2020);
|
SELECT MAX(cases_mediated) FROM mediators WHERE year = 2020;
|
What are the names and locations of all expeditions studying sharks?
|
CREATE TABLE expeditions (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),focus VARCHAR(255)); INSERT INTO expeditions (id,name,location,focus) VALUES (1,'Shark Exploration','Atlantic Ocean','Sharks');
|
SELECT expeditions.name, expeditions.location FROM expeditions WHERE expeditions.focus = 'Sharks';
|
List the destinations and total shipment weights for shipments originating from 'SEA' in January 2022.
|
CREATE TABLE warehouse (id VARCHAR(5),name VARCHAR(10),location VARCHAR(15)); INSERT INTO warehouse (id,name,location) VALUES ('W01','BOS','Boston'),('W02','NYC','New York'),('W03','SEA','Seattle'); CREATE TABLE shipment (id INT,warehouse_id VARCHAR(5),destination VARCHAR(10),weight INT,shipped_date DATE); INSERT INTO shipment (id,warehouse_id,destination,weight,shipped_date) VALUES (1,'SEA','NYC',100,'2022-01-05'),(2,'SEA','LAX',200,'2022-01-10'),(3,'SEA','CHI',150,'2022-01-15');
|
SELECT s.destination, SUM(s.weight) FROM shipment s JOIN warehouse w ON s.warehouse_id = w.id WHERE w.name = 'SEA' AND s.shipped_date >= '2022-01-01' AND s.shipped_date < '2022-02-01' GROUP BY s.destination;
|
What is the maximum number of funding rounds for startups in the renewable energy sector?
|
CREATE TABLE company (id INT,name TEXT,industry TEXT); INSERT INTO company (id,name,industry) VALUES (1,'RenewableEnergy','Renewable Energy'); INSERT INTO company (id,name,industry) VALUES (2,'TechBoost','Technology'); CREATE TABLE funding_round (company_id INT,round_size INT); INSERT INTO funding_round (company_id,round_size) VALUES (1,5000000); INSERT INTO funding_round (company_id,round_size) VALUES (2,7000000); INSERT INTO funding_round (company_id,round_size) VALUES (1,6000000); INSERT INTO funding_round (company_id,round_size) VALUES (1,7000000);
|
SELECT COUNT(*) FROM funding_round INNER JOIN company ON funding_round.company_id = company.id WHERE company.industry = 'Renewable Energy' GROUP BY company_id ORDER BY COUNT(*) DESC LIMIT 1;
|
What is the daily revenue by platform for the last 7 days?
|
CREATE TABLE daily_ad_data (platform VARCHAR(20),date DATE,revenue NUMERIC(10,2));
|
SELECT platform, date, SUM(revenue) FROM daily_ad_data WHERE date >= (CURRENT_DATE - INTERVAL '7 days') GROUP BY platform, date ORDER BY date;
|
What is the minimum carbon price in the 'California' market in USD/tonne, for the years 2018 to 2022?
|
CREATE TABLE CarbonPrice (year INT,price FLOAT,market VARCHAR(50));
|
SELECT MIN(price) FROM CarbonPrice WHERE market = 'California' AND year BETWEEN 2018 AND 2022;
|
List all claims and their associated policy type, along with the total claim amount, for policyholders over 65 years old.
|
CREATE TABLE Claim (ClaimId INT,PolicyId INT,ClaimAmount DECIMAL(10,2)); CREATE TABLE Policy (PolicyId INT,PolicyType VARCHAR(50),IssueDate DATE,PolicyholderAge INT);
|
SELECT Policy.PolicyType, Claim.ClaimId, Claim.ClaimAmount, SUM(Claim.ClaimAmount) OVER (PARTITION BY Policy.PolicyType) as TotalClaimAmount FROM Policy INNER JOIN Claim ON Policy.PolicyId = Claim.PolicyId WHERE Policy.PolicyholderAge > 65;
|
What are the top 3 countries with the most reported vulnerabilities in the last month?
|
CREATE TABLE vulnerabilities (id INT,country VARCHAR(255),report_date DATE); INSERT INTO vulnerabilities (id,country,report_date) VALUES (1,'USA','2022-01-01'); INSERT INTO vulnerabilities (id,country,report_date) VALUES (2,'Canada','2022-01-05'); INSERT INTO vulnerabilities (id,country,report_date) VALUES (3,'Mexico','2022-01-09');
|
SELECT country, COUNT(*) as total_vulnerabilities FROM vulnerabilities WHERE report_date >= DATEADD(month, -1, GETDATE()) GROUP BY country ORDER BY total_vulnerabilities DESC LIMIT 3;
|
Which autonomous driving research projects received funding from the US government in 2021 and 2022?
|
CREATE TABLE Research_Project (id INT,name VARCHAR(50),type VARCHAR(20),country VARCHAR(10),start_year INT,end_year INT); INSERT INTO Research_Project (id,name,type,country,start_year,end_year) VALUES (1,'Project A','Autonomous Driving','USA',2021,2023),(2,'Project B','Electric Vehicles','China',2020,2022),(3,'Project C','Autonomous Driving','Germany',2022,2025);
|
SELECT name FROM Research_Project WHERE type = 'Autonomous Driving' AND country = 'USA' AND start_year BETWEEN 2021 AND 2022;
|
What is the total number of streams for each genre, ordered by the total number of streams?
|
CREATE TABLE songs (id INT,title VARCHAR(255),artist_name VARCHAR(255),genre VARCHAR(255),streams INT); INSERT INTO songs (id,title,artist_name,genre,streams) VALUES (1,'Shake it Off','Taylor Swift','Pop',10000000),(2,'Dynamite','BTS','Pop',15000000),(3,'Rolling in the Deep','Adele','Soul',12000000),(4,'Love Story','Taylor Swift','Country',8000000),(5,'Permission to Dance','BTS','Pop',13000000),(6,'Hello','Adele','Soul',9000000),(7,'Bad Guy','Billie Eilish','Pop',11000000),(8,'Old Town Road','Lil Nas X','Country',14000000);
|
SELECT genre, SUM(streams) as total_streams FROM songs GROUP BY genre ORDER BY total_streams DESC;
|
What is the total biomass of fish in the Arctic ocean by species?
|
CREATE TABLE fish_data (id INT,species TEXT,ocean TEXT,biomass FLOAT); INSERT INTO fish_data (id,species,ocean,biomass) VALUES (1,'Species A','Arctic',1200),(2,'Species B','Arctic',1500),(3,'Species C','Arctic',1800);
|
SELECT species, SUM(biomass) FROM fish_data WHERE ocean = 'Arctic' GROUP BY species;
|
What is the average wind speed in 'Cape Town' for March?
|
CREATE TABLE weather (city VARCHAR(255),wind_speed FLOAT,date DATE); INSERT INTO weather (city,wind_speed,date) VALUES ('Cape Town',15,'2022-03-01'),('Cape Town',18,'2022-03-02'),('Cape Town',12,'2022-03-03');
|
SELECT AVG(wind_speed) FROM weather WHERE city = 'Cape Town' AND date BETWEEN '2022-03-01' AND '2022-03-31';
|
What is the total number of government departments in the country of India?
|
CREATE TABLE GovernmentDepartments (DepartmentID int,DepartmentName varchar(255),Country varchar(255)); INSERT INTO GovernmentDepartments (DepartmentID,DepartmentName,Country) VALUES (1,'Indian Department of Defense','India'),(2,'Indian Department of Health','India');
|
SELECT COUNT(*) FROM GovernmentDepartments WHERE Country = 'India';
|
Select the average depth of all marine species habitats.
|
CREATE TABLE marine_species (id INT,species_name VARCHAR(50),habitat_depth FLOAT); INSERT INTO marine_species (id,species_name,habitat_depth) VALUES (1,'Orca',200.0),(2,'Blue Whale',500.0);
|
SELECT AVG(habitat_depth) FROM marine_species;
|
What is the most common gender of authors in the 'authors' table?
|
CREATE TABLE authors (id INT,name VARCHAR(50),gender VARCHAR(10)); INSERT INTO authors (id,name,gender) VALUES (1,'Alice','Female'),(2,'Bob','Male');
|
SELECT gender, COUNT(*) FROM authors GROUP BY gender ORDER BY COUNT(*) DESC LIMIT 1;
|
Update the last login date of the user with Id = 10 to Jan 7, 2022 in the "Members" table
|
CREATE TABLE Members (Id INT PRIMARY KEY,FirstName VARCHAR(50),LastName VARCHAR(50),JoinDate DATETIME,LastLogin DATETIME);
|
UPDATE Members SET LastLogin = '2022-01-07' WHERE Id = 10;
|
What is the total number of green incentive programs in each city?
|
CREATE TABLE GreenIncentive (id INT,city VARCHAR(255),program VARCHAR(255),start_date DATE,end_date DATE); INSERT INTO GreenIncentive (id,city,program,start_date,end_date) VALUES (1,'Los Angeles','Solar Panel Rebate','2010-01-01','2015-12-31'),(2,'San Francisco','Green Roof Subsidy','2012-01-01','2017-12-31');
|
SELECT city, COUNT(*) as 'Total Programs' FROM GreenIncentive GROUP BY city;
|
Delete all satellites that are no longer in orbit.
|
CREATE TABLE satellites (id INT,name VARCHAR(50),launch_date DATE,return_date DATE,orbit_type VARCHAR(50));
|
DELETE FROM satellites WHERE return_date IS NOT NULL;
|
list the names of employees who have never published an article
|
CREATE TABLE Employees (id INT,name VARCHAR(50)); CREATE TABLE Articles (id INT,author_id INT,published_date DATE); INSERT INTO Employees (id,name) VALUES (1,'John Doe'); INSERT INTO Employees (id,name) VALUES (2,'Jane Smith'); INSERT INTO Articles (id,author_id,published_date) VALUES (1,1,'2022-01-01'); INSERT INTO Articles (id,author_id,published_date) VALUES (2,2,'2022-01-02');
|
SELECT e.id, e.name FROM Employees e LEFT JOIN Articles a ON e.id = a.author_id WHERE a.id IS NULL;
|
What were the sales figures for the top 3 drugs by sales in Q1 2020?
|
CREATE TABLE sales (drug_name TEXT,qty_sold INTEGER,sale_date DATE); INSERT INTO sales (drug_name,qty_sold,sale_date) VALUES ('DrugA',500,'2020-01-01'),('DrugB',750,'2020-01-02'),('DrugC',600,'2020-01-03');
|
SELECT drug_name, SUM(qty_sold) as qty_sold FROM sales WHERE sale_date BETWEEN '2020-01-01' AND '2020-03-31' GROUP BY drug_name ORDER BY SUM(qty_sold) DESC LIMIT 3;
|
List all suppliers from Canada with their respective total order quantities.
|
CREATE TABLE Suppliers(supplier_id INT,supplier_name VARCHAR(50),country VARCHAR(50)); CREATE TABLE Orders(order_id INT,supplier_id INT,order_quantity INT); INSERT INTO Suppliers VALUES(1,'ABC Corp','Canada'),(2,'DEF Inc','USA'); INSERT INTO Orders VALUES(1,1,500),(2,1,300),(3,2,700);
|
SELECT Suppliers.supplier_name, SUM(Orders.order_quantity) FROM Suppliers INNER JOIN Orders ON Suppliers.supplier_id = Orders.supplier_id WHERE Suppliers.country = 'Canada' GROUP BY Suppliers.supplier_name;
|
Which donors have not donated to any project in the education sector, in ascending order by donor_id?
|
CREATE TABLE donors (donor_id INT,name TEXT);CREATE TABLE projects (project_id INT,name TEXT,sector TEXT);CREATE TABLE donations (donation_id INT,donor_id INT,project_id INT,amount FLOAT);INSERT INTO donors VALUES (1,'Eva Green'),(2,'Frank Red'),(3,'Grace Blue'),(4,'Harry Yellow');INSERT INTO projects VALUES (1,'Library','education'),(2,'Science Lab','education'),(3,'Art Studio','arts'),(4,'Music Room','arts');INSERT INTO donations VALUES (1,1,3,1000.00),(2,1,4,2000.00),(3,2,1,3000.00),(4,2,2,4000.00),(5,3,3,5000.00),(6,3,4,6000.00),(7,4,1,7000.00),(8,4,2,8000.00);
|
SELECT donors.donor_id, donors.name FROM donors LEFT JOIN donations ON donors.donor_id = donations.donor_id LEFT JOIN projects ON donations.project_id = projects.project_id WHERE projects.sector IS NULL OR projects.sector != 'education' GROUP BY donors.donor_id ORDER BY donors.donor_id ASC;
|
List all unique fertilizer types and their corresponding nutrient ratios (nitrogen, phosphorus, potassium) in ascending order of nitrogen content
|
CREATE TABLE fertilizer (fertilizer_type VARCHAR(255),nitrogen DECIMAL(5,2),phosphorus DECIMAL(5,2),potassium DECIMAL(5,2)); INSERT INTO fertilizer (fertilizer_type,nitrogen,phosphorus,potassium) VALUES ('urea',46.0,0.0,0.0),('ammonium nitrate',34.0,0.0,0.0),('monoammonium phosphate',11.0,23.0,0.0),('triple superphosphate',0.0,46.0,0.0);
|
SELECT DISTINCT fertilizer_type, nitrogen, phosphorus, potassium FROM fertilizer ORDER BY nitrogen ASC;
|
What is the total amount of research grants awarded to female faculty members in the School of Engineering in 2020?
|
CREATE TABLE research_grants (id INT,year INT,faculty_name VARCHAR(50),faculty_department VARCHAR(50),faculty_gender VARCHAR(10),grant_amount INT); INSERT INTO research_grants (id,year,faculty_name,faculty_department,faculty_gender,grant_amount) VALUES (1,2019,'Jose Hernandez','School of Computer Science','Male',10000),(2,2020,'Fatima Lopez','School of Computer Science','Female',15000),(3,2018,'Hong Kim','School of Engineering','Male',20000);
|
SELECT SUM(grant_amount) FROM research_grants WHERE faculty_department LIKE '%Engineering%' AND year = 2020 AND faculty_gender = 'Female';
|
What is the total cargo weight handled by each port, including their corresponding cargo type?
|
CREATE TABLE ports (port_id INT,port_name VARCHAR(100)); CREATE TABLE cargo (cargo_id INT,cargo_type VARCHAR(50),port_id INT); INSERT INTO ports VALUES (1,'Port of Los Angeles'); INSERT INTO ports VALUES (2,'Port of Long Beach'); INSERT INTO cargo VALUES (1,'Container',1); INSERT INTO cargo VALUES (2,'Bulk',2);
|
SELECT ports.port_name, cargo.cargo_type, SUM(cargo.weight) as total_weight FROM cargo INNER JOIN ports ON cargo.port_id = ports.port_id GROUP BY ports.port_name, cargo.cargo_type;
|
How many unique artists are in the songs table?
|
CREATE TABLE songs (id INT,title VARCHAR(255),artist VARCHAR(255)); INSERT INTO songs (id,title,artist) VALUES (1,'Song 1','Artist A'),(2,'Song 2','Artist B');
|
SELECT COUNT(DISTINCT artist) FROM songs;
|
Which country has the highest average mascara price?
|
CREATE TABLE products (product_id INT,product_name VARCHAR(255),category VARCHAR(255),price DECIMAL(10,2),country VARCHAR(255)); INSERT INTO products (product_id,product_name,category,price,country) VALUES (1,'Volumizing Mascara','Makeup',12.5,'US'),(2,'Lengthening Mascara','Makeup',14.99,'France'),(3,'Waterproof Mascara','Makeup',9.99,'Canada');
|
SELECT country, AVG(price) as avg_price FROM products WHERE category = 'Makeup' AND product_name LIKE '%Mascara%' GROUP BY country ORDER BY avg_price DESC LIMIT 1;
|
List the top 3 agricultural innovation metrics by their average scores in 2019, along with the number of evaluations they received.
|
CREATE TABLE agri_innovation (year INT,metric VARCHAR(255),score FLOAT,evaluations INT); INSERT INTO agri_innovation (year,metric,score,evaluations) VALUES (2019,'Precision Agriculture',8.2,50),(2019,'Drip Irrigation',8.5,75),(2019,'Vertical Farming',7.8,60),(2019,'Automated Harvesting',8.0,45);
|
SELECT metric, AVG(score) as avg_score, COUNT(evaluations) as num_evals FROM agri_innovation WHERE year = 2019 GROUP BY metric ORDER BY avg_score DESC, num_evals DESC LIMIT 3;
|
What is the maximum price of eco-friendly materials in the materials table?
|
CREATE TABLE materials (material_id INT,material_name TEXT,is_eco_friendly BOOLEAN,price DECIMAL); INSERT INTO materials VALUES (1,'organic cotton',TRUE,2.5); INSERT INTO materials VALUES (2,'recycled polyester',TRUE,3.25);
|
SELECT MAX(price) FROM materials WHERE is_eco_friendly = TRUE;
|
What are the top 5 countries with the highest number of defense contracts awarded?
|
CREATE TABLE defense_contracts_by_country (id INT,contract_id VARCHAR(50),contract_amount DECIMAL(10,2),country VARCHAR(50));
|
SELECT country, COUNT(DISTINCT contract_id) AS num_contracts FROM defense_contracts_by_country GROUP BY country ORDER BY num_contracts DESC LIMIT 5;
|
What is the total biomass of fish in freshwater fish farms in the Southern Hemisphere?
|
CREATE TABLE fish_farms_fw (id INT,name TEXT,type TEXT,location TEXT,biomass FLOAT); INSERT INTO fish_farms_fw (id,name,type,location,biomass) VALUES (1,'Farm Q','Fish','Brazil',30000.0),(2,'Farm R','Fish','Argentina',20000.0);
|
SELECT SUM(biomass) FROM fish_farms_fw WHERE type = 'Fish' AND location IN (SELECT location FROM fish_farms_fw WHERE biomass IS NOT NULL GROUP BY location HAVING EXTRACT(HOUR FROM AVG(location)) > 12);
|
What is the average number of heritage sites per country in the Americas?
|
CREATE TABLE CountriesAmericas (id INT,name TEXT,region TEXT); INSERT INTO CountriesAmericas (id,name,region) VALUES (1,'United States','Americas'),(2,'Canada','Americas'); CREATE TABLE HeritageSitesAmericas (id INT,country_id INT,name TEXT); INSERT INTO HeritageSitesAmericas (id,country_id,name) VALUES (1,1,'Statue of Liberty'),(2,1,'Grand Canyon'),(3,2,'Niagara Falls'),(4,2,'CN Tower');
|
SELECT AVG(site_count) FROM (SELECT COUNT(HeritageSitesAmericas.id) AS site_count FROM HeritageSitesAmericas GROUP BY HeritageSitesAmericas.country_id) AS SiteCountPerCountry
|
What's the gender ratio of players who play VR games in Australia?
|
CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10),Location VARCHAR(20)); INSERT INTO Players (PlayerID,Age,Gender,Location) VALUES (1,25,'Male','Australia'); INSERT INTO Players (PlayerID,Age,Gender,Location) VALUES (2,30,'Female','Australia'); CREATE TABLE Games (GameID INT,GameName VARCHAR(20),VR BOOLEAN); INSERT INTO Games (GameID,GameName,VR) VALUES (1,'Ocean Explorer',true);
|
SELECT (COUNT(CASE WHEN Gender = 'Male' THEN 1 END) * 1.0 / COUNT(*)) AS Male_ratio, (COUNT(CASE WHEN Gender = 'Female' THEN 1 END) * 1.0 / COUNT(*)) AS Female_ratio FROM Players INNER JOIN Games ON Players.Location = Games.GameName WHERE Games.VR = true AND Players.Location = 'Australia';
|
What is the average price of upcycled products sold by vendors in Oregon?
|
CREATE TABLE vendors (vendor_id INT,vendor_name VARCHAR(50),state VARCHAR(50)); INSERT INTO vendors VALUES (1,'VendorA','Oregon'); INSERT INTO vendors VALUES (2,'VendorB','Texas'); CREATE TABLE products (product_id INT,product_name VARCHAR(50),vendor_id INT,price DECIMAL(5,2),upcycled BOOLEAN); INSERT INTO products VALUES (1,'Product1',1,150,true); INSERT INTO products VALUES (2,'Product2',1,75,true); INSERT INTO products VALUES (3,'Product3',2,100,false); INSERT INTO products VALUES (4,'Product4',1,200,true); CREATE TABLE sales (sale_id INT,product_id INT,vendor_id INT,sale_amount DECIMAL(5,2)); INSERT INTO sales VALUES (1,1,1,50); INSERT INTO sales VALUES (2,2,1,75); INSERT INTO sales VALUES (3,3,2,30); INSERT INTO sales VALUES (4,4,1,60);
|
SELECT AVG(products.price) FROM products JOIN vendors ON products.vendor_id = vendors.vendor_id WHERE products.upcycled = true AND vendors.state = 'Oregon';
|
What is the minimum monthly data usage for mobile subscribers?
|
CREATE TABLE mobile_usage (id INT,name VARCHAR(50),data_usage FLOAT); INSERT INTO mobile_usage (id,name,data_usage) VALUES (1,'Jane Doe',10.0);
|
SELECT MIN(data_usage) FROM mobile_usage;
|
Identify the top 3 regions with the lowest average mobile speed, ordered from the lowest to the highest.
|
CREATE TABLE mobile_speeds (region VARCHAR(255),speed FLOAT); INSERT INTO mobile_speeds (region,speed) VALUES ('North',50),('North',51),('South',45),('East',55),('East',60),('West',48);
|
SELECT region, AVG(speed) as avg_speed, ROW_NUMBER() OVER (ORDER BY AVG(speed) ASC) as rank FROM mobile_speeds GROUP BY region HAVING rank <= 3;
|
Identify the top 3 countries with the highest CO2 emissions in the past month?
|
CREATE TABLE CO2Emissions (Country VARCHAR(50),CO2 INT,CO2Date DATETIME);
|
SELECT Country, SUM(CO2) OVER (PARTITION BY Country ORDER BY CO2Date ROWS BETWEEN 29 PRECEDING AND CURRENT ROW) AS TotalCO2, RANK() OVER (ORDER BY SUM(CO2) DESC) AS Rank FROM CO2Emissions WHERE CO2Date >= DATEADD(month, -1, CURRENT_TIMESTAMP) GROUP BY Country, CO2Date HAVING Rank <= 3
|
What is the average number of military personnel by country, ordered from highest to lowest?
|
CREATE TABLE MilitaryPersonnel (Country VARCHAR(50),MilitaryPersonnel INT); INSERT INTO MilitaryPersonnel (Country,MilitaryPersonnel) VALUES ('USA',1400000),('China',2000000),('Russia',1000000);
|
SELECT Country, AVG(MilitaryPersonnel) AS AvgMilitaryPersonnel FROM MilitaryPersonnel GROUP BY Country ORDER BY AvgMilitaryPersonnel DESC;
|
What is the maximum ocean acidity level in the Southern Ocean?
|
CREATE TABLE ocean_acidity (region varchar(255),level decimal(10,2)); INSERT INTO ocean_acidity (region,level) VALUES ('Southern Ocean',8.30),('Arctic',8.20),('Indian',8.15);
|
SELECT MAX(level) FROM ocean_acidity WHERE region = 'Southern Ocean';
|
List all marine species that are found in both 'coral_reefs' and 'ocean_species'.
|
CREATE TABLE coral_reefs (id INT,species VARCHAR(255));
|
SELECT coral_reefs.species FROM coral_reefs INNER JOIN ocean_species ON coral_reefs.species = ocean_species.species;
|
Calculate the total calories provided by vegetarian menu options in European restaurants.
|
CREATE TABLE MenuItems (menu_item_id INTEGER,menu_item_name TEXT,menu_type TEXT,calories INTEGER); INSERT INTO MenuItems (menu_item_id,menu_item_name,menu_type,calories) VALUES (1,'Vegetarian Lasagna','Entree',650);
|
SELECT SUM(calories) FROM MenuItems WHERE menu_type = 'Entree' AND menu_item_name LIKE '%Vegetarian%' AND country = 'Europe';
|
What is the name of the AI algorithm with the highest bias score in the 'algorithmic_bias' table?
|
CREATE TABLE algorithmic_bias (algorithm_id INT,name TEXT,bias_score FLOAT); INSERT INTO algorithmic_bias (algorithm_id,name,bias_score) VALUES (1,'AlgorithmI',0.15),(2,'AlgorithmJ',0.22),(3,'AlgorithmK',0.18);
|
SELECT name FROM algorithmic_bias ORDER BY bias_score DESC LIMIT 1;
|
What is the maximum water consumption per household in the state of California?
|
CREATE TABLE household_water_consumption (id INT,state VARCHAR(20),water_consumption FLOAT); INSERT INTO household_water_consumption (id,state,water_consumption) VALUES (1,'California',150),(2,'California',200),(3,'Texas',120);
|
SELECT state, MAX(water_consumption) FROM household_water_consumption WHERE state = 'California';
|
What is the average energy production of wind turbines installed in the USA before 2010?
|
CREATE TABLE wind_turbines (id INT,installation_year INT,energy_production FLOAT); INSERT INTO wind_turbines (id,installation_year,energy_production) VALUES (1,2005,2.5),(2,2008,3.2),(3,2012,3.8),(4,2015,4.1);
|
SELECT AVG(energy_production) FROM wind_turbines WHERE installation_year < 2010;
|
Update the 'city' column in the 'stations' table for 'Station 1' to 'New York'
|
CREATE TABLE stations (id INT,name TEXT,city TEXT,capacity INT);
|
UPDATE stations SET city = 'New York' WHERE name = 'Station 1';
|
What is the average ESG rating for companies in the 'technology' sector?
|
CREATE TABLE companies (id INT,sector VARCHAR(20),ESG_rating FLOAT)
|
SELECT AVG(ESG_rating) FROM companies WHERE sector = 'technology'
|
What is the total number of registered voters in the state of Texas, and what is the percentage of those voters who are registered as Democrats?
|
CREATE TABLE parties (party_name VARCHAR(255),party_abbreviation VARCHAR(255)); INSERT INTO parties VALUES ('Democratic Party','DP'); INSERT INTO parties VALUES ('Republican Party','RP'); CREATE TABLE voters (voter_name VARCHAR(255),voter_party VARCHAR(255),state VARCHAR(255));
|
SELECT (COUNT(*) FILTER (WHERE voter_party = 'DP')::float / COUNT(*) * 100) AS democratic_percentage FROM voters JOIN states ON voters.state = states.state_abbreviation WHERE states.state_name = 'Texas';
|
What is the total number of alternative sentencing programs implemented in Illinois since 2017?
|
CREATE TABLE alternative_sentencing_programs (program_id INT,year INT,state VARCHAR(20)); INSERT INTO alternative_sentencing_programs (program_id,year,state) VALUES (1,2022,'Illinois'),(2,2021,'Illinois'),(3,2020,'Illinois'),(4,2019,'Illinois'),(5,2018,'Illinois'),(6,2017,'Illinois');
|
SELECT COUNT(*) FROM alternative_sentencing_programs WHERE year >= 2017 AND state = 'Illinois';
|
What is the maximum quantity of eco-friendly dye used in a single batch?
|
CREATE TABLE dye_usage (id INT,batch_number INT,dye_type VARCHAR(20),quantity INT); INSERT INTO dye_usage (id,batch_number,dye_type,quantity) VALUES (1,101,'eco_friendly',200); INSERT INTO dye_usage (id,batch_number,dye_type,quantity) VALUES (2,102,'regular',300);
|
SELECT MAX(quantity) FROM dye_usage WHERE dye_type = 'eco_friendly';
|
What is the total waste generation trend in metric tons per year for the Caribbean region from 2017 to 2021?
|
CREATE TABLE waste_generation_trend_caribbean (region VARCHAR(50),year INT,waste_amount FLOAT); INSERT INTO waste_generation_trend_caribbean (region,year,waste_amount) VALUES ('Caribbean',2017,120000.0),('Caribbean',2018,130000.0),('Caribbean',2019,140000.0),('Caribbean',2020,150000.0),('Caribbean',2021,160000.0);
|
SELECT year, SUM(waste_amount) FROM waste_generation_trend_caribbean WHERE region = 'Caribbean' GROUP BY year;
|
What is the percentage of donation amount by gender, with cross join?
|
CREATE TABLE Donors (DonorID INT,DonorName TEXT,DonationAmount DECIMAL,Gender TEXT); INSERT INTO Donors (DonorID,DonorName,DonationAmount,Gender) VALUES (1,'John Doe',500.00,'Male'),(2,'Jane Smith',350.00,'Female'),(3,'Alice Johnson',700.00,'Female');
|
SELECT D1.Gender, SUM(D1.DonationAmount) as TotalDonation, (SUM(D1.DonationAmount)/SUM(D2.DonationAmount))*100 as Percentage FROM Donors D1 CROSS JOIN Donors D2 GROUP BY D1.Gender;
|
What is the average price of silk shirts sold in the past year, grouped by month?
|
CREATE TABLE silk_shirts (id INT PRIMARY KEY,price DECIMAL(5,2),sale_date DATE); INSERT INTO silk_shirts (id,price,sale_date) VALUES (1,59.99,'2021-06-15'),(2,69.99,'2021-07-10'),(3,49.99,'2021-08-05');
|
SELECT AVG(price), EXTRACT(MONTH FROM sale_date) FROM silk_shirts WHERE sale_date >= DATE '2020-01-01' AND sale_date < DATE '2021-01-01' AND shirt_type = 'silk' GROUP BY EXTRACT(MONTH FROM sale_date);
|
How many sustainable construction projects were completed in Texas?
|
CREATE TABLE CompletedProjects (project_id INT,sustainability VARCHAR(255),state VARCHAR(255)); INSERT INTO CompletedProjects (project_id,sustainability,state) VALUES (1,'sustainable','Texas'),(2,'not sustainable','California');
|
SELECT COUNT(*) FROM CompletedProjects WHERE sustainability = 'sustainable' AND state = 'Texas';
|
Update freight forwarder addresses
|
CREATE TABLE forwarders(id INT,name VARCHAR(255),address VARCHAR(255)); INSERT INTO forwarders VALUES(1,'ABC Logistics','123 Main St'),(2,'DEF Freight','456 Elm St');
|
UPDATE forwarders SET address = '789 Oak St' WHERE name = 'ABC Logistics'; UPDATE forwarders SET address = '321 Maple St' WHERE name = 'DEF Freight';
|
Display the number of electric bicycles and electric scooters in the micro_mobility view.
|
CREATE VIEW micro_mobility AS SELECT 'ebike' AS vehicle_type,COUNT(*) AS quantity UNION ALL SELECT 'escooter',COUNT(*);
|
SELECT vehicle_type, quantity FROM micro_mobility;
|
Display bioprocess engineering information for projects with a duration greater than 12 months and order the results by duration in ascending order.
|
CREATE SCHEMA if not exists bioprocess; CREATE TABLE if not exists bioprocess.projects (id INT,name VARCHAR(100),duration INT); INSERT INTO bioprocess.projects (id,name,duration) VALUES (1,'Protein Production',18),(2,'Cell Culture',15),(3,'Fermentation',9),(4,'Bioprocess Optimization',24);
|
SELECT * FROM bioprocess.projects WHERE duration > 12 ORDER BY duration ASC;
|
Identify the number of pollution control initiatives in the Indian Ocean by country.
|
CREATE TABLE pollution_control_initiatives (initiative_id INT,initiative_name TEXT,country TEXT,region TEXT); INSERT INTO pollution_control_initiatives (initiative_id,initiative_name,country,region) VALUES (1,'Initiative X','India','Indian Ocean'),(2,'Initiative Y','Australia','Indian Ocean'),(3,'Initiative Z','Indonesia','Indian Ocean');
|
SELECT country, COUNT(*) FROM pollution_control_initiatives WHERE region = 'Indian Ocean' GROUP BY country;
|
How many community policing programs were active between 2015 and 2017?
|
CREATE TABLE community_policing (id INT PRIMARY KEY,program_name VARCHAR(50),start_date DATE,end_date DATE);
|
SELECT COUNT(*) as active_programs FROM community_policing WHERE start_date BETWEEN '2015-01-01' AND '2017-12-31' AND end_date BETWEEN '2015-01-01' AND '2017-12-31';
|
What is the total CO2 emission from all hotels in Spain?
|
CREATE TABLE Hotels (id INT,name TEXT,country TEXT,type TEXT,co2_emission INT); INSERT INTO Hotels (id,name,country,type,co2_emission) VALUES (1,'Eco Hotel','Spain','Eco',50);
|
SELECT SUM(co2_emission) FROM Hotels WHERE country = 'Spain';
|
What is the total cost of ingredients sourced from sustainable suppliers for each product category?
|
CREATE TABLE ingredients (ingredient_id INT,product_id INT,supplier_id INT,cost DECIMAL(10,2)); CREATE TABLE suppliers (supplier_id INT,supplier_name TEXT,is_sustainable BOOLEAN); CREATE TABLE products (product_id INT,product_name TEXT,product_category TEXT);
|
SELECT products.product_category, SUM(ingredients.cost) as total_cost FROM ingredients INNER JOIN suppliers ON ingredients.supplier_id = suppliers.supplier_id INNER JOIN products ON ingredients.product_id = products.product_id WHERE suppliers.is_sustainable = TRUE GROUP BY products.product_category;
|
What is the average age of teachers who have completed cross-cultural training in the last 2 years, in New York state?
|
CREATE TABLE states (state_name VARCHAR(255),state_id INT); INSERT INTO states (state_name,state_id) VALUES ('New York',2); CREATE TABLE schools (school_name VARCHAR(255),state_id INT,PRIMARY KEY (school_name,state_id)); CREATE TABLE teachers (teacher_id INT,teacher_age INT,school_name VARCHAR(255),state_id INT,PRIMARY KEY (teacher_id),FOREIGN KEY (school_name,state_id) REFERENCES schools(school_name,state_id)); CREATE TABLE professional_development (pd_id INT,teacher_id INT,pd_date DATE,pd_type VARCHAR(255),PRIMARY KEY (pd_id),FOREIGN KEY (teacher_id) REFERENCES teachers(teacher_id));
|
SELECT AVG(teachers.teacher_age) FROM teachers INNER JOIN professional_development ON teachers.teacher_id = professional_development.teacher_id INNER JOIN schools ON teachers.school_name = schools.school_name WHERE schools.state_id = 2 AND professional_development.pd_type = 'cross-cultural training' AND professional_development.pd_date >= DATEADD(year, -2, GETDATE());
|
List all types of renewable energy projects in the database
|
CREATE TABLE projects (id INT,name TEXT,type TEXT);
|
SELECT DISTINCT type FROM projects;
|
Which accessible technology projects were launched before 2010?
|
CREATE TABLE AccessibleTech (project_id INT,launch_date DATE); INSERT INTO AccessibleTech (project_id,launch_date) VALUES (1,'2005-02-17'),(2,'2007-11-09'),(3,'2009-06-23'),(4,'2011-08-04'),(5,'2013-01-15');
|
SELECT project_id, launch_date FROM AccessibleTech WHERE launch_date < '2010-01-01';
|
List all departments and their associated data types.
|
CREATE TABLE department_data (dept_name TEXT,column_name TEXT,data_type TEXT); INSERT INTO department_data (dept_name,column_name,data_type) VALUES ('Human Services Department','age','INTEGER'),('Human Services Department','gender','TEXT'),('Human Services Department','income','FLOAT'),('Education Department','school_name','TEXT'),('Education Department','student_count','INTEGER');
|
SELECT dept_name, column_name, data_type FROM department_data;
|
List suppliers from Southeast Asia who use ethical labor practices.
|
CREATE TABLE suppliers (supplier_id INT,name VARCHAR(255),region VARCHAR(50),ethical_labor_practices BOOLEAN); INSERT INTO suppliers (supplier_id,name,region,ethical_labor_practices) VALUES (1,'Fair Trade Fabrics','Southeast Asia',TRUE),(2,'Eco-Friendly Packaging','North America',FALSE);
|
SELECT * FROM suppliers WHERE region = 'Southeast Asia' AND ethical_labor_practices = TRUE;
|
How many unique artists have released songs in the 'Rock' genre?
|
CREATE TABLE songs (id INT,title VARCHAR(100),release_year INT,genre VARCHAR(50),streams INT); INSERT INTO songs (id,title,release_year,genre,streams) VALUES (1,'Shape of You',2017,'Pop',2000000000); INSERT INTO songs (id,title,release_year,genre,streams) VALUES (2,'Sicko Mode',2018,'Hip Hop',1500000000); INSERT INTO songs (id,title,release_year,genre,streams) VALUES (3,'Black Panther',2018,'Soundtrack',1200000000); CREATE TABLE artists (id INT,name VARCHAR(100),age INT,genre VARCHAR(50)); INSERT INTO artists (id,name,age,genre) VALUES (1,'Ed Sheeran',30,'Pop'); INSERT INTO artists (id,name,age,genre) VALUES (2,'Travis Scott',31,'Hip Hop'); INSERT INTO artists (id,name,age,genre) VALUES (3,'Kendrick Lamar',34,'Soundtrack'); INSERT INTO artists (id,name,age,genre) VALUES (4,'Queen',50,'Rock');
|
SELECT COUNT(DISTINCT artists.name) FROM songs JOIN artists ON songs.genre = artists.genre WHERE artists.genre = 'Rock';
|
What is the total number of hours that the network was under attack in the past month?
|
CREATE TABLE attack_timeline(id INT,start_time TIMESTAMP,end_time TIMESTAMP);
|
SELECT SUM(TIMESTAMPDIFF(HOUR, start_time, end_time)) as total_hours FROM attack_timeline WHERE start_time >= NOW() - INTERVAL 1 MONTH;
|
List the production figures of gas for all fields in the Gulf of Mexico in Q1 2019.
|
CREATE TABLE gulf_of_mexico_fields (field_id INT,field_name VARCHAR(50),gas_production FLOAT,datetime DATETIME); INSERT INTO gulf_of_mexico_fields (field_id,field_name,gas_production,datetime) VALUES (1,'Gulf of Mexico Field A',2000000,'2019-01-01 00:00:00'),(2,'Gulf of Mexico Field B',2500000,'2019-01-01 00:00:00');
|
SELECT field_name, SUM(gas_production) FROM gulf_of_mexico_fields WHERE QUARTER(datetime) = 1 AND YEAR(datetime) = 2019 GROUP BY field_name;
|
Which models were trained on the 'arts_images' table?
|
CREATE TABLE arts_images (id INT,image_url VARCHAR(255),image_type VARCHAR(50),model_used VARCHAR(50));
|
SELECT model_used FROM arts_images;
|
List the names and capacities of all warehouses in India and the total quantity of items stored in each.
|
CREATE TABLE Warehouses(id INT,location VARCHAR(50),capacity INT); INSERT INTO Warehouses(id,location,capacity) VALUES (1,'India',1500); CREATE TABLE Inventory(id INT,warehouse_id INT,quantity INT); INSERT INTO Inventory(id,warehouse_id,quantity) VALUES (1,1,750);
|
SELECT Warehouses.location, SUM(Inventory.quantity), Warehouses.capacity FROM Warehouses INNER JOIN Inventory ON Warehouses.id = Inventory.warehouse_id WHERE Warehouses.location = 'India' GROUP BY Warehouses.id;
|
Check if the 'habitat_preservation' program exists
|
CREATE TABLE animal_population (animal_id INT,animal_name VARCHAR(50),program VARCHAR(50)); INSERT INTO animal_population (animal_id,animal_name,program) VALUES (1,'Grizzly Bear','habitat_preservation'),(2,'Gray Wolf','community_education');
|
SELECT EXISTS(SELECT 1 FROM animal_population WHERE program = 'habitat_preservation');
|
What is the average salary for male employees in the IT department?
|
CREATE TABLE Employees (EmployeeID INT,Gender VARCHAR(10),Department VARCHAR(20),Salary FLOAT);
|
SELECT AVG(Salary) FROM Employees WHERE Gender = 'Male' AND Department = 'IT';
|
What is the distribution of traditional art forms by region?
|
CREATE TABLE traditional_arts (id INT,art_form VARCHAR(255),region VARCHAR(255),country VARCHAR(255)); INSERT INTO traditional_arts (id,art_form,region,country) VALUES (1,'Uzbek Suzani','Central Asia','Uzbekistan'),(2,'Kilim Weaving','Middle East','Turkey');
|
SELECT region, COUNT(*) as art_forms_count FROM traditional_arts GROUP BY region;
|
Add a new restorative justice program to the "programs" table
|
CREATE TABLE programs (id INT,name VARCHAR(50),type VARCHAR(20),location VARCHAR(50));
|
INSERT INTO programs (id, name, type, location) VALUES (3002, 'Neighborhood Healing', 'Restorative Justice', 'San Francisco');
|
What is the total number of geothermal power plants in the state of Nevada, grouped by plant status?
|
CREATE TABLE geothermal_plants (id INT,plant_name VARCHAR(255),state VARCHAR(255),plant_status VARCHAR(255),num_units INT);
|
SELECT plant_status, COUNT(plant_name) FROM geothermal_plants WHERE state = 'Nevada' GROUP BY plant_status;
|
What is the total amount of waste produced by each site in the past year?
|
CREATE TABLE WasteData (SiteName VARCHAR(50),WasteQuantity INT,WasteDate DATE); INSERT INTO WasteData (SiteName,WasteQuantity,WasteDate) VALUES ('Site A',2000,'2022-02-15');
|
SELECT SiteName, SUM(WasteQuantity) FROM WasteData WHERE WasteDate >= CURRENT_DATE - INTERVAL '1 year' GROUP BY SiteName;
|
What is the minimum number of workers in factories that produce the most ethical activewear?
|
CREATE TABLE Factories (factory_id INT,name VARCHAR(100),location VARCHAR(100),num_workers INT,wage DECIMAL(5,2)); CREATE TABLE Products (product_id INT,name VARCHAR(100),factory_id INT); INSERT INTO Factories VALUES (1,'Factory X','Los Angeles',100,15.00),(2,'Factory Y','Jakarta',250,5.00),(3,'Factory Z','Rome',300,12.00),(4,'Factory W','Berlin',150,18.00); INSERT INTO Products VALUES (1,'Eco Leggings',1),(2,'Fair Trade Tank Top',2),(3,'Sustainable Sports Bra',3),(4,'Organic Cotton Shirt',3);
|
SELECT MIN(Factories.num_workers) FROM Factories JOIN Products ON Factories.factory_id = Products.factory_id WHERE Products.name LIKE '%activewear%';
|
What is the maximum pollution level recorded in the Mediterranean Sea in the last 5 years?
|
CREATE TABLE pollution_records (id INT,location TEXT,pollution_level INT,record_date DATE); INSERT INTO pollution_records (id,location,pollution_level,record_date) VALUES (1,'Mediterranean Sea',8,'2018-01-01'),(2,'Mediterranean Sea',9,'2019-01-01'),(3,'Baltic Sea',7,'2020-01-01');
|
SELECT MAX(pollution_level) FROM pollution_records WHERE location = 'Mediterranean Sea' AND record_date >= DATE_SUB(CURRENT_DATE, INTERVAL 5 YEAR);
|
Count the number of water treatment plants in California that were built after 2015?
|
CREATE TABLE water_treatment_plants (name VARCHAR(50),state VARCHAR(2),built INT); INSERT INTO water_treatment_plants (name,state,built) VALUES ('Plant A','CA',2017),('Plant B','CA',2019),('Plant C','CA',2013);
|
SELECT COUNT(*) FROM water_treatment_plants WHERE state = 'CA' AND built > 2015;
|
What was the revenue generated by each hotel in Spain in the last quarter?
|
CREATE TABLE hotel_revenue (hotel_name TEXT,quarter TEXT,revenue INT); INSERT INTO hotel_revenue (hotel_name,quarter,revenue) VALUES ('Barcelona Eco Hotel','Q1',8000),('Madrid Green Hotel','Q1',10000);
|
SELECT hotel_name, revenue FROM hotel_revenue WHERE quarter = 'Q1' AND hotel_name LIKE '%Spain%';
|
What is the total donation amount for donor 'Bob Johnson'?
|
CREATE TABLE donors (donor_id INT,donor_name VARCHAR(30),donation_amount DECIMAL(5,2)); INSERT INTO donors (donor_id,donor_name,donation_amount) VALUES (1,'Jane Doe',300),(2,'Mary Smith',400),(3,'Bob Johnson',200),(5,'Sophia Lee',700);
|
SELECT SUM(donation_amount) FROM donors WHERE donor_name = 'Bob Johnson';
|
Identify community engagement events in 'Africa' between 2000 and 2005.
|
CREATE TABLE CommunityEngagement (id INT,name VARCHAR(255),region VARCHAR(255),start_year INT,end_year INT); INSERT INTO CommunityEngagement (id,name,region,start_year,end_year) VALUES (1,'Cape Town Jazz Festival','Africa',2000,2005);
|
SELECT * FROM CommunityEngagement WHERE region = 'Africa' AND start_year BETWEEN 2000 AND 2005;
|
Find the average virtual tour bookings per user in Tokyo and Osaka.
|
CREATE TABLE user_virtual_tours (user_id INT,city VARCHAR(20),tour_count INT); INSERT INTO user_virtual_tours (user_id,city,tour_count) VALUES (1,'Tokyo',5),(2,'Tokyo',3),(3,'Osaka',4),(4,'Osaka',2);
|
SELECT AVG(tour_count) FROM user_virtual_tours WHERE city IN ('Tokyo', 'Osaka');
|
What is the average donation amount made to environmental causes in the US in 2021?
|
CREATE TABLE donations_environment_us (id INT,donor_name TEXT,country TEXT,cause TEXT,donation_amount DECIMAL,donation_date DATE); INSERT INTO donations_environment_us (id,donor_name,country,cause,donation_amount,donation_date) VALUES (1,'John Smith','USA','Environment',100.00,'2021-05-10'); INSERT INTO donations_environment_us (id,donor_name,country,cause,donation_amount,donation_date) VALUES (2,'Emily Johnson','USA','Environment',200.00,'2021-03-25');
|
SELECT AVG(donation_amount) FROM donations_environment_us WHERE country = 'USA' AND cause = 'Environment' AND YEAR(donation_date) = 2021;
|
How many pollution control initiatives are registered in the Atlantic ocean in the pollution_control table?
|
CREATE TABLE pollution_control (id INT,name TEXT,region TEXT); INSERT INTO pollution_control (id,name,region) VALUES (1,'Initiative A','Indian Ocean'); INSERT INTO pollution_control (id,name,region) VALUES (2,'Initiative B','Atlantic Ocean');
|
SELECT COUNT(*) FROM pollution_control WHERE region = 'Atlantic Ocean';
|
Which crops were planted in '2022'?
|
CREATE TABLE Crops (id INT PRIMARY KEY,name VARCHAR(50),planting_date DATE,harvest_date DATE,yield INT,farmer_id INT,FOREIGN KEY (farmer_id) REFERENCES Farmers(id)); INSERT INTO Crops (id,name,planting_date,harvest_date,yield,farmer_id) VALUES (1,'Corn','2022-05-01','2022-08-01',100,1); INSERT INTO Crops (id,name,planting_date,harvest_date,yield,farmer_id) VALUES (2,'Soybeans','2022-06-15','2022-09-15',50,2); INSERT INTO Crops (id,name,planting_date,harvest_date,yield,farmer_id) VALUES (3,'Rice','2021-03-01','2021-06-01',80,3);
|
SELECT * FROM Crops WHERE YEAR(planting_date) = 2022;
|
Identify the top 3 most vulnerable software applications and their associated vulnerabilities
|
CREATE TABLE vulnerabilities (id INT,software_app VARCHAR(50),severity INT);
|
SELECT software_app, severity, COUNT(*) as num_vulnerabilities FROM vulnerabilities WHERE severity >= 5 GROUP BY software_app ORDER BY num_vulnerabilities DESC LIMIT 3;
|
Total budget for AI safety projects.
|
CREATE TABLE safety_projects (id INT PRIMARY KEY,project_name VARCHAR(50),budget FLOAT); INSERT INTO safety_projects (id,project_name,budget) VALUES (1,'Secure AI',150000.0),(2,'Robust AI',125000.0),(3,'Privacy-Preserving AI',170000.0),(4,'Verification & Validation',200000.0),(5,'Ethical AI',225000.0);
|
SELECT SUM(budget) FROM safety_projects;
|
List pollution levels with a sudden increase.
|
CREATE TABLE PollutionTrend (ID INT,Location VARCHAR(50),Pollutant VARCHAR(50),Level INT,MeasurementDate DATE); INSERT INTO PollutionTrend (ID,Location,Pollutant,Level,MeasurementDate) VALUES (1,'NewYork','Mercury',5,'2020-01-01'),(2,'California','Lead',10,'2020-01-02'),(3,'Texas','CarbonMonoxide',15,'2020-01-03'),(4,'NewYork','Mercury',10,'2020-01-04');
|
SELECT Location, Pollutant, Level, LEAD(Level) OVER (PARTITION BY Location ORDER BY MeasurementDate) as NextLevel FROM PollutionTrend;
|
Which games were released before 2010 and have a genre of 'Action'?
|
CREATE TABLE Games (GameID INT,Name VARCHAR(50),Genre VARCHAR(20),ReleaseDate DATETIME,Publisher VARCHAR(50)); INSERT INTO Games (GameID,Name,Genre,ReleaseDate,Publisher) VALUES (2,'Grand Theft Auto III','Action','2001-10-22','Rockstar Games');
|
SELECT Name FROM Games WHERE ReleaseDate < '2010-01-01' AND Genre = 'Action';
|
How many consumer complaints were there for each cosmetic product in 2022?
|
CREATE TABLE Consumer_Complaints (ComplaintID INT,ProductID INT,ComplaintDate DATE); INSERT INTO Consumer_Complaints (ComplaintID,ProductID,ComplaintDate) VALUES (7,101,'2022-01-01'),(8,102,'2022-02-01'),(9,101,'2022-03-01'),(10,103,'2022-04-01'),(11,102,'2022-05-01'),(12,101,'2022-06-01');
|
SELECT ProductID, COUNT(*) as Complaints FROM Consumer_Complaints WHERE EXTRACT(YEAR FROM ComplaintDate) = 2022 GROUP BY ProductID;
|
What is the total number of organic farms in Canada?
|
CREATE TABLE farms (country VARCHAR(255),organic BOOLEAN); INSERT INTO farms (country,organic) VALUES ('Canada',TRUE),('Canada',TRUE),('Canada',FALSE),('Canada',TRUE);
|
SELECT COUNT(*) FROM farms WHERE country = 'Canada' AND organic = TRUE;
|
What is the data usage distribution for broadband customers in a specific state?
|
CREATE TABLE broadband_customers (customer_id INT,data_usage FLOAT,state VARCHAR(50)); INSERT INTO broadband_customers (customer_id,data_usage,state) VALUES (1,3.5,'New York'),(2,4.2,'California'),(3,5.1,'New York'); CREATE VIEW data_usage_view AS SELECT state,SUM(data_usage) as total_data_usage FROM broadband_customers GROUP BY state;
|
SELECT state, total_data_usage, total_data_usage/SUM(total_data_usage) OVER (PARTITION BY state) as data_usage_percentage FROM data_usage_view;
|
What is the number of visitors who attended the "African Art" exhibition and are under 30 years old?
|
CREATE TABLE age_demographics (visitor_id INT,age INT); INSERT INTO age_demographics (visitor_id,age) VALUES (100,28);
|
SELECT COUNT(*) FROM visitor_presence JOIN exhibitions ON visitor_presence.exhibition_id = exhibitions.exhibition_id JOIN age_demographics ON visitor_presence.visitor_id = age_demographics.visitor_id WHERE exhibitions.exhibition_name = 'African Art' AND age_demographics.age < 30;
|
Find all reverse logistics metrics for Route 2 and Route 3
|
CREATE TABLE ReverseLogistics (id INT,route VARCHAR(50),metric INT); INSERT INTO ReverseLogistics (id,route,metric) VALUES (1,'Route 2',200),(2,'Route 3',300);
|
SELECT route, metric FROM ReverseLogistics WHERE route IN ('Route 2', 'Route 3');
|
What is the average rating of attractions in Tokyo?
|
CREATE TABLE attractions (id INT,name VARCHAR(50),city VARCHAR(20),rating FLOAT); INSERT INTO attractions (id,name,city,rating) VALUES (1,'Palace','Tokyo',4.5),(2,'Castle','Osaka',4.2),(3,'Shrine','Kyoto',4.7);
|
SELECT AVG(rating) FROM attractions WHERE city = 'Tokyo';
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.