instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
Which organizations received the most funding in Q3 2020?
|
CREATE TABLE funding (org_id INT,amount DECIMAL(10,2),funding_date DATE); INSERT INTO funding (org_id,amount,funding_date) VALUES (1,5000.00,'2020-07-01'),(2,7000.00,'2020-08-15'),(1,3000.00,'2020-10-05');
|
SELECT org_id, SUM(amount) AS total_funding FROM funding WHERE QUARTER(funding_date) = 3 AND YEAR(funding_date) = 2020 GROUP BY org_id ORDER BY total_funding DESC;
|
Display the number of organic menu items and the percentage of organic menu items for each restaurant.
|
CREATE TABLE Restaurants (RestaurantID int,RestaurantName varchar(255)); CREATE TABLE MenuItems (MenuID int,MenuName varchar(255),RestaurantID int,IsOrganic bit);
|
SELECT R.RestaurantName, COUNT(MI.MenuID) as OrganicMenuItemCount, (COUNT(MI.MenuID) * 100.0 / (SELECT COUNT(*) FROM MenuItems WHERE RestaurantID = R.RestaurantID)) as OrganicPercentage FROM Restaurants R INNER JOIN MenuItems MI ON R.RestaurantID = MI.RestaurantID WHERE MI.IsOrganic = 1 GROUP BY R.RestaurantID;
|
Determine the average ocean acidification level in the Arctic Ocean.
|
CREATE TABLE ocean_acidification_arctic (location VARCHAR(255),level FLOAT); INSERT INTO ocean_acidification_arctic (location,level) VALUES ('Arctic Ocean',8.15);
|
SELECT AVG(level) FROM ocean_acidification_arctic WHERE location = 'Arctic Ocean';
|
What is the average delivery time for shipments to Texas from warehouse 2?
|
CREATE TABLE shipments (shipment_id INT,delivery_time INT,warehouse_id INT,recipient_state VARCHAR(50)); INSERT INTO shipments (shipment_id,delivery_time,warehouse_id,recipient_state) VALUES (1,3,2,'Texas'),(2,5,2,'Texas'),(3,4,2,'California');
|
SELECT AVG(delivery_time) FROM shipments WHERE warehouse_id = 2 AND recipient_state = 'Texas';
|
What is the percentage of revenue generated from ethical fashion brands in each product category?
|
CREATE TABLE Category_Revenue (sale_id INT,sale_date DATE,sale_amount FLOAT,brand_name VARCHAR(50),product_category VARCHAR(50));
|
SELECT Category_Revenue.product_category, AVG(CASE WHEN Category_Revenue.brand_name IN (SELECT DISTINCT brand_name FROM Ethical_Fashion_Brands) THEN 100 ELSE 0 END) as ethical_brand_percentage FROM Category_Revenue GROUP BY Category_Revenue.product_category;
|
What is the average running distance per game for each player?
|
CREATE TABLE Player (PlayerID int,PlayerName varchar(50)); CREATE TABLE Game (GameID int,PlayerID int,RunningDistance decimal(5,2)); INSERT INTO Player (PlayerID,PlayerName) VALUES (1,'John Doe'),(2,'Jane Smith'),(3,'Alex Johnson'); INSERT INTO Game (GameID,PlayerID,RunningDistance) VALUES (1,1,5.6),(2,1,6.2),(3,2,4.8),(4,2,5.5),(5,3,7.0),(6,3,7.3);
|
SELECT p.PlayerName, AVG(g.RunningDistance) AS AvgRunningDistance FROM Player p JOIN Game g ON p.PlayerID = g.PlayerID GROUP BY p.PlayerID, p.PlayerName;
|
What is the average age of players who play games in the 'Simulation' genre in Africa?
|
CREATE TABLE players (id INT,age INT,game_genre VARCHAR(20),location VARCHAR(20)); INSERT INTO players (id,age,game_genre,location) VALUES (1,25,'racing','USA'),(2,30,'rpg','Germany'),(3,22,'shooter','France'),(4,35,'Simulation','Nigeria'),(5,40,'Simulation','Egypt');
|
SELECT AVG(age) FROM players WHERE game_genre = 'Simulation' AND location LIKE 'Africa%';
|
Determine average price difference between Blue Dream and Sour Diesel strains across all dispensaries in Colorado.
|
CREATE TABLE strains (id INT,name VARCHAR(255)); INSERT INTO strains (id,name) VALUES (1,'Blue Dream'),(2,'Sour Diesel'); CREATE TABLE prices (id INT,strain_id INT,dispensary_id INT,price DECIMAL(10,2));
|
SELECT AVG(p1.price - p2.price) as price_difference FROM strains s1 INNER JOIN prices p1 ON s1.id = p1.strain_id INNER JOIN strains s2 ON s2.name = 'Sour Diesel' INNER JOIN prices p2 ON s2.id = p2.strain_id AND p1.dispensary_id = p2.dispensary_id WHERE s1.name = 'Blue Dream';
|
Calculate the percentage of time each machine was in production during Q3 2020.
|
CREATE TABLE MachineProduction (ID INT,MachineID INT,StartTime TIME,EndTime TIME); INSERT INTO MachineProduction (ID,MachineID,StartTime,EndTime) VALUES (1,501,'06:00:00','14:00:00'),(2,502,'08:00:00','16:00:00'),(3,501,'10:00:00','18:00:00'),(4,503,'07:00:00','15:00:00');
|
SELECT MachineID, SUM(TIMESTAMPDIFF(HOUR, StartTime, EndTime)) / (SELECT SUM(TIMESTAMPDIFF(HOUR, StartTime, EndTime)) FROM MachineProduction WHERE MachineProduction.MachineID = Machines.ID AND MachineProduction.StartTime >= '2020-07-01' AND MachineProduction.StartTime < '2020-10-01') * 100 AS Percentage FROM Machines WHERE MachineID IN (SELECT MachineID FROM MachineProduction WHERE MachineProduction.StartTime >= '2020-07-01' AND MachineProduction.StartTime < '2020-10-01') GROUP BY MachineID;
|
Which is the previous improvement score for each patient at their follow-up date?
|
CREATE TABLE patient_outcomes (patient_id INT,condition_id INT,improvement_score INT,follow_up_date DATE); INSERT INTO patient_outcomes (patient_id,condition_id,improvement_score,follow_up_date) VALUES (5,1,12,'2022-01-01'); INSERT INTO patient_outcomes (patient_id,condition_id,improvement_score,follow_up_date) VALUES (6,1,18,'2022-02-01'); INSERT INTO patient_outcomes (patient_id,condition_id,improvement_score,follow_up_date) VALUES (7,2,7,'2022-03-01'); INSERT INTO patient_outcomes (patient_id,condition_id,improvement_score,follow_up_date) VALUES (8,2,11,'2022-04-01');
|
SELECT patient_id, condition_id, improvement_score, follow_up_date, LAG(improvement_score) OVER (PARTITION BY patient_id ORDER BY follow_up_date) as previous_score FROM patient_outcomes;
|
List all routes with fare collections on weekends.
|
CREATE TABLE route (route_id INT,route_name VARCHAR(50)); INSERT INTO route (route_id,route_name) VALUES (1,'Red Line'),(2,'Green Line'),(3,'Blue Line'); CREATE TABLE fare (fare_id INT,route_id INT,fare_amount DECIMAL(5,2),collection_date DATE); INSERT INTO fare (fare_id,route_id,fare_amount,collection_date) VALUES (1,1,3.50,'2022-06-01'),(2,1,3.25,'2022-06-03'),(3,2,3.50,'2022-06-05'),(4,2,3.25,'2022-06-07'),(5,3,3.50,'2022-06-09'),(6,3,3.25,'2022-06-11');
|
SELECT route_name FROM route JOIN fare ON route.route_id = fare.route_id WHERE DATEPART(dw, collection_date) IN (1, 7);
|
What is the minimum premium for policies with sum insured less than 60000?
|
CREATE TABLE policy_info (policy_id INT,premium FLOAT,sum_insured INT); INSERT INTO policy_info (policy_id,premium,sum_insured) VALUES (1,1200.50,60000),(2,2500.00,70000),(3,1800.00,90000);
|
SELECT MIN(premium) FROM policy_info WHERE sum_insured < 60000;
|
What was the total number of tickets sold for theater performances in Q1 2022?
|
CREATE TABLE Events (EventID INT,EventType VARCHAR(50),StartDate DATE,EndDate DATE); INSERT INTO Events (EventID,EventType,StartDate,EndDate) VALUES (1,'Dance Performance','2022-04-01','2022-04-03'),(2,'Theater Performance','2022-01-01','2022-01-31'); CREATE TABLE Tickets (TicketID INT,EventID INT,Quantity INT); INSERT INTO Tickets (TicketID,EventID,Quantity) VALUES (1,1,100),(2,2,200);
|
SELECT SUM(Quantity) FROM Events INNER JOIN Tickets ON Events.EventID = Tickets.EventID WHERE Events.EventType = 'Theater Performance' AND QUARTER(StartDate) = 1;
|
What is the total number of rides taken in autonomous ridesharing services?
|
CREATE TABLE if not exists autonomous_ridesharing (ride_id INT,driver_id INT,passenger_id INT,start_time TIMESTAMP,end_time TIMESTAMP,vehicle_type VARCHAR(255),is_autonomous BOOLEAN);
|
SELECT COUNT(*) as total_autonomous_rides FROM autonomous_ridesharing WHERE is_autonomous = TRUE;
|
What is the minimum budget allocated for public transportation in the state of Illinois?
|
CREATE TABLE state_services (state VARCHAR(20),service VARCHAR(20),budget INT); INSERT INTO state_services (state,service,budget) VALUES ('Illinois','Public Transportation',8000000);
|
SELECT MIN(budget) FROM state_services WHERE state = 'Illinois' AND service = 'Public Transportation';
|
What is the total value of military equipment by country of origin, ranked by total value in descending order?
|
CREATE TABLE Equipment_Origin (Equipment_Type VARCHAR(255),Country_Of_Origin VARCHAR(255),Equipment_Value INT); INSERT INTO Equipment_Origin (Equipment_Type,Country_Of_Origin,Equipment_Value) VALUES ('Aircraft','USA',5000000),('Vehicles','Canada',3000000),('Naval','Mexico',4000000),('Weaponry','Brazil',6000000),('Aircraft','USA',7000000),('Vehicles','Canada',8000000),('Naval','Mexico',9000000),('Weaponry','Brazil',10000000);
|
SELECT Country_Of_Origin, SUM(Equipment_Value) as Total_Equipment_Value FROM Equipment_Origin GROUP BY Country_Of_Origin ORDER BY Total_Equipment_Value DESC;
|
Show the distribution of garment production by material and country.
|
CREATE TABLE garment_production (id INT,country VARCHAR(50),material VARCHAR(50),quantity INT); INSERT INTO garment_production (id,country,material,quantity) VALUES (1,'India','Cotton',5000),(2,'Bangladesh','Polyester',4000),(3,'China','Viscose',6000);
|
SELECT country, material, SUM(quantity) as total_quantity FROM garment_production GROUP BY country, material;
|
What is the total number of wells drilled in the Gulf of Mexico between 2017 and 2020, and what is the sum of their daily production rates of gas?
|
CREATE TABLE gulf_of_mexico (id INT,well_name VARCHAR(255),drill_date DATE,daily_production_gas FLOAT);
|
SELECT COUNT(*) as total_wells, SUM(daily_production_gas) as total_daily_production_gas FROM gulf_of_mexico WHERE drill_date BETWEEN '2017-01-01' AND '2020-12-31';
|
Find the top 3 suppliers in the US by the number of orders in 2021?
|
CREATE TABLE suppliers (supplier_id INT,supplier_name VARCHAR(50),country VARCHAR(50),orders INT);
|
SELECT supplier_name, COUNT(orders) FROM suppliers WHERE country = 'USA' AND EXTRACT(YEAR FROM order_date) = 2021 GROUP BY supplier_name ORDER BY COUNT(orders) DESC LIMIT 3;
|
List the names and species of all animals in the Svalbard Wildlife Reserve.
|
CREATE TABLE Animals (name VARCHAR(50),species VARCHAR(50),location VARCHAR(50)); INSERT INTO Animals (name,species,location) VALUES ('Polar Bear 1','Polar Bear','Svalbard Wildlife Reserve'),('Polar Bear 2','Polar Bear','Svalbard Wildlife Reserve'),('Reindeer 1','Reindeer','Svalbard Wildlife Reserve'); CREATE TABLE Reserves (name VARCHAR(50),location VARCHAR(50)); INSERT INTO Reserves (name,location) VALUES ('Svalbard Wildlife Reserve','Svalbard');
|
SELECT name, species FROM Animals INNER JOIN Reserves ON TRUE WHERE Animals.location = Reserves.location AND Reserves.name = 'Svalbard Wildlife Reserve';
|
How many community policing events were held in 'Precinct 5' last year?
|
CREATE TABLE community_policing (id INT,precinct VARCHAR(20),year INT,events INT);
|
SELECT SUM(events) FROM community_policing WHERE precinct = 'Precinct 5' AND year = 2021;
|
Calculate the number of volunteers who joined in H1 2018 from 'Africa' and 'South America'?
|
CREATE TABLE volunteers (volunteer_id INT,volunteer_name TEXT,volunteer_region TEXT,volunteer_join_date DATE); INSERT INTO volunteers (volunteer_id,volunteer_name,volunteer_region,volunteer_join_date) VALUES (1,'Alice Doe','Africa','2018-01-01');
|
SELECT COUNT(*) FROM volunteers WHERE EXTRACT(QUARTER FROM volunteer_join_date) IN (1, 2) AND volunteer_region IN ('Africa', 'South America');
|
Show the top 3 cities with the most fans in 'fan_demographics_v'
|
CREATE VIEW fan_demographics_v AS SELECT fan_id,age,gender,city,state,country FROM fan_data; CREATE TABLE fan_data (fan_id INT,age INT,gender VARCHAR(10),city VARCHAR(50),state VARCHAR(20),country VARCHAR(50)); INSERT INTO fan_data (fan_id,age,gender,city,state,country) VALUES (1,22,'Male','New York','NY','USA'); INSERT INTO fan_data (fan_id,age,gender,city,state,country) VALUES (2,28,'Female','Los Angeles','CA','USA');
|
SELECT city, COUNT(*) AS fan_count FROM fan_demographics_v GROUP BY city ORDER BY fan_count DESC LIMIT 3;
|
What is the number of male and female patients who received therapy in New York in 2022?
|
CREATE TABLE therapy_patients (patient_id INT,gender VARCHAR(6),therapy_type VARCHAR(10),state VARCHAR(20),year INT); INSERT INTO therapy_patients VALUES (1,'Male','CBT','New York',2022),(2,'Female','DBT','New York',2022),(3,'Male','CBT','New York',2022);
|
SELECT gender, COUNT(*) FROM therapy_patients WHERE therapy_type IN ('CBT', 'DBT') AND state = 'New York' AND year = 2022 GROUP BY gender;
|
What is the average number of hospital beds per rural clinic in Texas and California?
|
CREATE TABLE rural_clinics (clinic_id INT,clinic_name VARCHAR(50),state VARCHAR(2),num_hospital_beds INT); INSERT INTO rural_clinics (clinic_id,clinic_name,state,num_hospital_beds) VALUES (1,'Rural Clinic A','TX',15),(2,'Rural Clinic B','TX',20),(3,'Rural Clinic C','CA',10),(4,'Rural Clinic D','CA',12);
|
SELECT state, AVG(num_hospital_beds) as avg_hospital_beds FROM rural_clinics WHERE state IN ('TX', 'CA') GROUP BY state;
|
Create a view that joins excavation sites and artifacts
|
CREATE TABLE ExcavationSites (SiteID INT PRIMARY KEY,SiteName VARCHAR(255),Country VARCHAR(255),StartDate DATE,EndDate DATE); CREATE TABLE Artifacts (ArtifactID INT PRIMARY KEY,SiteID INT,ArtifactName VARCHAR(255),Description TEXT,Material VARCHAR(255),DateFound DATE); CREATE VIEW ExcavationArtifacts AS SELECT ES.SiteName,A.ArtifactName,A.Material,A.DateFound FROM ExcavationSites ES INNER JOIN Artifacts A ON ES.SiteID = A.SiteID;
|
CREATE VIEW ExcavationArtifacts AS SELECT ES.SiteName, A.ArtifactName, A.Material, A.DateFound FROM ExcavationSites ES INNER JOIN Artifacts A ON ES.SiteID = A.SiteID;
|
Compute the 12-month rolling average financial wellbeing score.
|
CREATE TABLE wellbeing_scores (customer_id INT,score INT,score_date DATE);
|
SELECT customer_id, AVG(score) OVER (PARTITION BY customer_id ORDER BY score_date ROWS BETWEEN 11 PRECEDING AND CURRENT ROW) AS rolling_avg FROM wellbeing_scores;
|
What is the maximum number of likes received by posts with the hashtag '#travel' in the 'North America' region for the month of June 2021?
|
CREATE TABLE posts (post_id INT,user_id INT,post_date DATE,likes INT,hashtags VARCHAR(255),region VARCHAR(255)); INSERT INTO posts (post_id,user_id,post_date,likes,hashtags,region) VALUES (1,1,'2021-06-01',100,'#travel','North America');
|
SELECT MAX(likes) FROM posts WHERE hashtags LIKE '%#travel%' AND region = 'North America' AND post_date >= '2021-06-01' AND post_date < '2021-07-01';
|
Find the difference in revenue between restaurants 1 and 2. Display the result as a single value.
|
CREATE TABLE restaurant_revenue (restaurant_id INT,revenue INT); INSERT INTO restaurant_revenue (restaurant_id,revenue) VALUES (1,1200),(2,1500),(3,800),(4,2000),(5,1700);
|
SELECT ABS(SUM(r1.revenue) - SUM(r2.revenue)) as revenue_difference FROM restaurant_revenue r1, restaurant_revenue r2 WHERE r1.restaurant_id = 1 AND r2.restaurant_id = 2;
|
How many employees are working on each mining site in Colorado?
|
CREATE TABLE sites (site_id INT,site_name VARCHAR(100),state VARCHAR(50)); INSERT INTO sites (site_id,site_name,state) VALUES (1,'Golden Mining Site','California'); INSERT INTO sites (site_id,site_name,state) VALUES (2,'Silver Peak Mine','Nevada'); INSERT INTO sites (site_id,site_name,state) VALUES (3,'Colorado Mine','Colorado'); CREATE TABLE employees (employee_id INT,employee_name VARCHAR(100),site_id INT); INSERT INTO employees (employee_id,employee_name,site_id) VALUES (1,'John Doe',1); INSERT INTO employees (employee_id,employee_name,site_id) VALUES (2,'Jane Smith',1); INSERT INTO employees (employee_id,employee_name,site_id) VALUES (3,'Robert Johnson',2); INSERT INTO employees (employee_id,employee_name,site_id) VALUES (4,'Maria Garcia',3); INSERT INTO employees (employee_id,employee_name,site_id) VALUES (5,'Jose Hernandez',3);
|
SELECT sites.site_name, COUNT(employees.employee_id) as total_employees FROM sites LEFT JOIN employees ON sites.site_id = employees.site_id WHERE sites.state = 'Colorado' GROUP BY sites.site_name;
|
How many hotels have adopted AI-powered chatbots in Tokyo, Japan?
|
CREATE TABLE hotel_tech (hotel_id INT,hotel_name VARCHAR(255),city VARCHAR(255),country VARCHAR(255),has_ai_chatbot BOOLEAN); INSERT INTO hotel_tech (hotel_id,hotel_name,city,country,has_ai_chatbot) VALUES (1,'Hotel Grande','Tokyo','Japan',true),(2,'Hotel Matsumoto','Tokyo','Japan',false);
|
SELECT COUNT(*) FROM hotel_tech WHERE city = 'Tokyo' AND country = 'Japan' AND has_ai_chatbot = true;
|
What is the percentage of concert ticket sales in Europe out of the total sales worldwide?
|
CREATE TABLE concerts (concert_id INT,concert_country VARCHAR(50),tickets_sold INT); INSERT INTO concerts (concert_id,concert_country,tickets_sold) VALUES (1,'France',500),(2,'Germany',800),(3,'United States',1500);
|
SELECT (SUM(CASE WHEN concert_country = 'Europe' THEN tickets_sold ELSE 0 END) / SUM(tickets_sold)) * 100 AS percentage FROM concerts;
|
Find the autonomous driving research data from 2020.
|
CREATE TABLE AutonomousResearch (Year INT,Data VARCHAR(255)); INSERT INTO AutonomousResearch (Year,Data) VALUES (2018,'Data 1'),(2019,'Data 2'),(2020,'Data 3'),(2021,'Data 4');
|
SELECT Data FROM AutonomousResearch WHERE Year = 2020;
|
What is the distribution of AI safety violations by type in South America?
|
CREATE TABLE ai_safety_violations_types (violation_id INT PRIMARY KEY,violation_type VARCHAR(255),region VARCHAR(255));
|
SELECT violation_type, COUNT(*) AS violation_count FROM ai_safety_violations_types WHERE region = 'South America' GROUP BY violation_type;
|
What was the average expenditure per day for adventure tourists in New Zealand in 2020?
|
CREATE TABLE tourism_stats (country VARCHAR(255),year INT,tourism_type VARCHAR(255),daily_expenditure DECIMAL(10,2)); INSERT INTO tourism_stats (country,year,tourism_type,daily_expenditure) VALUES ('New Zealand',2020,'Adventure',150.00),('New Zealand',2020,'Adventure',160.00),('New Zealand',2020,'Adventure',170.00);
|
SELECT AVG(daily_expenditure) AS avg_daily_expenditure FROM tourism_stats WHERE country = 'New Zealand' AND year = 2020 AND tourism_type = 'Adventure';
|
Non-sustainable food items by supplier
|
CREATE TABLE Supplier (SupplierID INT,SupplierName VARCHAR(50),FarmID INT); INSERT INTO Supplier (SupplierID,SupplierName,FarmID) VALUES (1,'Farm Fresh',2),(2,'Green Fields',3);
|
SELECT s.SupplierName, f.ItemName FROM Supplier s INNER JOIN FoodItem f ON s.FarmID = f.FarmID WHERE f.IsSustainable = FALSE;
|
What is the total amount of dysprosium produced in South Africa between 2015 and 2017?
|
CREATE TABLE south_africa_dysprosium (id INT,year INT,amount INT); INSERT INTO south_africa_dysprosium (id,year,amount) VALUES (1,2014,2000),(2,2015,2500),(3,2016,3000),(4,2017,3500),(5,2018,4000);
|
SELECT SUM(amount) FROM south_africa_dysprosium WHERE year BETWEEN 2015 AND 2017;
|
What are the top 3 states with the highest number of bridges built before 1950?
|
CREATE TABLE bridges (id INT,bridge_name VARCHAR(255),built_year INT,state VARCHAR(255)); INSERT INTO bridges (id,bridge_name,built_year,state) VALUES (1,'Brooklyn Bridge',1883,'New York'),(2,'Golden Gate Bridge',1937,'California'),(3,'Ford Rouge Bridge',1932,'Michigan'),(4,'Boston University Bridge',1928,'Massachusetts'),(5,'Cape Cod Canal Railroad Bridge',1935,'Massachusetts'),(6,'Hell Gate Bridge',1916,'New York'),(7,'Ambassador Bridge',1929,'Michigan');
|
SELECT state, COUNT(*) as bridge_count FROM bridges WHERE built_year < 1950 GROUP BY state ORDER BY bridge_count DESC LIMIT 3;
|
Insert a new product made from recycled polyester with a quantity of 15 and a price of 50.
|
CREATE TABLE PRODUCT (id INT PRIMARY KEY,name TEXT,material TEXT,quantity INT,price INT,country TEXT,certifications TEXT,is_recycled BOOLEAN);
|
INSERT INTO PRODUCT (name, material, quantity, price, country, certifications, is_recycled) VALUES ('Recycled Polyester Jacket', 'Recycled Polyester', 15, 50, 'Canada', 'BlueSign', TRUE);
|
How many art pieces were created by artists from Africa in the 'sculpture' medium?
|
CREATE TABLE art_pieces (id INT,title TEXT,artist_name TEXT,medium TEXT,region TEXT); INSERT INTO art_pieces (id,title,artist_name,medium,region) VALUES (1,'African Mask','Unknown','sculpture','Africa');
|
SELECT COUNT(*) FROM art_pieces WHERE medium = 'sculpture' AND region = 'Africa';
|
What is the total revenue of products that are 'vegan' and 'organic' certified?
|
CREATE TABLE products (product_id INT,product_name VARCHAR(255),certification VARCHAR(255),price DECIMAL(10,2),quantity INT);INSERT INTO products VALUES (1,'Product A','vegan',10,10),(2,'Product B','organic',15,20),(3,'Product C','organic',20,30),(4,'Product D','vegan',25,40),(5,'Product E','vegan,organic',30,50);
|
SELECT SUM(price * quantity) FROM products WHERE certification IN ('vegan', 'organic') GROUP BY certification HAVING COUNT(DISTINCT certification) = 2
|
What is the average co-ownership price per square foot in the city of Portland, OR?
|
CREATE TABLE real_estate(id INT,city VARCHAR(50),price DECIMAL(10,2),size INT); INSERT INTO real_estate VALUES (1,'Portland',350000,1500);
|
SELECT AVG(price/size) FROM real_estate WHERE city = 'Portland';
|
What is the total revenue generated from sales of songs released in 2021?
|
CREATE TABLE sales (id INT,song_id INT,price FLOAT,release_year INT); INSERT INTO sales (id,song_id,price,release_year) VALUES (1,1,1.2,2021),(2,2,0.9,2021),(3,3,1.5,2021),(4,4,0.8,2020),(5,5,1.3,2021);
|
SELECT SUM(price) FROM sales WHERE release_year = 2021;
|
Which ethical labor practice certifications are held by suppliers in Germany?
|
CREATE TABLE certifications(certification_id INT,certification_name TEXT); INSERT INTO certifications(certification_id,certification_name) VALUES (1,'Fair Trade'),(2,'SA8000'),(3,'SEDEX'); CREATE TABLE suppliers(supplier_id INT,supplier_name TEXT,country TEXT); INSERT INTO suppliers(supplier_id,supplier_name,country) VALUES (1,'Ethical Fabrics Germany','Germany'); CREATE TABLE supplier_certifications(supplier_id INT,certification_id INT); INSERT INTO supplier_certifications(supplier_id,certification_id) VALUES (1,2),(1,3);
|
SELECT DISTINCT suppliers.country, certifications.certification_name FROM suppliers JOIN supplier_certifications ON suppliers.supplier_id = supplier_certifications.supplier_id JOIN certifications ON supplier_certifications.certification_id = certifications.certification_id WHERE suppliers.country = 'Germany';
|
Show me the names and locations of all military bases located in 'asia' schema
|
CREATE SCHEMA if not exists asia; USE asia; CREATE TABLE if not exists military_bases (id INT,name VARCHAR(255),type VARCHAR(255),location VARCHAR(255)); INSERT INTO military_bases (id,name,type,location) VALUES (1,'Yokota Air Base','Air Force Base','Japan'),(2,'Camp Humphreys','Army Base','South Korea'),(3,'INDRA Base','Air Force Base','India');
|
SELECT name, location FROM asia.military_bases;
|
What was the total number of concert ticket sales for artist 'X'?
|
CREATE TABLE ArtistTicketSales (artist VARCHAR(255),year INT,sales INT);
|
SELECT SUM(sales) FROM ArtistTicketSales WHERE artist = 'X';
|
What is the total waste quantity generated per location and material, and the total landfill capacity for each location, for the year 2020?
|
CREATE TABLE WasteGeneration (Date date,Location text,Material text,Quantity integer);CREATE TABLE LandfillCapacity (Location text,Capacity integer);
|
SELECT wg.Location, wg.Material, SUM(wg.Quantity) as TotalWasteQuantity, lc.Capacity as TotalLandfillCapacity FROM WasteGeneration wg JOIN LandfillCapacity lc ON wg.Location = lc.Location WHERE wg.Date >= '2020-01-01' AND wg.Date < '2021-01-01' GROUP BY wg.Location, wg.Material, lc.Capacity;
|
What is the maximum number of visitors to eco-friendly accommodations in South America?
|
CREATE TABLE accommodations (id INT,name TEXT,continent TEXT,type TEXT,visitors INT); INSERT INTO accommodations (id,name,continent,type,visitors) VALUES (1,'Eco Lodge','South America','Eco-friendly',2500),(2,'Green Hotel','South America','Eco-friendly',3000);
|
SELECT MAX(visitors) FROM accommodations WHERE continent = 'South America' AND type = 'Eco-friendly';
|
What was the total budget for criminal justice systems before 2018?
|
CREATE TABLE public.criminal_justice (id serial PRIMARY KEY,name text,type text,budget integer,year integer); INSERT INTO public.criminal_justice (name,type,budget,year) VALUES ('Prison System','Corrections',85000000,2020),('Police Department','Law Enforcement',150000000,2018);
|
SELECT name, type, budget, year, (SELECT SUM(budget) FROM public.criminal_justice cj2 WHERE cj2.year < cj.year AND cj2.id <> cj.id) as total_budget_before FROM public.criminal_justice cj WHERE year < 2018;
|
Insert a new record into the Ships table for a ship named 'Sea Explorer' that was decommissioned in 2010.
|
CREATE TABLE ships (name VARCHAR(255),year_decommissioned INT,type VARCHAR(255));
|
INSERT INTO ships (name, year_decommissioned, type) VALUES ('Sea Explorer', 2010, 'Exploration');
|
List the unique types of workouts offered in the 'Boston' and 'Seattle' studios.
|
CREATE TABLE Workouts (studio VARCHAR(50),workout VARCHAR(50)); INSERT INTO Workouts (studio,workout) VALUES ('Boston','Yoga'),('Boston','Pilates'),('Seattle','Cycling'),('Seattle','Yoga');
|
SELECT DISTINCT workout FROM Workouts WHERE studio IN ('Boston', 'Seattle');
|
Update the player's name in the players table
|
CREATE TABLE players (player_id INT,name VARCHAR(100),game VARCHAR(50));
|
UPDATE players SET name = 'NewPlayerName' WHERE player_id = 1;
|
What is the minimum number of wins for teams that have won a championship in the last 5 years?
|
CREATE TABLE teams (team_id INT,team_name VARCHAR(50),division VARCHAR(50),wins INT,championships INT);
|
SELECT MIN(teams.wins) FROM teams WHERE teams.championships > 0;
|
List all autonomous driving research programs in Germany and the number of safety tests conducted.
|
CREATE TABLE SafetyTests (Id INT,TestType VARCHAR(50),VehicleId INT,TestDate DATE,Program VARCHAR(100)); CREATE TABLE AutonomousVehicles (Id INT,Name VARCHAR(100),Program VARCHAR(100)); INSERT INTO SafetyTests (Id,TestType,VehicleId,TestDate,Program) VALUES (9,'Lane Keeping',5,'2021-04-15','AutonomousDrivingGermany'),(10,'Traffic Sign Recognition',5,'2021-04-16','AutonomousDrivingGermany'); INSERT INTO AutonomousVehicles (Id,Name,Program) VALUES (5,'AutonomousCarGermany','AutonomousDrivingGermany');
|
SELECT AutonomousVehicles.Program, COUNT(SafetyTests.Id) FROM AutonomousVehicles INNER JOIN SafetyTests ON AutonomousVehicles.Id = SafetyTests.VehicleId WHERE Program LIKE '%Germany%' GROUP BY AutonomousVehicles.Program;
|
What is the total number of intelligence reports filed in the last quarter for the Asia-Pacific region?
|
CREATE TABLE intelligence_reports (id INT,report_date DATE,region VARCHAR(255)); INSERT INTO intelligence_reports (id,report_date,region) VALUES (1,'2022-01-01','Asia-Pacific'),(2,'2022-02-15','Europe'),(3,'2022-03-01','Asia-Pacific'); CREATE VIEW recent_intelligence_reports AS SELECT * FROM intelligence_reports WHERE report_date >= DATE_SUB(CURDATE(),INTERVAL 3 MONTH) AND region = 'Asia-Pacific';
|
SELECT COUNT(*) FROM recent_intelligence_reports;
|
What is the total number of lifelong learning course enrollments by age group?
|
CREATE TABLE age_group (age_group_id INT,age_group TEXT); CREATE TABLE enrollment (enrollment_id INT,age_group_id INT,num_students INT); INSERT INTO age_group (age_group_id,age_group) VALUES (1,'Under 18'),(2,'18-24'),(3,'25-34'),(4,'35-44'),(5,'45-54'),(6,'55-64'),(7,'65+'); INSERT INTO enrollment (enrollment_id,age_group_id,num_students) VALUES (101,2,150),(102,3,120),(103,4,200),(104,5,250),(105,6,180),(106,7,130);
|
SELECT age_group, SUM(num_students) FROM enrollment INNER JOIN age_group ON enrollment.age_group_id = age_group.age_group_id GROUP BY age_group;
|
What is the number of accommodations provided, per accommodation type, per country?
|
CREATE TABLE Accommodations (ID INT PRIMARY KEY,Country VARCHAR(50),AccommodationType VARCHAR(50),Quantity INT); INSERT INTO Accommodations (ID,Country,AccommodationType,Quantity) VALUES (1,'USA','Sign Language Interpretation',300),(2,'Canada','Wheelchair Ramp',250),(3,'Mexico','Assistive Listening Devices',150);
|
SELECT Country, AccommodationType, SUM(Quantity) as Total FROM Accommodations GROUP BY Country, AccommodationType;
|
How many hours of educational content are available in South America for speakers of indigenous languages?
|
CREATE TABLE content (content_id INT,content_type VARCHAR(20),language VARCHAR(20),audience_type VARCHAR(20),hours_available FLOAT); INSERT INTO content VALUES (1,'educational','Quechua','children',10.5);
|
SELECT SUM(hours_available) FROM content WHERE content_type = 'educational' AND language IN ('Quechua', 'Aymara', 'Guarani') AND audience_type = 'children' AND country IN ('Brazil', 'Argentina', 'Colombia', 'Peru', 'Chile');
|
What is the average training time for models developed by Explainable AI team?
|
CREATE TABLE ExplainableAIModels (ModelID INT PRIMARY KEY,ModelName VARCHAR(50),TrainingTime FLOAT,Team VARCHAR(20)); INSERT INTO ExplainableAIModels (ModelID,ModelName,TrainingTime,Team) VALUES (1,'ModelA',2.5,'Explainable AI'),(2,'ModelB',3.2,'Explainable AI');
|
SELECT AVG(TrainingTime) FROM ExplainableAIModels WHERE Team = 'Explainable AI';
|
What are total sales for each dispensary in California, grouped by city?
|
CREATE TABLE dispensaries (id INT,name VARCHAR(255),city VARCHAR(255),state VARCHAR(255)); INSERT INTO dispensaries (id,name,city,state) VALUES (1,'Dispensary A','San Francisco','CA'); CREATE TABLE sales (id INT,dispensary_id INT,amount DECIMAL(10,2));
|
SELECT d.city, SUM(s.amount) as total_sales FROM dispensaries d INNER JOIN sales s ON d.id = s.dispensary_id WHERE d.state = 'CA' GROUP BY d.city;
|
What is the total number of virtual tour views for each OTA in the 'ota_stats' table?
|
CREATE TABLE ota_stats (ota_name TEXT,virtual_tour_views INT); INSERT INTO ota_stats (ota_name,virtual_tour_views) VALUES ('Expedia',15000),('Booking.com',18000),('Agoda',12000);
|
SELECT ota_name, SUM(virtual_tour_views) FROM ota_stats GROUP BY ota_name;
|
How many units of vegan products were sold in the second quarter of 2022?
|
CREATE TABLE Dates (date DATE); CREATE TABLE Sales (sale_id INT,date DATE,product_id INT,quantity INT); CREATE TABLE Products (product_id INT,product_name VARCHAR(255),is_vegan BOOLEAN);
|
SELECT SUM(s.quantity) as total_quantity FROM Sales s JOIN Dates d ON s.date = d.date JOIN Products p ON s.product_id = p.product_id WHERE d.date BETWEEN '2022-04-01' AND '2022-06-30' AND p.is_vegan = TRUE;
|
What is the number of employees who have worked for more than 5 years in the company?
|
CREATE TABLE Employees (EmployeeID INT,YearsAtCompany INT);
|
SELECT COUNT(*) as LongTermEmployees FROM Employees WHERE YearsAtCompany > 5;
|
What is the cumulative water usage for the Clear Water Plant up to a specific date?
|
CREATE TABLE WastewaterTreatmentFacilities (FacilityID INT,FacilityName VARCHAR(255),Address VARCHAR(255),City VARCHAR(255),State VARCHAR(255),ZipCode VARCHAR(10)); INSERT INTO WastewaterTreatmentFacilities (FacilityID,FacilityName,Address,City,State,ZipCode) VALUES (1,'Clear Water Plant','1234 5th St','Houston','TX','77002'); CREATE TABLE WaterUsage (UsageID INT,FacilityID INT,UsageDate DATE,TotalGallons INT); INSERT INTO WaterUsage (UsageID,FacilityID,UsageDate,TotalGallons) VALUES (1,1,'2022-01-01',500000),(2,1,'2022-01-02',550000),(3,1,'2022-01-03',600000);
|
SELECT UsageID, SUM(TotalGallons) OVER (ORDER BY UsageDate) FROM WaterUsage WHERE FacilityID = 1;
|
What is the average resilience score for each city, grouped by metric?
|
CREATE TABLE Resilience (Id INT,City VARCHAR(50),Metric VARCHAR(50),Value FLOAT,Year INT); INSERT INTO Resilience (Id,City,Metric,Value,Year) VALUES (1,'Miami','Flood Resistance',70,2010); INSERT INTO Resilience (Id,City,Metric,Value,Year) VALUES (2,'Houston','Earthquake Resistance',80,2015);
|
SELECT City, AVG(Value) as Average_Resilience, Metric FROM Resilience GROUP BY City, Metric;
|
List the names and locations of fish processing plants in West Africa and their connected fish farms.
|
CREATE TABLE fish_processing_plants (id INT,name TEXT,region TEXT); CREATE TABLE plant_connections (id INT,plant_id INT,farm_id INT); INSERT INTO fish_processing_plants (id,name,region) VALUES (1,'Plant A','West Africa'),(2,'Plant B','West Africa'),(3,'Plant C','Central Africa'); INSERT INTO plant_connections (id,plant_id,farm_id) VALUES (1,1,1),(2,1,2),(3,2,3),(4,3,4);
|
SELECT FPP.name, FPP.region, TF.name AS farm_name FROM fish_processing_plants FPP JOIN plant_connections PC ON FPP.id = PC.plant_id JOIN tilapia_farms TF ON PC.farm_id = TF.id WHERE FPP.region = 'West Africa';
|
What is the total capacity of factories in Spain and France?
|
CREATE TABLE factories (factory_id INT,location VARCHAR(50),capacity INT); INSERT INTO factories (factory_id,location,capacity) VALUES (1,'Madrid,Spain',5000),(2,'Paris,France',7000),(3,'London,UK',6000);
|
SELECT SUM(capacity) FROM factories WHERE location LIKE '%Spain%' OR location LIKE '%France%';
|
How many players in total have scored at least 10 goals in the 'Premier League'?
|
CREATE TABLE players (player_id INT,name TEXT); INSERT INTO players (player_id,name) VALUES (1,'Messi'),(2,'Ronaldo'),(3,'Rooney'); CREATE TABLE goals (goal_id INT,player_id INT,league TEXT,goals INT); INSERT INTO goals (goal_id,player_id,league,goals) VALUES (1,1,'Premier League',20),(2,1,'Premier League',30),(3,2,'Premier League',40),(4,2,'Bundesliga',50),(5,3,'Premier League',15);
|
SELECT COUNT(*) FROM (SELECT player_id FROM goals WHERE league = 'Premier League' GROUP BY player_id HAVING SUM(goals) >= 10) AS subquery;
|
Insert a new project with "project_id" 1001, "contractor_id" 1001, "start_date" "2022-01-01", and "end_date" "2022-12-31" into the "Projects" table.
|
CREATE TABLE Projects (project_id INT,contractor_id INT,start_date DATE,end_date DATE);
|
INSERT INTO Projects (project_id, contractor_id, start_date, end_date) VALUES (1001, 1001, '2022-01-01', '2022-12-31');
|
Show the number of accidents by month in the 'safety_stats' table.
|
CREATE TABLE safety_stats (date DATE,accidents INT);
|
SELECT EXTRACT(MONTH FROM date), COUNT(*) FROM safety_stats GROUP BY EXTRACT(MONTH FROM date);
|
What is the maximum donation amount and the corresponding donor's name?
|
CREATE TABLE Donors (DonorID INT,DonorName TEXT,DonationAmount DECIMAL(10,2)); INSERT INTO Donors (DonorID,DonorName,DonationAmount) VALUES (1,'Rihanna',1000.00); INSERT INTO Donors (DonorID,DonorName,DonationAmount) VALUES (2,'Bill Gates',5000.00); INSERT INTO Donors (DonorID,DonorName,DonationAmount) VALUES (3,'Oprah Winfrey',2500.00);
|
SELECT DonorName, MAX(DonationAmount) FROM Donors;
|
Update the speed of the vessel 'VesselB' to 22.0 in the table 'vessels'.
|
CREATE TABLE vessels (id INT,name TEXT,port_id INT,speed FLOAT); INSERT INTO vessels (id,name,port_id,speed) VALUES (1,'VesselA',1,20.5),(2,'VesselB',1,21.3),(3,'VesselC',2,25.0);
|
UPDATE vessels SET speed = 22.0 WHERE name = 'VesselB';
|
What is the minimum age of patients diagnosed with eating disorders in Japan?
|
CREATE TABLE patients (patient_id INT,patient_name VARCHAR(50),condition VARCHAR(50),country VARCHAR(50),birth_date DATE); INSERT INTO patients (patient_id,patient_name,condition,country,birth_date) VALUES (1,'Hana Yamada','Anorexia','Japan','1998-05-15'),(2,'Taro Nakamura','Bulimia','Japan','2001-08-08');
|
SELECT MIN(YEAR(GETDATE()) - YEAR(birth_date)) FROM patients WHERE patients.country = 'Japan' AND patients.condition LIKE '%Eating Disorder%';
|
How many students are enrolled in each program in the Spring semester?
|
CREATE TABLE enrollment(id INT,program TEXT,semester TEXT); INSERT INTO enrollment(id,program,semester) VALUES (1,'Data Science','Spring'),(2,'Mathematics','Spring'),(3,'Physics','Fall');
|
SELECT program, COUNT(*) FROM enrollment GROUP BY program HAVING semester = 'Spring';
|
What is the average cargo weight handled per day by the port of Shanghai in February 2022?
|
CREATE TABLE cargo_handling (cargo_handling_id INT,port VARCHAR(255),cargo_weight INT,handling_date DATE);INSERT INTO cargo_handling (cargo_handling_id,port,cargo_weight,handling_date) VALUES (1,'Shanghai',50000,'2022-02-01'),(2,'Shanghai',55000,'2022-02-02');
|
SELECT AVG(cargo_weight) FROM cargo_handling WHERE port = 'Shanghai' AND EXTRACT(MONTH FROM handling_date) = 2 AND EXTRACT(YEAR FROM handling_date) = 2022;
|
What was the total investment (in USD) in energy storage projects in Massachusetts between 2016 and 2021?
|
CREATE TABLE energy_storage_projects (project_id INT,state VARCHAR(20),start_year INT,end_year INT,investment FLOAT);
|
SELECT SUM(investment) FROM energy_storage_projects WHERE state = 'Massachusetts' AND start_year BETWEEN 2016 AND 2021;
|
What is the average energy efficiency rating of residential buildings in 'New York' city?
|
CREATE TABLE buildings (id INT,city VARCHAR(50),type VARCHAR(50),rating FLOAT); INSERT INTO buildings (id,city,type,rating) VALUES (1,'New York','Residential',80.5),(2,'Los Angeles','Residential',75.0);
|
SELECT AVG(rating) FROM buildings WHERE city = 'New York' AND type = 'Residential';
|
Who are the top 5 contributors to heritage site preservation funds in the Americas, based on the amount donated?
|
CREATE TABLE Heritage_Donors (Donor_Name VARCHAR(50),Country VARCHAR(50),Donation_Amount INT); INSERT INTO Heritage_Donors (Donor_Name,Country,Donation_Amount) VALUES ('John Smith','USA',500000),('Jane Doe','Canada',300000),('Maria Garcia','Mexico',400000);
|
SELECT Donor_Name, Country, Donation_Amount FROM Heritage_Donors WHERE Country IN ('USA', 'Canada', 'Mexico') ORDER BY Donation_Amount DESC LIMIT 5;
|
List all genetic research experiments conducted in the United Kingdom and France.
|
CREATE SCHEMA if not exists genetics;CREATE TABLE if not exists genetics.experiments (id INT PRIMARY KEY,name VARCHAR(100),location VARCHAR(100)); INSERT INTO genetics.experiments (id,name,location) VALUES (1,'ExpA','London'),(2,'ExpB','Manchester'),(3,'ExpC','Paris'),(4,'ExpD','Lyon'),(5,'ExpE','Glasgow');
|
SELECT DISTINCT name FROM genetics.experiments WHERE location = 'United Kingdom' OR location = 'France';
|
What is the age distribution of offenders who committed crimes against women in the past 5 years?
|
CREATE TABLE offenders (offender_id INT,offender_age INT,offender_gender VARCHAR(10),offense_date DATE); INSERT INTO offenders (offender_id,offender_age,offender_gender,offense_date) VALUES (1,32,'Male','2018-01-01'),(2,28,'Female','2019-01-01'),(3,45,'Male','2020-01-01');
|
SELECT offender_age, COUNT(*) AS num_offenders FROM offenders WHERE offender_gender = 'Male' AND offense_date BETWEEN DATEADD(year, -5, CURRENT_DATE()) AND CURRENT_DATE() GROUP BY offender_age;
|
Identify the number of AI safety incidents for each algorithm in the Asia-Pacific region.
|
CREATE TABLE ai_safety (id INT,algorithm_name VARCHAR(50),incident_count INT,region VARCHAR(50)); INSERT INTO ai_safety (id,algorithm_name,incident_count,region) VALUES (1,'Algorithm A',3,'Asia-Pacific'),(2,'Algorithm B',5,'Asia-Pacific');
|
SELECT algorithm_name, region, SUM(incident_count) FROM ai_safety WHERE region = 'Asia-Pacific' GROUP BY algorithm_name, region;
|
What is the total water usage in Mega Liters for the top 3 water consuming countries in Asia in 2020?
|
CREATE TABLE water_usage (country VARCHAR(50),usage FLOAT,year INT); INSERT INTO water_usage (country,usage,year) VALUES ('China',12345.6,2020),('India',23456.7,2020),('Indonesia',34567.8,2020);
|
SELECT SUM(usage) FROM (SELECT usage FROM water_usage WHERE year = 2020 AND country IN ('China', 'India', 'Indonesia') ORDER BY usage DESC LIMIT 3);
|
How many streams does each platform generate on average per day?
|
CREATE TABLE music_platforms (id INT,platform VARCHAR(255)); INSERT INTO music_platforms (id,platform) VALUES (1,'Spotify'),(2,'Apple Music'),(3,'YouTube'),(4,'Pandora'); CREATE TABLE streams (id INT,track_id INT,platform_id INT,timestamp TIMESTAMP); INSERT INTO streams (id,track_id,platform_id,timestamp) VALUES (1,1,1,'2022-01-01 00:00:00'),(2,2,2,'2022-01-01 01:00:00'),(3,3,3,'2022-01-01 02:00:00'),(4,4,4,'2022-01-01 03:00:00');
|
SELECT platform, AVG(TIMESTAMPDIFF(DAY, timestamp, LEAD(timestamp) OVER (PARTITION BY platform_id ORDER BY timestamp))) as avg_daily_streams FROM streams GROUP BY platform;
|
What are the names of organizations working on social good projects in Europe?
|
CREATE TABLE org_social (org_id INT,org_name TEXT,initiative TEXT); INSERT INTO org_social (org_id,org_name,initiative) VALUES (1,'OrgG','social good'),(2,'OrgH','ethical AI'),(3,'OrgI','social good');
|
SELECT org_name FROM org_social WHERE initiative = 'social good' AND region = 'Europe';
|
Update the weight of artifact '1' from 'Site I' to 18.5
|
CREATE TABLE Site (SiteID VARCHAR(10),SiteName VARCHAR(20)); INSERT INTO Site (SiteID,SiteName) VALUES ('I','Site I'); CREATE TABLE Artifact (ArtifactID VARCHAR(10),SiteID VARCHAR(10),Weight FLOAT); INSERT INTO Artifact (ArtifactID,SiteID,Weight) VALUES ('1','I',12.3),('2','I',25.6),('3','I',18.9);
|
UPDATE Artifact SET Weight = 18.5 WHERE ArtifactID = '1' AND SiteID = 'I';
|
Which causes received the most donations in April 2022?
|
CREATE TABLE causes (id INT,name VARCHAR(255)); INSERT INTO causes (id,name) VALUES (1,'Education'),(2,'Health'),(3,'Environment'),(4,'Poverty Alleviation'); CREATE TABLE donations (id INT,cause_id INT,amount DECIMAL(10,2),donation_date DATE); INSERT INTO donations (id,cause_id,amount,donation_date) VALUES (1,1,500.00,'2022-04-01'),(2,2,1000.00,'2022-04-15'),(3,1,750.00,'2022-04-03'),(4,3,200.00,'2022-04-01'),(5,2,150.00,'2022-04-30'),(6,4,1250.00,'2022-04-25');
|
SELECT cause_id, SUM(amount) as total_donation_amount FROM donations WHERE donation_date BETWEEN '2022-04-01' AND '2022-04-30' GROUP BY cause_id ORDER BY total_donation_amount DESC;
|
How many companies were founded by underrepresented minorities each year?
|
CREATE TABLE Companies (id INT,name VARCHAR(50),industry VARCHAR(50),country VARCHAR(50),founding_year INT,founder_minority VARCHAR(10)); INSERT INTO Companies (id,name,industry,country,founding_year,founder_minority) VALUES (1,'GreenTech','Renewable Energy','USA',2019,'Yes'); INSERT INTO Companies (id,name,industry,country,founding_year,founder_minority) VALUES (2,'SunPower','Renewable Energy','USA',2018,'No');
|
SELECT founding_year, COUNT(*) as underrepresented_minorities_count FROM Companies WHERE founder_minority = 'Yes' GROUP BY founding_year;
|
What is the average production quantity for wells in the 'North Sea' that were commissioned in 2017 or later?
|
CREATE TABLE wells (well_id INT,well_name VARCHAR(50),region VARCHAR(50),production_qty FLOAT,commission_date DATE); INSERT INTO wells VALUES (1,'Well A','North Sea',15000,'2017-01-01'); INSERT INTO wells VALUES (2,'Well B','North Sea',12000,'2018-01-01'); INSERT INTO wells VALUES (3,'Well C','Gulf of Mexico',18000,'2016-01-01');
|
SELECT AVG(production_qty) as avg_production FROM wells WHERE region = 'North Sea' AND commission_date >= '2017-01-01';
|
What is the total number of green buildings in each city?
|
CREATE TABLE GreenBuildings (city VARCHAR(20),num_buildings INT); INSERT INTO GreenBuildings (city,num_buildings) VALUES ('CityA',250),('CityB',300),('CityC',180),('CityD',350);
|
SELECT city, SUM(num_buildings) FROM GreenBuildings GROUP BY city;
|
Update the 'capacity_mw' value to 50 in the 'solar_plants' table where the 'id' is 1
|
CREATE TABLE solar_plants (id INT PRIMARY KEY,name VARCHAR(255),capacity_mw FLOAT,country VARCHAR(255));
|
UPDATE solar_plants SET capacity_mw = 50 WHERE id = 1;
|
Identify the number of anomalous satellite image readings for each field in the last week, considering an anomaly as a reading 2 standard deviations away from the mean.
|
CREATE TABLE field (id INT,name VARCHAR(255)); CREATE TABLE satellite_image (id INT,field_id INT,brightness INT,contrast INT,timestamp TIMESTAMP); INSERT INTO field VALUES (1,'Field A'),(2,'Field B'); INSERT INTO satellite_image VALUES (1,1,100,50,'2022-02-01 10:00:00'),(2,2,80,60,'2022-02-01 10:00:00');
|
SELECT f.name, COUNT(*) as num_anomalies FROM field f INNER JOIN satellite_image si ON f.id = si.field_id CROSS JOIN (SELECT AVG(brightness) as avg_brightness, AVG(contrast) as avg_contrast, STDDEV(brightness) as stddev_brightness, STDDEV(contrast) as stddev_contrast FROM satellite_image WHERE timestamp BETWEEN DATE_SUB(NOW(), INTERVAL 1 WEEK) AND NOW()) as means WHERE si.brightness < means.avg_brightness - 2 * means.stddev_brightness OR si.brightness > means.avg_brightness + 2 * means.stddev_brightness OR si.contrast < means.avg_contrast - 2 * means.stddev_contrast OR si.contrast > means.avg_contrast + 2 * means.stddev_contrast GROUP BY f.name;
|
How many dispensaries are located in each city in Nevada?
|
CREATE TABLE Dispensaries (id INT,name TEXT,city TEXT,state TEXT); INSERT INTO Dispensaries (id,name,city,state) VALUES (1,'Dispensary A','Las Vegas','Nevada'); INSERT INTO Dispensaries (id,name,city,state) VALUES (2,'Dispensary B','Reno','Nevada'); INSERT INTO Dispensaries (id,name,city,state) VALUES (3,'Dispensary C','Las Vegas','Nevada');
|
SELECT d.city, COUNT(DISTINCT d.id) as num_dispensaries FROM Dispensaries d WHERE d.state = 'Nevada' GROUP BY d.city;
|
Which clean energy policies were implemented in H1 2021?
|
CREATE TABLE policies (policy_id INT,policy_date DATE); INSERT INTO policies (policy_id,policy_date) VALUES (1,'2021-04-01'),(2,'2021-06-15');
|
SELECT policy_id, policy_date FROM policies WHERE policy_date BETWEEN '2021-01-01' AND '2021-06-30';
|
What is the minimum temperature recorded on Mars by any rover?
|
CREATE TABLE mars_temperature (id INT,rover_name VARCHAR(50),temperature FLOAT); INSERT INTO mars_temperature (id,rover_name,temperature) VALUES (1,'Spirit',-55),(2,'Opportunity',-70),(3,'Curiosity',-80);
|
SELECT MIN(temperature) FROM mars_temperature;
|
What is the change in timber production between 2018 and 2019, by species, and rank them by the largest increase first?
|
CREATE TABLE species_timber (species_id INT,species_name VARCHAR(50),year INT,volume INT); INSERT INTO species_timber (species_id,species_name,year,volume) VALUES (1,'Oak',2018,1000),(2,'Pine',2018,2000),(3,'Maple',2018,3000),(4,'Birch',2018,4000),(1,'Oak',2019,1500),(2,'Pine',2019,2500),(3,'Maple',2019,3500),(4,'Birch',2019,4500);
|
SELECT species_id, species_name, (volume - LAG(volume, 1) OVER (PARTITION BY species_name ORDER BY year)) AS volume_change, RANK() OVER (ORDER BY volume_change DESC) AS volume_rank FROM species_timber WHERE year IN (2018, 2019) GROUP BY species_id, species_name, volume, year ORDER BY year, volume_rank ASC;
|
Find the average price of garments in each category in the garments table
|
CREATE TABLE garments (id INT,name VARCHAR(100),price DECIMAL(5,2),category VARCHAR(50));
|
SELECT category, AVG(price) as avg_price FROM garments GROUP BY category;
|
What was the total number of drama performances in each city district in 2020?
|
CREATE TABLE DramaPerformances (id INT,district VARCHAR(10),performance_type VARCHAR(20),performance_date DATE); INSERT INTO DramaPerformances (id,district,performance_type,performance_date) VALUES (1,'Manhattan','Play','2020-02-01'),(2,'Brooklyn','Musical','2020-10-15'),(3,'Queens','Opera','2020-07-03');
|
SELECT district, performance_type, COUNT(*) as performance_count FROM DramaPerformances WHERE YEAR(performance_date) = 2020 AND performance_type = 'Drama' GROUP BY district, performance_type;
|
What is the maximum cargo weight for shipments to the United States in 2022?
|
CREATE TABLE regions (id INT,name TEXT); INSERT INTO regions (id,name) VALUES (1,'North America'),(2,'South America'); CREATE TABLE countries (id INT,region_id INT,name TEXT); INSERT INTO countries (id,region_id,name) VALUES (1,1,'United States'),(2,1,'Canada'),(3,2,'Brazil'); CREATE TABLE shipments (id INT,cargo_weight FLOAT,country_id INT); INSERT INTO shipments (id,cargo_weight,country_id) VALUES (1,8000.0,1),(2,9000.0,1),(3,6000.0,1);
|
SELECT MAX(cargo_weight) FROM shipments INNER JOIN countries ON shipments.country_id = countries.id WHERE countries.name = 'United States' AND shipment_date BETWEEN '2022-01-01' AND '2022-12-31';
|
What is the maximum daily temperature recorded at each mine location in the last month?
|
CREATE TABLE mine (id INT,name TEXT,location TEXT); INSERT INTO mine (id,name,location) VALUES (1,'Golden Mine','USA'),(2,'Silver Mine','Canada'); CREATE TABLE temperature (id INT,mine_id INT,date DATE,temperature REAL); INSERT INTO temperature (id,mine_id,date,temperature) VALUES (1,1,'2022-03-01',20),(2,1,'2022-03-02',22),(3,1,'2022-03-03',25),(4,2,'2022-03-01',10),(5,2,'2022-03-02',12),(6,2,'2022-03-03',15);
|
SELECT mine_id, MAX(temperature) as max_temperature FROM temperature WHERE date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) AND CURRENT_DATE GROUP BY mine_id;
|
What is the success rate of startups founded by women?
|
CREATE TABLE companies (id INT,name TEXT,founder_gender TEXT); INSERT INTO companies (id,name,founder_gender) VALUES (1,'Foobar Inc','Female'),(2,'Gizmos Inc','Male'),(3,'Widgets Inc','Female'),(4,'Doodads Inc','Male'),(5,'Thingamajigs Inc','Female'),(6,'Whatchamacallits Inc','Female'); CREATE TABLE success (company_id INT,is_successful BOOLEAN); INSERT INTO success (company_id,is_successful) VALUES (1,1),(2,0),(3,1),(4,1),(5,1),(6,0);
|
SELECT COUNT(*) as num_successful_startups, 100.0 * COUNT(*) / (SELECT COUNT(*) FROM companies) as success_rate FROM success JOIN companies ON success.company_id = companies.id WHERE companies.founder_gender = 'Female' AND is_successful = 1;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.