instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
What is the total energy consumption by each department in the last quarter?
|
CREATE TABLE departments (id INT,name TEXT); INSERT INTO departments (id,name) VALUES (1,'Research'),(2,'Production'),(3,'Quality'),(4,'Maintenance'); CREATE TABLE energy_consumption (dept_id INT,consumption_date DATE,energy_used FLOAT); INSERT INTO energy_consumption (dept_id,consumption_date,energy_used) VALUES (1,'2022-01-01',500.0),(1,'2022-01-02',510.0),(1,'2022-01-03',495.0),(2,'2022-01-01',800.0),(2,'2022-01-02',805.0),(2,'2022-01-03',795.0),(3,'2022-01-01',300.0),(3,'2022-01-02',310.0),(3,'2022-01-03',295.0),(4,'2022-01-01',600.0),(4,'2022-01-02',610.0),(4,'2022-01-03',595.0);
|
SELECT dept_id, SUM(energy_used) as total_energy_consumption FROM energy_consumption WHERE consumption_date BETWEEN DATE_SUB(NOW(), INTERVAL 3 MONTH) AND NOW() GROUP BY dept_id;
|
What is the average response time for emergency calls in 'Harbor Side' this year?
|
CREATE TABLE emergency_calls (id INT,region VARCHAR(20),response_time INT,year INT);
|
SELECT AVG(response_time) FROM emergency_calls WHERE region = 'Harbor Side' AND year = YEAR(CURRENT_DATE);
|
List all the airports and their respective runway lengths from the 'airport_info' and 'runway_lengths' tables.
|
CREATE TABLE airport_info (airport_id INT,airport_name VARCHAR(50)); CREATE TABLE runway_lengths (airport_id INT,runway_length INT); INSERT INTO airport_info (airport_id,airport_name) VALUES (1,'JFK Airport'),(2,'LaGuardia Airport'),(3,'Newark Airport'); INSERT INTO runway_lengths (airport_id,runway_length) VALUES (1,14000),(2,7000),(3,11000);
|
SELECT airport_info.airport_name, runway_lengths.runway_length FROM airport_info INNER JOIN runway_lengths ON airport_info.airport_id = runway_lengths.airport_id;
|
What is the total CO2 emissions for uranium mines that have more than 200 employees?
|
CREATE TABLE uranium_mines (id INT,name VARCHAR(50),location VARCHAR(50),size INT,num_employees INT,co2_emissions INT); INSERT INTO uranium_mines VALUES (1,'Uranium Mine 1','Canada',450,350,25000); INSERT INTO uranium_mines VALUES (2,'Uranium Mine 2','USA',600,400,30000); INSERT INTO uranium_mines VALUES (3,'Uranium Mine 3','Kazakhstan',200,150,15000);
|
SELECT SUM(co2_emissions) FROM uranium_mines WHERE num_employees > 200;
|
What are the earliest artifacts from each excavation site?
|
CREATE TABLE Sites (SiteID INT,SiteName TEXT); INSERT INTO Sites (SiteID,SiteName) VALUES (1,'Site-A'),(2,'Site-B'),(3,'Site-C'); CREATE TABLE Artifacts (ArtifactID INT,ArtifactName TEXT,SiteID INT,Age INT); INSERT INTO Artifacts (ArtifactID,ArtifactName,SiteID,Age) VALUES (1,'Pottery Shard',1,1000),(2,'Bronze Arrowhead',2,800),(3,'Flint Tool',3,2000),(4,'Ancient Coin',1,1500),(5,'Stone Hammer',2,3000);
|
SELECT Sites.SiteName, MIN(Artifacts.Age) AS EarliestAge FROM Sites INNER JOIN Artifacts ON Sites.SiteID = Artifacts.SiteID GROUP BY Sites.SiteName;
|
What is the total number of ingredients in each beauty product?
|
CREATE TABLE products (product_id INT,product_name VARCHAR(255),num_ingredients INT); CREATE TABLE ingredients (ingredient_id INT,product_id INT,ingredient_name VARCHAR(255));
|
SELECT p.product_name, COUNT(i.ingredient_id) as total_ingredients FROM products p INNER JOIN ingredients i ON p.product_id = i.product_id GROUP BY p.product_name;
|
How many pharmacies are there in the state of California that have a prescription volume greater than 5000?
|
CREATE TABLE pharmacies (name TEXT,state TEXT,prescription_volume INTEGER); INSERT INTO pharmacies (name,state,prescription_volume) VALUES ('CVS Pharmacy','California',7000),('Walgreens','California',6500),('Rite Aid Pharmacy','California',5500);
|
SELECT COUNT(*) FROM pharmacies WHERE state = 'California' AND prescription_volume > 5000;
|
What percentage of size 14 garments were sold to repeat customers in the last quarter?
|
CREATE TABLE sales (item VARCHAR(20),size VARCHAR(5),customer VARCHAR(20),date DATE); INSERT INTO sales (item,size,customer,date) VALUES ('Dress','14','Customer A','2022-04-01'),('Skirt','14','Customer A','2022-05-15'),('Top','14','Customer B','2022-06-30'); CREATE TABLE customers (customer VARCHAR(20),purchase_count INT); INSERT INTO customers (customer,purchase_count) VALUES ('Customer A',2),('Customer B',1);
|
SELECT (COUNT(*) FILTER (WHERE purchases >= 2)) * 100.0 / COUNT(*) FROM (SELECT customer, COUNT(*) AS purchases FROM sales WHERE size = '14' AND date >= '2022-04-01' AND date <= '2022-06-30' GROUP BY customer) AS subquery INNER JOIN customers ON subquery.customer = customers.customer;
|
How many mining accidents were reported in Asia in the last 5 years?
|
CREATE TABLE Accidents (AccidentID INT,CompanyID INT,AccidentDate DATE); INSERT INTO Accidents (AccidentID,CompanyID,AccidentDate) VALUES (1,1,'2020-01-01'),(2,2,'2019-12-15'),(3,3,'2018-05-23'),(4,4,'2017-09-04'),(5,1,'2016-02-10');
|
SELECT COUNT(*) FROM Accidents WHERE YEAR(AccidentDate) >= YEAR(CURRENT_DATE) - 5 AND Country IN ('China', 'India', 'Indonesia');
|
Display the number of fish for each species in the 'FreshwaterFish' table
|
CREATE TABLE FreshwaterFish (id INT,species VARCHAR(255),weight FLOAT,length FLOAT); INSERT INTO FreshwaterFish (id,species,weight,length) VALUES (1,'Catfish',1.2,0.35); INSERT INTO FreshwaterFish (id,species,weight,length) VALUES (2,'Bass',0.7,0.3); INSERT INTO FreshwaterFish (id,species,weight,length) VALUES (3,'Trout',0.5,0.25);
|
SELECT species, COUNT(*) FROM FreshwaterFish GROUP BY species;
|
Update the feed conversion ratio for all farmed cod in Norway to 1.5 in 2021.
|
CREATE TABLE Farming(country VARCHAR(255),year INT,species VARCHAR(255),feed_conversion_ratio FLOAT);
|
UPDATE Farming SET feed_conversion_ratio = 1.5 WHERE country = 'Norway' AND species = 'Cod' AND year = 2021;
|
Determine the total weight of all 'Frozen' products imported from 'Europe'
|
CREATE TABLE imports (import_id INT,import_date DATE,weight INT,country TEXT,product TEXT); INSERT INTO imports (import_id,import_date,weight,country,product) VALUES (1,'2022-01-01',500,'Germany','Frozen Fish'),(2,'2022-01-05',600,'France','Frozen Chicken'),(3,'2022-02-10',700,'India','Fish'),(4,'2022-03-15',800,'England','Frozen Vegetables');
|
SELECT SUM(weight) FROM imports WHERE product LIKE 'Frozen%' AND country IN ('Germany', 'France', 'England');
|
How many citizen feedback records were received for each public service in the province of Quebec in the last month?
|
CREATE TABLE feedback (service VARCHAR(255),date DATE); INSERT INTO feedback (service,date) VALUES ('education','2023-01-01'),('education','2023-02-15'),('healthcare','2023-03-01'),('transportation','2023-04-01'),('education','2023-03-20'),('healthcare','2023-04-10');
|
SELECT service, COUNT(*) FROM feedback WHERE date >= DATEADD(month, -1, GETDATE()) GROUP BY service;
|
Find the number of geothermal power projects in Indonesia, Philippines, and Mexico.
|
CREATE TABLE geothermal_power_projects (id INT,name TEXT,country TEXT); INSERT INTO geothermal_power_projects (id,name,country) VALUES (1,'Sarulla Geothermal Power Plant','Indonesia');
|
SELECT COUNT(*) FROM geothermal_power_projects WHERE country IN ('Indonesia', 'Philippines', 'Mexico');
|
What is the average number of pallets shipped per day from the 'Berlin' warehouse to 'Germany' via 'Global Shipping' in the last month?
|
CREATE TABLE warehouse (id INT PRIMARY KEY,name VARCHAR(50),city VARCHAR(50));CREATE TABLE carrier (id INT PRIMARY KEY,name VARCHAR(50));CREATE TABLE shipment (id INT PRIMARY KEY,warehouse_id INT,carrier_id INT,pallet_count INT,shipped_date DATE);
|
SELECT AVG(shipment.pallet_count / 30) FROM shipment WHERE shipment.warehouse_id = (SELECT id FROM warehouse WHERE city = 'Berlin') AND shipment.carrier_id = (SELECT id FROM carrier WHERE name = 'Global Shipping') AND shipment.shipped_date BETWEEN (CURRENT_DATE - INTERVAL '30 days') AND CURRENT_DATE;
|
What is the total spending on healthcare per rural capita in New York?
|
CREATE TABLE healthcare_spending (id INTEGER,state VARCHAR(255),county VARCHAR(255),amount FLOAT);
|
SELECT county, AVG(amount) AS avg_spending FROM healthcare_spending WHERE state = 'New York' AND county LIKE '%rural%' GROUP BY county;
|
Delete subscribers who have not made any payments in Q3 of 2023 for the 'Broadband' service.
|
CREATE TABLE Subscribers (subscriber_id INT,service VARCHAR(20),region VARCHAR(20),revenue FLOAT,payment_date DATE); INSERT INTO Subscribers (subscriber_id,service,region,revenue,payment_date) VALUES (1,'Broadband','Metro',50.00,'2023-07-01'),(2,'Mobile','Urban',35.00,'2023-07-15'),(3,'Mobile','Rural',20.00,'2023-07-31'),(4,'Broadband','Metro',40.00,NULL),(5,'Broadband','Rural',60.00,'2023-07-20');
|
DELETE FROM Subscribers WHERE service = 'Broadband' AND QUARTER(payment_date) = 3 AND YEAR(payment_date) = 2023 AND payment_date IS NULL;
|
What is the total number of artworks in the 'modern' and 'contemporary' categories?
|
CREATE TABLE Artworks (id INT,category VARCHAR(20)); INSERT INTO Artworks (id,category) VALUES (1,'modern'),(2,'contemporary'),(3,'classic');
|
SELECT COUNT(*) FROM Artworks WHERE category IN ('modern', 'contemporary');
|
How many patients have been treated with psychodynamic therapy in Florida?
|
CREATE TABLE patients (id INT,name TEXT,state TEXT);CREATE TABLE treatments (id INT,patient_id INT,therapy TEXT);INSERT INTO patients (id,name,state) VALUES (1,'James Doe','Florida');INSERT INTO treatments (id,patient_id,therapy) VALUES (1,1,'Psychodynamic');
|
SELECT COUNT(DISTINCT patients.id) FROM patients INNER JOIN treatments ON patients.id = treatments.patient_id WHERE patients.state = 'Florida' AND treatments.therapy = 'Psychodynamic';
|
What is the total zinc production for each machine type?
|
CREATE TABLE zinc_production (id INT,machine_type VARCHAR(20),zinc_production FLOAT); INSERT INTO zinc_production (id,machine_type,zinc_production) VALUES (5,'TypeD',1100.0),(6,'TypeA',1400.0),(7,'TypeB',1600.0),(8,'TypeD',1700.5);
|
SELECT machine_type, SUM(zinc_production) as total_production FROM zinc_production GROUP BY machine_type;
|
What is the total quantity of chemical waste generated by each manufacturer in the African region in the past year?
|
CREATE TABLE Manufacturers (ManufacturerID INT,ManufacturerName TEXT,Region TEXT); INSERT INTO Manufacturers (ManufacturerID,ManufacturerName,Region) VALUES (1,'ABC Chemicals','Africa'),(2,'XYZ Chemicals','North America'),(3,' DEF Chemicals','Africa'); CREATE TABLE WasteGeneration (WasteGenerationID INT,ManufacturerID INT,Chemical TEXT,Quantity INT,WasteGenerationDate DATE); INSERT INTO WasteGeneration (WasteGenerationID,ManufacturerID,Chemical,Quantity,WasteGenerationDate) VALUES (1,1,'Acetone',500,'2020-01-01'),(2,1,'Ethanol',700,'2020-01-10'),(3,2,'Methanol',800,'2020-02-01'),(4,3,'Propanol',900,'2020-01-01'),(5,3,'Butanol',1000,'2020-02-01');
|
SELECT M.ManufacturerName, YEAR(WG.WasteGenerationDate) AS WasteGenerationYear, SUM(WG.Quantity) AS TotalWasteQuantity FROM WasteGeneration WG INNER JOIN Manufacturers M ON WG.ManufacturerID = M.ManufacturerID WHERE M.Region = 'Africa' AND YEAR(WG.WasteGenerationDate) = YEAR(CURDATE()) - 1 GROUP BY M.ManufacturerName, WasteGenerationYear;
|
List the unique game genres and the number of VR games in each genre.
|
CREATE TABLE GameGenres (GenreID INT,GenreName TEXT,VR BOOLEAN); INSERT INTO GameGenres (GenreID,GenreName,VR) VALUES (1,'Action',FALSE),(2,'RPG',FALSE),(3,'Strategy',FALSE),(4,'Simulation',TRUE),(5,'FPS',TRUE),(6,'Sports',FALSE);
|
SELECT GenreName, COUNT(*) FROM GameGenres WHERE VR = TRUE GROUP BY GenreName;
|
What is the sum of investments in the healthcare sector?
|
CREATE TABLE strategies (id INT,sector VARCHAR(20),investment FLOAT); INSERT INTO strategies (id,sector,investment) VALUES (1,'Education',50000.0),(2,'Healthcare',75000.0),(3,'Education',100000.0);
|
SELECT SUM(investment) FROM strategies WHERE sector = 'Healthcare';
|
How many items of each type were shipped via each transportation mode?
|
CREATE TABLE shipments (id INT,order_id INT,item_type VARCHAR(50),transportation_mode VARCHAR(50),quantity INT); INSERT INTO shipments (id,order_id,item_type,transportation_mode,quantity) VALUES (1,1001,'Item1','Air',50),(2,1002,'Item2','Road',80),(3,1003,'Item1','Rail',75),(4,1004,'Item3','Sea',30);
|
SELECT item_type, transportation_mode, SUM(quantity) as total_quantity FROM shipments GROUP BY item_type, transportation_mode;
|
Find the species and their status
|
CREATE TABLE species (id INT,name VARCHAR(255),conservation_status VARCHAR(255)); INSERT INTO species (id,name,conservation_status) VALUES (1,'Blue Whale','Endangered');
|
SELECT name, CONCAT('Conservation Status: ', conservation_status) AS 'Conservation Status' FROM species;
|
List the excavation sites where the total quantity of pottery is more than 20.
|
CREATE TABLE SiteJ (site_id INT,site_name VARCHAR(20),artifact_type VARCHAR(20),quantity INT); INSERT INTO SiteJ (site_id,site_name,artifact_type,quantity) VALUES (1,'SiteJ','Pottery',25),(2,'SiteK','Bone Fragments',18),(3,'SiteL','Pottery',12),(4,'SiteM','Pottery',30);
|
SELECT site_name FROM SiteJ WHERE artifact_type = 'Pottery' GROUP BY site_name HAVING SUM(quantity) > 20;
|
What is the maximum and minimum donation amount from donors in Africa?
|
CREATE TABLE Donations (donation_id INT,donation_amount DECIMAL(10,2),donor_location VARCHAR(50)); INSERT INTO Donations (donation_id,donation_amount,donor_location) VALUES (1,10.00,'Egypt'),(2,20.00,'Nigeria'),(3,30.00,'South Africa');
|
SELECT MIN(donation_amount) AS 'Minimum Donation', MAX(donation_amount) AS 'Maximum Donation' FROM Donations WHERE donor_location LIKE 'Africa%';
|
Which fabric type has the most sustainable options?
|
CREATE TABLE Fabrics (id INT,fabric_type VARCHAR(255),sustainable BOOLEAN); INSERT INTO Fabrics (id,fabric_type,sustainable) VALUES (1,'Cotton',true),(2,'Polyester',false),(3,'Hemp',true),(4,'Rayon',false),(5,'Bamboo',true),(6,'Silk',false);
|
SELECT Fabrics.fabric_type, COUNT(Fabrics.id) AS count FROM Fabrics WHERE Fabrics.sustainable = true GROUP BY Fabrics.fabric_type ORDER BY count DESC LIMIT 1;
|
What is the total revenue for each supplier, by month?
|
CREATE TABLE purchases (purchase_date DATE,supplier VARCHAR(255),revenue DECIMAL(10,2));
|
SELECT supplier, DATE_TRUNC('month', purchase_date) AS purchase_month, SUM(revenue) AS total_revenue FROM purchases GROUP BY supplier, purchase_month;
|
How many threat intelligence records were added in January 2022 for the defense sector?
|
CREATE TABLE ThreatIntelligence (Id INT,ThreatType VARCHAR(50),Sector VARCHAR(50),Timestamp DATETIME); INSERT INTO ThreatIntelligence (Id,ThreatType,Sector,Timestamp) VALUES (1,'Cyber','Defense','2022-01-01 10:30:00'),(2,'Physical','Aerospace','2022-02-01 15:45:00');
|
SELECT COUNT(*) FROM ThreatIntelligence WHERE Sector = 'Defense' AND YEAR(Timestamp) = 2022 AND MONTH(Timestamp) = 1;
|
What is the average age of patients diagnosed with bipolar disorder in the United States?
|
CREATE TABLE diagnoses (id INT,patient_id INT,condition VARCHAR(255)); CREATE TABLE patients (id INT,age INT,country VARCHAR(255)); INSERT INTO diagnoses (id,patient_id,condition) VALUES (1,1,'Depression'),(2,2,'Anxiety'),(3,3,'Bipolar'),(4,4,'Bipolar'); INSERT INTO patients (id,age,country) VALUES (1,35,'United States'),(2,42,'Canada'),(3,28,'Mexico'),(4,31,'United States');
|
SELECT AVG(patients.age) FROM patients JOIN diagnoses ON patients.id = diagnoses.patient_id WHERE diagnoses.condition = 'Bipolar' AND patients.country = 'United States';
|
What is the name and department of all faculty members who have not published any papers?
|
CREATE TABLE faculty (faculty_id INT,name TEXT,department TEXT); INSERT INTO faculty (faculty_id,name,department) VALUES (1,'John Doe','Mathematics'),(2,'Jane Smith','Computer Science'); CREATE TABLE publications (paper_id INT,faculty_id INT,title TEXT); INSERT INTO publications (paper_id,faculty_id,title) VALUES (1,3,'Machine Learning Research'),(2,4,'Advanced Algebra');
|
SELECT faculty.name, faculty.department FROM faculty LEFT JOIN publications ON faculty.faculty_id = publications.faculty_id WHERE publications.faculty_id IS NULL;
|
What is the total number of crime incidents in the city of Miami reported in the month of July 2021?
|
CREATE TABLE crime_incidents (id INT,city VARCHAR(20),month INT,year INT,incidents INT); INSERT INTO crime_incidents (id,city,month,year,incidents) VALUES (1,'Miami',7,2021,150); INSERT INTO crime_incidents (id,city,month,year,incidents) VALUES (2,'Miami',7,2021,140);
|
SELECT SUM(incidents) FROM crime_incidents WHERE city = 'Miami' AND month = 7 AND year = 2021;
|
List the digital assets that have had the largest increase in transaction count from one day to the next.
|
CREATE TABLE transactions (asset TEXT,tx_date DATE,tx_count INT); INSERT INTO transactions (asset,tx_date,tx_count) VALUES ('Securitize','2021-01-01',100),('Securitize','2021-01-02',110),('Polymath','2021-01-01',120),('Polymath','2021-01-02',125),('Polymath','2021-01-03',130);
|
SELECT asset, (LEAD(tx_count) OVER (PARTITION BY asset ORDER BY tx_date) - tx_count) AS tx_count_diff FROM transactions ORDER BY tx_count_diff DESC;
|
Calculate the moving average of feed quantity for each farm over the last 3 days
|
CREATE TABLE Feeding (Farm_ID INT,Date DATE,Feed_Quantity INT); INSERT INTO Feeding (Farm_ID,Date,Feed_Quantity) VALUES (1,'2022-01-01',5000),(1,'2022-01-02',5500),(1,'2022-01-03',6000),(1,'2022-01-04',6500),(1,'2022-01-05',7000);
|
SELECT Farm_ID, Date, Feed_Quantity, AVG(Feed_Quantity) OVER(PARTITION BY Farm_ID ORDER BY Date ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS Moving_Avg FROM Feeding WHERE Farm_ID = 1;
|
List the marine species and their maximum depths found in the Mariana Trench.
|
CREATE TABLE oceans (ocean_id INT,name VARCHAR(50)); CREATE TABLE species (species_id INT,name VARCHAR(50),ocean_id INT,max_depth DECIMAL(5,2)); INSERT INTO oceans VALUES (1,'Atlantic'),(2,'Pacific'),(3,'Indian'); INSERT INTO species VALUES (1,'Clownfish',2,10),(2,'Salmon',1,100),(3,'Clownfish',3,15),(4,'Dolphin',1,200),(5,'Turtle',3,30),(6,'Shark',2,250),(7,'Shark',1,300),(8,'Squid',3,40),(9,'Giant Squid',2,1000),(10,'Anglerfish',2,1500),(11,'Mariana Snailfish',2,8178);
|
SELECT s.name, s.max_depth FROM species s WHERE s.name = 'Mariana Snailfish';
|
What are the names of students who are not in the Computer Science department?
|
CREATE TABLE Students (StudentID INT,FirstName VARCHAR(50),LastName VARCHAR(50),Department VARCHAR(50)); INSERT INTO Students (StudentID,FirstName,LastName,Department) VALUES (1,'John','Doe','Computer Science'); INSERT INTO Students (StudentID,FirstName,LastName,Department) VALUES (2,'Jane','Doe','Mathematics'); INSERT INTO Students (StudentID,FirstName,LastName,Department) VALUES (3,'Mohamed','Ali','Engineering'); INSERT INTO Students (StudentID,FirstName,LastName,Department) VALUES (4,'Nia','Smith','Computer Science');
|
SELECT FirstName, LastName FROM Students WHERE Department != 'Computer Science';
|
What are the top 3 countries with the highest average game spend per player in the "VirtualRealityGames" genre?
|
CREATE TABLE Games (GameID INT,GameName VARCHAR(255),Genre VARCHAR(255));CREATE TABLE Players (PlayerID INT,PlayerName VARCHAR(255),GameID INT,Spend DECIMAL(10,2));
|
SELECT g.Genre, c.Country, AVG(p.Spend) as AvgSpend FROM Games g JOIN Players p ON g.GameID = p.GameID JOIN (SELECT PlayerID, Country FROM PlayerProfile GROUP BY PlayerID) c ON p.PlayerID = c.PlayerID WHERE g.Genre = 'VirtualRealityGames' GROUP BY g.Genre, c.Country ORDER BY AvgSpend DESC LIMIT 3;
|
Which city had the lowest recycling rate in 2022?
|
CREATE TABLE recycling_rates (city TEXT,year INT,recycling_rate DECIMAL(5,4)); INSERT INTO recycling_rates (city,year,recycling_rate) VALUES ('Accra',2022,0.25),('Cape Town',2022,0.35),('Johannesburg',2022,0.45);
|
SELECT city, MIN(recycling_rate) FROM recycling_rates WHERE year = 2022 GROUP BY city;
|
What is the maximum cost of a device for accessibility in North America?
|
CREATE TABLE device_cost_north_america (country VARCHAR(20),device VARCHAR(20),cost FLOAT); INSERT INTO device_cost_north_america (country,device,cost) VALUES ('Canada','Screen Reader',130.00),('USA','Adaptive Keyboard',90.00),('Mexico','Speech Recognition Software',110.00);
|
SELECT MAX(cost) FROM device_cost_north_america WHERE country = 'North America';
|
Update the funding for 'Genetech' to 2500000.
|
CREATE TABLE startups (id INT,name VARCHAR(50),sector VARCHAR(50),funding FLOAT); INSERT INTO startups (id,name,sector,funding) VALUES (1,'Genetech','genetic research',2000000),(2,'BioVentures','bioprocess engineering',1500000);
|
UPDATE startups SET funding = 2500000 WHERE name = 'Genetech';
|
Delete all records in the materials table where the material_type is 'concrete'
|
CREATE TABLE materials (id INT PRIMARY KEY,material_name VARCHAR(255),material_type VARCHAR(255)); INSERT INTO materials (id,material_name,material_type) VALUES (1,'Rebar','steel'); INSERT INTO materials (id,material_name,material_type) VALUES (2,'Concrete Block','concrete');
|
DELETE FROM materials WHERE material_type = 'concrete';
|
List the 'property_id' and 'building_type' of buildings in the 'affordable_housing' table.
|
CREATE TABLE affordable_housing (property_id INT,building_type VARCHAR(255),PRIMARY KEY (property_id)); INSERT INTO affordable_housing (property_id,building_type) VALUES (1,'Apartment'),(2,'Townhouse'),(3,'Single-family');
|
SELECT property_id, building_type FROM affordable_housing;
|
What is the total fare collected for route 204 and 205?
|
CREATE TABLE fares (id INT,route_id INT,fare FLOAT,distance FLOAT); INSERT INTO fares (id,route_id,fare,distance) VALUES (4001,204,5.0,50.0),(4002,205,6.0,60.0);
|
SELECT route_id, SUM(fare) as total_fare FROM fares GROUP BY route_id HAVING route_id IN (204, 205);
|
Delete the 'Teen' size from the 'Size' table
|
CREATE TABLE Size (id INT PRIMARY KEY,name VARCHAR(50),average_spending DECIMAL(5,2));
|
DELETE FROM Size WHERE name = 'Teen';
|
Find the well with the highest gas production in the Marcellus shale
|
CREATE TABLE if not exists shale_gas_production (well_id INT,well_name TEXT,location TEXT,gas_production FLOAT); INSERT INTO shale_gas_production (well_id,well_name,location,gas_production) VALUES (1,'Well F','Marcellus',12345.67),(2,'Well G','Marcellus',23456.78),(3,'Well H','Utica',34567.89);
|
SELECT well_name, gas_production FROM shale_gas_production WHERE location = 'Marcellus' ORDER BY gas_production DESC LIMIT 1;
|
What is the average number of humanitarian assistance missions conducted per quarter in 2019?
|
CREATE TABLE HumanitarianAssistanceByQuarter (Quarter VARCHAR(10),Missions INT); INSERT INTO HumanitarianAssistanceByQuarter (Quarter,Missions) VALUES ('Q1 2019',10),('Q2 2019',12),('Q3 2019',15),('Q4 2019',18);
|
SELECT AVG(Missions) FROM HumanitarianAssistanceByQuarter WHERE YEAR(Quarter) = 2019;
|
List the top 2 countries with the highest number of UNESCO World Heritage Sites.
|
CREATE TABLE countries (id INT,name VARCHAR(255),unesco_sites INT); INSERT INTO countries (id,name,unesco_sites) VALUES (1,'Italy',55),(2,'China',54),(3,'Spain',49);
|
SELECT name, RANK() OVER (ORDER BY unesco_sites DESC) as site_rank FROM countries WHERE unesco_sites IS NOT NULL QUALIFY site_rank <= 2;
|
Which programs funded by private donors had over 50% attendance?
|
CREATE TABLE Programs (ProgramID int,ProgramName varchar(50),FundingSource varchar(50),Attendance int); INSERT INTO Programs VALUES (1,'Art Education','Private Donor',80),(2,'Theater Workshop','Government Grant',60),(3,'Music Camp','Local Sponsor',40);
|
SELECT ProgramName FROM Programs WHERE FundingSource = 'Private Donor' AND Attendance > (SELECT 0.5 * SUM(Attendance) FROM Programs WHERE FundingSource = 'Private Donor');
|
What is the maximum number of followers for users who have posted about veganism in the last year?
|
CREATE TABLE users (id INT,followers INT); CREATE TABLE posts (id INT,user_id INT,content TEXT,created_at DATETIME);
|
SELECT MAX(users.followers) FROM users INNER JOIN posts ON users.id = posts.user_id WHERE posts.content LIKE '%veganism%' AND posts.created_at >= DATE_SUB(NOW(), INTERVAL 1 YEAR);
|
Calculate the success rate of clinical trials for drugs approved between 2017 and 2020.
|
CREATE TABLE clinical_trials (drug_name TEXT,approval_year INTEGER,success BOOLEAN); INSERT INTO clinical_trials (drug_name,approval_year,success) VALUES ('DrugP',2018,true),('DrugP',2019,true),('DrugQ',2020,false),('DrugR',2017,true),('DrugR',2018,true),('DrugS',2019,false);
|
SELECT AVG(success) as avg_success_rate FROM (SELECT approval_year, success, COUNT(*) as trials_count FROM clinical_trials WHERE approval_year BETWEEN 2017 AND 2020 GROUP BY approval_year, success) subquery WHERE trials_count > 1;
|
How many product recalls were issued for brands in the USA in the last 12 months?
|
CREATE TABLE brands (brand_id INT,brand_name TEXT,country TEXT); CREATE TABLE product_recalls (recall_id INT,brand_id INT,recall_date DATE); INSERT INTO brands (brand_id,brand_name,country) VALUES (1,'Brand X','USA'),(2,'Brand Y','USA'),(3,'Brand Z','Canada'); INSERT INTO product_recalls (recall_id,brand_id,recall_date) VALUES (1,1,'2022-01-01'),(2,2,'2022-02-01'),(3,1,'2021-12-01');
|
SELECT brand_name, COUNT(*) as recalls_in_last_12_months FROM brands JOIN product_recalls ON brands.brand_id = product_recalls.brand_id WHERE country = 'USA' AND recall_date > DATEADD(month, -12, CURRENT_DATE) GROUP BY brand_name;
|
List all attorneys who have never lost a case, along with their demographic information.
|
CREATE TABLE Attorneys (AttorneyID INT,Age INT,Gender VARCHAR(10),Income FLOAT); CREATE TABLE Cases (CaseID INT,AttorneyID INT,CaseStatus VARCHAR(10));
|
SELECT A.AttorneyID, A.Age, A.Gender, A.Income FROM Attorneys A WHERE NOT EXISTS (SELECT 1 FROM Cases C WHERE A.AttorneyID = C.AttorneyID AND C.CaseStatus = 'Lost');
|
What is the total amount of organic waste generated in the world, and how does that compare to the amount of organic waste generated in Europe?
|
CREATE TABLE OrganicWaste (Region VARCHAR(50),WasteQuantity INT); INSERT INTO OrganicWaste (Region,WasteQuantity) VALUES ('World',100000000),('Europe',10000000),('North America',30000000),('Asia',40000000);
|
SELECT Region, WasteQuantity FROM OrganicWaste WHERE Region IN ('World', 'Europe');
|
What is the percentage of organic ingredients used in each product?
|
CREATE TABLE Products (Product_ID INT PRIMARY KEY,Product_Name TEXT); CREATE TABLE Ingredients (Product_ID INT,Ingredient_Name TEXT,Organic BOOLEAN,Weight FLOAT); INSERT INTO Products (Product_ID,Product_Name) VALUES (1,'Facial Cleanser'),(2,'Moisturizing Cream'),(3,'Exfoliating Scrub'); INSERT INTO Ingredients (Product_ID,Ingredient_Name,Organic,Weight) VALUES (1,'Aloe Vera',TRUE,25.0),(1,'Chamomile',FALSE,10.0),(2,'Rosehip',TRUE,15.0),(2,'Lavender',TRUE,20.0),(3,'Jojoba',TRUE,12.0),(3,'Argan',FALSE,18.0);
|
SELECT p.Product_Name, (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM Ingredients i WHERE i.Product_ID = p.Product_ID)) AS Percentage_Organic FROM Ingredients i JOIN Products p ON i.Product_ID = p.Product_ID WHERE i.Organic = TRUE GROUP BY p.Product_ID;
|
What is the most common mental health condition in Canada's youth population?
|
CREATE TABLE conditions (id INT,patient_id INT,condition VARCHAR(255)); CREATE TABLE patients (id INT,age INT,country VARCHAR(255)); INSERT INTO conditions (id,patient_id,condition) VALUES (1,1,'depression'),(2,2,'anxiety'),(3,3,'bipolar'),(4,4,'schizophrenia'); INSERT INTO patients (id,age,country) VALUES (1,15,'Canada'),(2,22,'Canada'),(3,30,'Canada'),(4,45,'Canada');
|
SELECT conditions.condition, COUNT(conditions.condition) AS count FROM conditions JOIN patients ON conditions.patient_id = patients.id WHERE patients.country = 'Canada' AND patients.age < 18 GROUP BY conditions.condition ORDER BY count DESC LIMIT 1;
|
Which country has the highest CO2 emissions in textile industry?
|
CREATE TABLE textile_emissions (id INT,country VARCHAR(50),co2_emissions INT); INSERT INTO textile_emissions (id,country,co2_emissions) VALUES (1,'Bangladesh',5000),(2,'China',15000),(3,'India',10000),(4,'USA',8000);
|
SELECT country, MAX(co2_emissions) as max_emissions FROM textile_emissions GROUP BY country;
|
What is the total transaction amount for each smart contract address?
|
CREATE TABLE Smart_Contracts (Contract_Address VARCHAR(100),Transaction_Date DATE,Transaction_Amount FLOAT); INSERT INTO Smart_Contracts (Contract_Address,Transaction_Date,Transaction_Amount) VALUES ('0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D','2022-01-03',600); INSERT INTO Smart_Contracts (Contract_Address,Transaction_Date,Transaction_Amount) VALUES ('0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D','2022-01-04',400); INSERT INTO Smart_Contracts (Contract_Address,Transaction_Date,Transaction_Amount) VALUES ('0x9c103d361B0454278666f37c937BED57300b4662','2022-01-04',350);
|
SELECT Contract_Address, SUM(Transaction_Amount) FROM Smart_Contracts GROUP BY Contract_Address
|
Calculate the total revenue for all games released in 2021
|
CREATE TABLE games (id INT,name VARCHAR(100),release_date DATE,revenue INT); INSERT INTO games (id,name,release_date,revenue) VALUES (1,'Apex Legends','2019-02-04',5000000); INSERT INTO games (id,name,release_date,revenue) VALUES (2,'Fortnite','2017-07-21',10000000);
|
SELECT SUM(revenue) FROM games WHERE EXTRACT(YEAR FROM release_date) = 2021;
|
Which countries have 'High' severity vulnerabilities and the number of such vulnerabilities? Provide the output in the format: country, count_of_high_severity_vulnerabilities.
|
CREATE TABLE country_severity (id INT,ip_address VARCHAR(255),country VARCHAR(255),severity VARCHAR(255)); INSERT INTO country_severity (id,ip_address,country,severity) VALUES (1,'192.168.1.1','US','High'),(2,'10.0.0.1','Canada','Low'),(3,'192.168.1.2','Mexico','High'),(4,'10.0.0.2','Canada','Medium'),(5,'10.0.0.3','Canada','High'),(6,'10.0.0.4','Canada','Low');
|
SELECT country, COUNT(*) as count_of_high_severity_vulnerabilities FROM country_severity WHERE severity = 'High' GROUP BY country;
|
How many healthcare complaints were received from rural areas in Q1 2022?
|
CREATE TABLE complaint (id INT,category VARCHAR(50),district_id INT,date DATE); INSERT INTO complaint (id,category,district_id,date) VALUES (1,'healthcare',1,'2022-01-01'),(2,'education',2,'2022-01-15'),(3,'healthcare',3,'2022-03-01'),(4,'education',1,'2022-04-01');
|
SELECT COUNT(*) FROM complaint WHERE category = 'healthcare' AND district_id IN (SELECT id FROM district WHERE type = 'rural') AND date BETWEEN '2022-01-01' AND '2022-03-31';
|
Who are the top 3 donors by total donation amount in 'donations' table?
|
CREATE TABLE donors (id INT,name TEXT,total_donations DECIMAL(10,2)); CREATE TABLE donations (id INT,donor_id INT,amount DECIMAL(10,2),donation_date DATE); INSERT INTO donors (id,name,total_donations) VALUES (1,'John Doe',500.00),(2,'Jane Smith',300.00),(3,'Bob Johnson',700.00); INSERT INTO donations (id,donor_id,amount,donation_date) VALUES (1,1,100.00,'2022-01-01'),(2,1,200.00,'2022-01-02'),(3,2,300.00,'2022-01-01'),(4,3,400.00,'2022-01-01'),(5,3,300.00,'2022-01-02');
|
SELECT donor_id, SUM(amount) as total_donations FROM donations GROUP BY donor_id ORDER BY total_donations DESC LIMIT 3;
|
What is the total revenue for the 'Burger' category?
|
CREATE TABLE restaurant_revenue (item_category VARCHAR(20),daily_revenue DECIMAL(10,2)); INSERT INTO restaurant_revenue (item_category,daily_revenue) VALUES ('Burger',1500.00),('Pizza',1200.00),('Salad',800.00);
|
SELECT SUM(daily_revenue) FROM restaurant_revenue WHERE item_category = 'Burger';
|
What is the average entry fee for exhibitions in Seoul with more than 50 visitors?
|
CREATE TABLE Exhibitions (exhibition_id INT,location VARCHAR(20),entry_fee INT); INSERT INTO Exhibitions (exhibition_id,location,entry_fee) VALUES (1,'Seoul',12),(2,'Seoul',8),(3,'Seoul',25); CREATE TABLE Visitors (visitor_id INT,exhibition_id INT); INSERT INTO Visitors (visitor_id,exhibition_id) VALUES (1,1),(2,1),(3,1),(4,2),(5,3),(6,3),(7,3),(8,3),(9,3);
|
SELECT AVG(entry_fee) FROM Exhibitions WHERE location = 'Seoul' GROUP BY location HAVING COUNT(DISTINCT visitor_id) > 50;
|
What is the average altitude of all space missions launched by a specific country, according to the Space_Missions table?
|
CREATE TABLE Space_Missions (ID INT,Mission_Name VARCHAR(255),Country VARCHAR(255),Avg_Altitude FLOAT); INSERT INTO Space_Missions (ID,Mission_Name,Country,Avg_Altitude) VALUES (1,'Apollo 11','USA',363300);
|
SELECT Country, AVG(Avg_Altitude) FROM Space_Missions GROUP BY Country;
|
What is the total number of patients who have received group therapy in New York?
|
CREATE TABLE therapy_sessions (patient_id INT,session_type VARCHAR(50)); INSERT INTO therapy_sessions (patient_id,session_type) VALUES (1,'Individual Therapy'),(2,'Group Therapy'),(3,'CBT'),(4,'Group Therapy'),(5,'Individual Therapy'); CREATE TABLE patient_location (patient_id INT,location VARCHAR(50)); INSERT INTO patient_location (patient_id,location) VALUES (1,'California'),(2,'New York'),(3,'Texas'),(4,'New York'),(5,'New York');
|
SELECT COUNT(DISTINCT patient_id) FROM therapy_sessions JOIN patient_location ON therapy_sessions.patient_id = patient_location.patient_id WHERE session_type = 'Group Therapy';
|
Which menu items have experienced a decrease in sales in the past month compared to the same month last year?
|
CREATE TABLE Sales (sale_id INT PRIMARY KEY,menu_item VARCHAR(50),sale_quantity INT,sale_date DATE); CREATE TABLE Menu (menu_item VARCHAR(50) PRIMARY KEY,menu_item_category VARCHAR(50));
|
SELECT s1.menu_item, s1.sale_quantity - s2.sale_quantity AS sales_delta FROM Sales s1 JOIN Sales s2 ON s1.menu_item = s2.menu_item WHERE s1.sale_date >= DATEADD(month, -1, GETDATE()) AND s2.sale_date >= DATEADD(month, -13, GETDATE());
|
What is the average amount of donations received per month in the 'refugee support' sector?
|
CREATE TABLE donations (id INT,sector TEXT,month INT,year INT,amount FLOAT); INSERT INTO donations (id,sector,month,year,amount) VALUES (1,'refugee support',1,2020,5000.00); INSERT INTO donations (id,sector,month,year,amount) VALUES (2,'refugee support',2,2020,6000.00); INSERT INTO donations (id,sector,month,year,amount) VALUES (3,'community development',1,2020,7000.00);
|
SELECT AVG(amount) FROM donations WHERE sector = 'refugee support' GROUP BY year, month;
|
What is the total investment in sustainable agriculture by gender in 2021?
|
CREATE TABLE investor_demographics (investor_id INT,investor_name VARCHAR(255),investment_amount INT,investment_year INT,sector VARCHAR(255),gender VARCHAR(10)); INSERT INTO investor_demographics (investor_id,investor_name,investment_amount,investment_year,sector,gender) VALUES (1,'EcoGrowth',120000,2021,'Sustainable Agriculture','Female'),(2,'GreenHarvest',180000,2021,'Sustainable Agriculture','Male'),(3,'SustainableFields',90000,2021,'Sustainable Agriculture','Non-binary');
|
SELECT gender, SUM(investment_amount) as total_investment FROM investor_demographics WHERE investment_year = 2021 AND sector = 'Sustainable Agriculture' GROUP BY gender;
|
What is the average time taken to patch high-severity vulnerabilities in the last quarter?
|
CREATE TABLE vulnerabilities (vulnerability_id INT,severity VARCHAR(255),last_updated TIMESTAMP,patch_time INT); INSERT INTO vulnerabilities (vulnerability_id,severity,last_updated,patch_time) VALUES (1,'High','2022-01-01 10:00:00',3),(2,'High','2022-02-01 15:30:00',5),(3,'High','2022-03-01 08:15:00',7);
|
SELECT AVG(patch_time) as avg_patch_time FROM vulnerabilities WHERE severity = 'High' AND last_updated >= DATEADD(quarter, -1, CURRENT_TIMESTAMP);
|
What's the average age of patients diagnosed with anxiety disorder?
|
CREATE TABLE patients (patient_id INT,name VARCHAR(50),age INT,gender VARCHAR(10),condition VARCHAR(50)); INSERT INTO patients (patient_id,name,age,gender,condition) VALUES (1,'John Doe',30,'Male','Anxiety Disorder'); INSERT INTO patients (patient_id,name,age,gender,condition) VALUES (2,'Jane Smith',35,'Female','Depression');
|
SELECT AVG(age) FROM patients WHERE condition = 'Anxiety Disorder';
|
What is the percentage change in Union membership from 2020 to 2021 for each union?
|
CREATE TABLE union_membership (id INT,union_name VARCHAR(255),year INT,membership INT); INSERT INTO union_membership (id,union_name,year,membership) VALUES (1,'Union A',2020,5000),(2,'Union A',2021,5500),(3,'Union B',2020,6000),(4,'Union B',2021,6200),(5,'Union C',2020,4000),(6,'Union C',2021,4100);
|
SELECT u.union_name, ((m2.membership - m1.membership) * 100.0 / m1.membership) as pct_change FROM union_membership m1 JOIN union_membership m2 ON m1.union_name = m2.union_name AND m1.year = 2020 AND m2.year = 2021;
|
What is the average ticket price for all musicals in the United States?
|
CREATE TABLE musicals (title VARCHAR(255),location VARCHAR(255),price DECIMAL(5,2)); INSERT INTO musicals (title,location,price) VALUES ('Phantom of the Opera','New York',125.99),('Lion King','New York',149.99),('Hamilton','Chicago',200.00),('Wicked','Los Angeles',150.00);
|
SELECT AVG(price) FROM musicals WHERE location IN ('New York', 'Chicago', 'Los Angeles');
|
How many deep-sea expeditions have been conducted in the Southern Ocean since 2010?
|
CREATE TABLE deep_sea_expeditions (id INT,expedition_name VARCHAR(255),year INT,region VARCHAR(255)); INSERT INTO deep_sea_expeditions (id,expedition_name,year,region) VALUES (1,'Expedition A',2015,'Southern Ocean'); INSERT INTO deep_sea_expeditions (id,expedition_name,year,region) VALUES (2,'Expedition B',2012,'Southern Ocean');
|
SELECT COUNT(*) FROM deep_sea_expeditions WHERE region = 'Southern Ocean' AND year >= 2010;
|
What is the maximum network infrastructure investment in Australia for the last 3 years?
|
CREATE TABLE investment_data (year INT,country VARCHAR(15),investment FLOAT); INSERT INTO investment_data (year,country,investment) VALUES (2019,'Australia',2500000),(2020,'Australia',3000000),(2021,'Australia',3500000);
|
SELECT MAX(investment) as max_investment FROM investment_data WHERE country = 'Australia' AND year BETWEEN 2019 AND 2021;
|
How many users from the United States have played the virtual reality game "Cybernetic Realms" in the last month?
|
CREATE TABLE users (id INT,country VARCHAR(50),game VARCHAR(50),last_played DATETIME); INSERT INTO users VALUES (1,'United States','Cybernetic Realms','2022-02-03 16:20:00'); INSERT INTO users VALUES (2,'Canada','Cybernetic Realms','2022-02-10 09:35:00');
|
SELECT COUNT(*) FROM users WHERE country = 'United States' AND game = 'Cybernetic Realms' AND last_played >= DATE_SUB(NOW(), INTERVAL 1 MONTH);
|
Show the swimming pools with a length of 50 meters
|
CREATE TABLE swimming_pools (id INT,name VARCHAR(50),location VARCHAR(50),length INT);
|
SELECT name FROM swimming_pools WHERE length = 50;
|
List the total quantity of each fabric type used in garment manufacturing in France.
|
CREATE TABLE fabrics (id INT,name TEXT); INSERT INTO fabrics (id,name) VALUES (1,'Cotton'),(2,'Polyester'),(3,'Wool'); CREATE TABLE garments (id INT,name TEXT,fabric_id INT,quantity INT); INSERT INTO garments (id,name,fabric_id,quantity) VALUES (1,'Shirt',1,50),(2,'Pants',2,75),(3,'Jacket',3,30); CREATE TABLE manufacturers (id INT,name TEXT,country TEXT); INSERT INTO manufacturers (id,name,country) VALUES (1,'ManufacturerA','France'); CREATE TABLE garment_manufacturers (garment_id INT,manufacturer_id INT); INSERT INTO garment_manufacturers (garment_id,manufacturer_id) VALUES (1,1),(2,1),(3,1);
|
SELECT f.name, SUM(g.quantity) FROM fabrics f JOIN garments g ON f.id = g.fabric_id JOIN garment_manufacturers gm ON g.id = gm.garment_id JOIN manufacturers m ON gm.manufacturer_id = m.id WHERE m.country = 'France' GROUP BY f.name;
|
How many citizen feedback records are there for 'ServiceA' in 'RegionA'?
|
CREATE TABLE Feedback(service VARCHAR(20),region VARCHAR(20),feedback_id INT); INSERT INTO Feedback VALUES ('ServiceA','RegionC',1001),('ServiceA','RegionC',1002),('ServiceB','RegionD',2001),('ServiceB','RegionD',2002),('ServiceA','RegionA',1501),('ServiceA','RegionA',1502);
|
SELECT COUNT(*) FROM Feedback WHERE service = 'ServiceA' AND region = 'RegionA';
|
What is the total number of goals scored by each hockey team in the 2022 season?
|
CREATE TABLE hockey_teams (team_id INT,team_name VARCHAR(50),goals INT); INSERT INTO hockey_teams (team_id,team_name,goals) VALUES (1,'Montreal Canadiens',187),(2,'Toronto Maple Leafs',201),(3,'Vancouver Canucks',178);
|
SELECT team_name, SUM(goals) as total_goals FROM hockey_teams GROUP BY team_name;
|
Find total revenue for each advertiser, per quarter
|
CREATE TABLE advertisers (id INT PRIMARY KEY,name TEXT NOT NULL); CREATE TABLE ad_revenue (advertiser_id INT,revenue DECIMAL(10,2),date DATE);
|
SELECT advertisers.name, CONCAT(QUARTER(ad_revenue.date), '/', YEAR(ad_revenue.date)) as quarter, SUM(ad_revenue.revenue) as total_revenue FROM advertisers INNER JOIN ad_revenue ON advertisers.id = ad_revenue.advertiser_id GROUP BY advertisers.name, quarter;
|
What is the average productivity of workers in each department for the year 2020?
|
CREATE TABLE productivity(id INT,worker TEXT,department TEXT,year INT,productivity FLOAT);INSERT INTO productivity(id,worker,department,year,productivity) VALUES (1,'John','mining',2020,12.5),(2,'Jane','mining',2020,13.7),(3,'Mike','mining',2020,11.8),(4,'Lucy','geology',2020,15.1),(5,'Ella','geology',2020,14.5);
|
SELECT department, AVG(productivity) FROM productivity WHERE year = 2020 GROUP BY department;
|
What is the average depth of all deep-sea exploration sites?
|
CREATE TABLE deep_sea_exploration (site_id INT,name VARCHAR(255),depth FLOAT); INSERT INTO deep_sea_exploration (site_id,name,depth) VALUES (1,'Atlantis',5000.0),(2,'Challenger Deep',10994.0),(3,'Sirena Deep',8098.0);
|
SELECT AVG(depth) FROM deep_sea_exploration;
|
What is the total funding for bioprocess engineering projects in the UK?
|
CREATE TABLE bioprocess_projects (id INT,project_name VARCHAR(50),location VARCHAR(50),funding_amount INT); INSERT INTO bioprocess_projects (id,project_name,location,funding_amount) VALUES (1,'Project G','UK',12000000); INSERT INTO bioprocess_projects (id,project_name,location,funding_amount) VALUES (2,'Project H','USA',10000000);
|
SELECT SUM(funding_amount) FROM bioprocess_projects WHERE location = 'UK' AND technology = 'Bioprocess Engineering';
|
What is the total funding received by biotech startups in Indonesia, Thailand, and Malaysia?
|
CREATE SCHEMA if not exists biotech; CREATE TABLE if not exists biotech.startups (id INT,name VARCHAR(50),location VARCHAR(50),funding DECIMAL(10,2)); INSERT INTO biotech.startups (id,name,location,funding) VALUES (1,'BioGen','Indonesia',3000000.00),(2,'Cell Therapy Asia','Thailand',5000000.00),(3,'Bio Sensor','Malaysia',7000000.00);
|
SELECT SUM(funding) FROM biotech.startups WHERE location IN ('Indonesia', 'Thailand', 'Malaysia');
|
What is the total number of electric vehicles in 'vehicle_ownership' table for each city?
|
CREATE TABLE vehicle_ownership (id INT,city VARCHAR(25),vehicle_type VARCHAR(20),ownership INT);
|
SELECT city, SUM(ownership) FROM vehicle_ownership WHERE vehicle_type = 'Electric Vehicle' GROUP BY city;
|
What is the average gross tonnage of container vessels per country?
|
CREATE TABLE Port (PortID INT,PortName VARCHAR(50),City VARCHAR(50),Country VARCHAR(50)); INSERT INTO Port (PortID,PortName,City,Country) VALUES (1,'Port of Los Angeles','Los Angeles','USA'); INSERT INTO Port (PortID,PortName,City,Country) VALUES (2,'Port of Rotterdam','Rotterdam','Netherlands'); CREATE TABLE Vessel (VesselID INT,VesselName VARCHAR(50),GrossTonnage INT,VesselType VARCHAR(50),PortID INT); INSERT INTO Vessel (VesselID,VesselName,GrossTonnage,VesselType,PortID) VALUES (1,'Ever Ace',235000,'Container',1); INSERT INTO Vessel (VesselID,VesselName,GrossTonnage,VesselType,PortID) VALUES (2,'Algeciras',128000,'Ro-Ro',2);
|
SELECT p.Country, AVG(v.GrossTonnage) AS AvgGrossTonnage FROM Vessel v JOIN Port p ON v.PortID = p.PortID WHERE VesselType = 'Container' GROUP BY p.Country;
|
Update the "offenses" table to reflect a new offense type
|
CREATE TABLE offenses (id INT,victim_id INT,offense_type VARCHAR(50),date_of_offense DATE);
|
UPDATE offenses SET offense_type = 'Cyberstalking' WHERE id = 2001;
|
What is the number of days with temperature above 30 degrees in Field11 and Field12 in the month of August?
|
CREATE TABLE Field11 (date DATE,temperature FLOAT); INSERT INTO Field11 VALUES ('2021-08-01',31),('2021-08-02',28); CREATE TABLE Field12 (date DATE,temperature FLOAT); INSERT INTO Field12 VALUES ('2021-08-01',33),('2021-08-02',29);
|
SELECT COUNT(*) as days_above_30 FROM (SELECT f11.date FROM Field11 f11 WHERE f11.temperature > 30 UNION ALL SELECT f12.date FROM Field12 f12 WHERE f12.temperature > 30) as days_above_30;
|
What are the unique professional development courses taken by teachers in 'Spring 2021' and 'Fall 2021'?
|
CREATE TABLE teacher_development (teacher_id INT,teacher_name VARCHAR(50),course_title VARCHAR(100),course_date DATE); INSERT INTO teacher_development (teacher_id,teacher_name,course_title,course_date) VALUES (1,'John Doe','Python Programming','2021-04-01'),(2,'Jane Smith','Data Analysis with SQL','2021-05-01'),(3,'John Doe','Machine Learning Fundamentals','2021-06-01'),(4,'Alice Johnson','Data Analysis with SQL','2021-09-01'),(5,'Bob Brown','Machine Learning Fundamentals','2021-10-01');
|
SELECT DISTINCT course_title FROM teacher_development WHERE course_date BETWEEN '2021-04-01' AND '2021-12-31' ORDER BY course_title;
|
Which cultural heritage sites in Japan have more than 3 virtual tours?
|
CREATE TABLE cultural_sites (site_id INT,site_name TEXT,country TEXT,num_virtual_tours INT); INSERT INTO cultural_sites (site_id,site_name,country,num_virtual_tours) VALUES (1,'Temple A','Japan',2),(2,'Shrine B','Japan',5);
|
SELECT site_name, country FROM cultural_sites WHERE country = 'Japan' AND num_virtual_tours > 3;
|
What is the total number of games released by a specific developer?
|
CREATE TABLE game_developers (id INT,game VARCHAR(20),developer VARCHAR(20)); INSERT INTO game_developers (id,game,developer) VALUES (1,'Game1','Dev1'),(2,'Game2','Dev2'),(3,'Game3','Dev1');
|
SELECT developer, COUNT(DISTINCT game) as count FROM game_developers GROUP BY developer;
|
List all marine accidents in the Indian Ocean after 2015.
|
CREATE TABLE marine_accidents (year INT,location VARCHAR); INSERT INTO marine_accidents (year,location) VALUES (2016,'Indian Ocean'),(2017,'Indian Ocean'),(2018,'Indian Ocean');
|
SELECT * FROM marine_accidents WHERE location = 'Indian Ocean' AND year > 2015;
|
List the number of AI safety incidents per country, sorted by the number of incidents in descending order.
|
CREATE TABLE AISafetyIncidents (IncidentID INT PRIMARY KEY,IncidentType VARCHAR(20),Country VARCHAR(20)); INSERT INTO AISafetyIncidents (IncidentID,IncidentType,Country) VALUES (1,'Data Leakage','USA'),(2,'Unexpected Behavior','Canada'),(3,'System Failure','Mexico');
|
SELECT Country, COUNT(*) AS IncidentCount FROM AISafetyIncidents GROUP BY Country ORDER BY IncidentCount DESC;
|
What is the average concert ticket price for Hip-Hop artists?
|
CREATE TABLE Concerts (ConcertID INT,ArtistID INT,Venue VARCHAR(100),Date DATE);
|
SELECT AVG(T.Price) AS AvgPrice FROM Artists A INNER JOIN Concerts C ON A.ArtistID = C.ArtistID INNER JOIN Tickets T ON C.ConcertID = T.ConcertID WHERE A.Genre = 'Hip-Hop';
|
How many food safety records were deleted in each month of 2022?
|
CREATE TABLE FoodSafetyRecords (RecordID INT,DeleteDate DATE); INSERT INTO FoodSafetyRecords (RecordID,DeleteDate) VALUES (1,'2022-01-01'),(2,'2022-01-05'),(3,'2022-02-10'),(4,'2022-03-20'),(5,'2022-03-30');
|
SELECT EXTRACT(MONTH FROM DeleteDate) AS Month, COUNT(*) FROM FoodSafetyRecords WHERE DeleteDate BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY EXTRACT(MONTH FROM DeleteDate);
|
Calculate the average price of sustainable urbanism projects in Los Angeles with at least 2 co-owners.
|
CREATE TABLE sustainable_urbanism (property_id INT,city VARCHAR(50),price INT,co_owner_count INT); INSERT INTO sustainable_urbanism (property_id,city,price,co_owner_count) VALUES (1,'Los Angeles',900000,2),(2,'Portland',400000,1),(3,'Los Angeles',1000000,3),(4,'Seattle',700000,1);
|
SELECT AVG(price) FROM sustainable_urbanism WHERE city = 'Los Angeles' AND co_owner_count > 1;
|
What is the total number of public parks in the state of New York that were established after the year 2010?
|
CREATE TABLE public_parks (name VARCHAR(255),state VARCHAR(255),established_year INT); INSERT INTO public_parks (name,state,established_year) VALUES ('Central Park','NY',1857); INSERT INTO public_parks (name,state,established_year) VALUES ('Prospect Park','NY',1867);
|
SELECT COUNT(*) FROM public_parks WHERE state = 'NY' AND established_year > 2010;
|
What is the total capacity of renewable energy sources in New York?
|
CREATE TABLE renewable_energy (id INT PRIMARY KEY,source VARCHAR(255),capacity FLOAT,location VARCHAR(255)); INSERT INTO renewable_energy (id,source,capacity,location) VALUES (1,'Solar',50.0,'California'); INSERT INTO renewable_energy (id,source,capacity,location) VALUES (2,'Wind',100.0,'Texas'); INSERT INTO renewable_energy (id,source,capacity,location) VALUES (3,'Hydro',150.0,'New York');
|
SELECT source, SUM(capacity) FROM renewable_energy WHERE location = 'New York' GROUP BY source;
|
What is the total quantity of "organic apples" sold by each store?
|
CREATE TABLE Stores (store_id INT,store_name VARCHAR(255)); INSERT INTO Stores (store_id,store_name) VALUES (1,'Store A'),(2,'Store B'),(3,'Store C'); CREATE TABLE Products (product_id INT,product_name VARCHAR(255),is_organic BOOLEAN); INSERT INTO Products (product_id,product_name,is_organic) VALUES (1,'Apples',FALSE),(2,'Organic Apples',TRUE); CREATE TABLE Sales (sale_id INT,store_id INT,product_id INT,quantity INT); INSERT INTO Sales (sale_id,store_id,product_id,quantity) VALUES (1,1,2,50),(2,2,2,75),(3,3,2,100);
|
SELECT s.store_name, p.product_name, SUM(s.quantity) as total_quantity FROM Sales s JOIN Stores st ON s.store_id = st.store_id JOIN Products p ON s.product_id = p.product_id WHERE p.is_organic = TRUE AND p.product_name = 'Organic Apples' GROUP BY s.store_id;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.