instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Who are the defense contractors involved in the Arctic geopolitical risk assessment?
CREATE TABLE GeopoliticalRiskAssessments (assessmentID INT,contractor VARCHAR(255),region VARCHAR(255)); INSERT INTO GeopoliticalRiskAssessments (assessmentID,contractor,region) VALUES (1,'Lockheed Martin','Arctic'); INSERT INTO GeopoliticalRiskAssessments (assessmentID,contractor,region) VALUES (2,'Raytheon Technologies','Arctic');
SELECT DISTINCT contractor FROM GeopoliticalRiskAssessments WHERE region = 'Arctic';
What is the total amount of funding received by 'community_development' table where the 'region' is 'south_america'?
CREATE TABLE community_development (id INT,community_name TEXT,community_size INT,region TEXT,funding FLOAT);
SELECT SUM(funding) FROM community_development WHERE region = 'south_america';
What is the average carbon price in the European Union Emissions Trading System over the last month?
CREATE TABLE carbon_prices (id INT,date DATE,price FLOAT); INSERT INTO carbon_prices (id,date,price) VALUES (1,'2022-01-01',30.0),(2,'2022-01-02',31.0),(3,'2022-01-03',29.0);
SELECT AVG(price) FROM carbon_prices WHERE date >= DATEADD(day, -30, CURRENT_DATE) AND region = 'European Union Emissions Trading System';
What is the average cost of a space mission for SpaceX?
CREATE TABLE space_missions (id INT,mission_name VARCHAR(50),mission_agency VARCHAR(50),cost INT); INSERT INTO space_missions (id,mission_name,mission_agency,cost) VALUES (1,'Mission1','SpaceX',1000000),(2,'Mission2','SpaceX',1500000),(3,'Mission3','NASA',2000000);
SELECT AVG(cost) FROM space_missions WHERE mission_agency = 'SpaceX';
What is the total number of employees in the 'manufacturing' and 'engineering' departments?
CREATE TABLE employees (id INT,name VARCHAR(50),department VARCHAR(20),salary DECIMAL(10,2)); INSERT INTO employees (id,name,department,salary) VALUES (1,'John Doe','manufacturing',50000.00),(2,'Jane Smith','engineering',60000.00),(3,'Alice Johnson','HR',55000.00);
SELECT SUM(salary) FROM employees WHERE department IN ('manufacturing', 'engineering');
Count the number of bike-share stations in the city of Chicago that have more than 20 bikes available.
CREATE TABLE bikeshare (station_id INT,city VARCHAR(20),num_bikes INT); INSERT INTO bikeshare (station_id,city,num_bikes) VALUES (1,'Chicago',25),(2,'Chicago',18),(3,'Chicago',30);
SELECT COUNT(*) FROM bikeshare WHERE city = 'Chicago' AND num_bikes > 20;
What is the average number of bookings per day for the 'Daily_Bookings' table?
CREATE TABLE Daily_Bookings (booking_date DATE,bookings INT); INSERT INTO Daily_Bookings (booking_date,bookings) VALUES ('2022-01-01',50),('2022-01-02',55),('2022-01-03',60);
SELECT AVG(bookings) FROM Daily_Bookings;
What is the minimum production rate (bbl/day) for wells in the 'North Sea'?
CREATE TABLE wells (well_id INT,region VARCHAR(20),production_rate FLOAT); INSERT INTO wells (well_id,region,production_rate) VALUES (1,'North Sea',1000),(2,'North Sea',1200),(3,'Gulf of Mexico',1500);
SELECT MIN(production_rate) FROM wells WHERE region = 'North Sea';
What is the maximum distance traveled for a single shipment in the freight forwarding data?
CREATE TABLE RouteExtreme (route_id INT,shipment_id INT,distance FLOAT,delivery_date DATE); INSERT INTO RouteExtreme (route_id,shipment_id,distance,delivery_date) VALUES (1,1,100,'2022-01-01'),(2,2,200,'2022-02-01'),(3,3,150,'2022-03-01');
SELECT MAX(distance) as max_distance FROM RouteExtreme;
Add new record to 'sustainable_practices' table with 'practice_name' as 'Rainwater Harvesting' and 'description' as 'Collecting and storing rainwater for later use'
CREATE TABLE sustainable_practices (practice_name VARCHAR(50),description VARCHAR(100));
INSERT INTO sustainable_practices (practice_name, description) VALUES ('Rainwater Harvesting', 'Collecting and storing rainwater for later use');
What is the total supply of stablecoins in the Cardano network, grouped by stablecoin type?
CREATE TABLE cardano_stablecoins (stablecoin_type VARCHAR(30),total_supply BIGINT);
SELECT stablecoin_type, SUM(total_supply) as total_stablecoin_supply FROM cardano_stablecoins GROUP BY stablecoin_type;
What is the total number of likes on posts about clean energy, published by users in Australia, in the month of March 2022?
CREATE TABLE posts (post_id INT,user_id INT,followers INT,likes INT,post_date DATE); CREATE TABLE users (user_id INT,country TEXT);
SELECT SUM(likes) FROM posts p JOIN users u ON p.user_id = u.user_id WHERE p.content LIKE '%clean energy%' AND u.country = 'Australia' AND p.post_date >= '2022-03-01' AND p.post_date < '2022-04-01';
Delete the record of the marine protected area 'MPA3' in the Atlantic Ocean from the marine_protected_areas table.
CREATE TABLE marine_protected_areas (id INT,name VARCHAR(50),location VARCHAR(50),avg_depth FLOAT); INSERT INTO marine_protected_areas (id,name,location,avg_depth) VALUES (1,'MPA1','Pacific Ocean',3500),(2,'MPA2','Atlantic Ocean',4200),(3,'MPA3','Atlantic Ocean',2700);
DELETE FROM marine_protected_areas WHERE name = 'MPA3' AND location = 'Atlantic Ocean';
List all defense diplomacy events in the 'defense_diplomacy' table, ordered by the 'event_date' column in descending order
CREATE TABLE defense_diplomacy (event_id INT,event_name VARCHAR(255),event_date DATE,participating_countries VARCHAR(255));
SELECT * FROM defense_diplomacy ORDER BY event_date DESC;
What is the average time to graduation for students in the Computer Science program who received research grants?
CREATE TABLE students (id INT,program VARCHAR(255),graduation_year INT,grant_recipient BOOLEAN); INSERT INTO students (id,program,graduation_year,grant_recipient) VALUES (1,'Computer Science',2020,TRUE),(2,'Computer Science',2019,FALSE),(3,'Mathematics',2018,TRUE),(4,'Computer Science',2021,TRUE);
SELECT AVG(graduation_year - enrollment_year) as avg_time_to_graduation FROM (SELECT s.id, s.program, s.graduation_year, (SELECT MIN(enrollment_year) FROM enrollments WHERE student_id = s.id) as enrollment_year FROM students s WHERE s.grant_recipient = TRUE) subquery;
What is the average age of readers who prefer politics news, grouped by their state in the USA?
CREATE TABLE us_readers (id INT,age INT,state VARCHAR(255),news_preference VARCHAR(255)); INSERT INTO us_readers (id,age,state,news_preference) VALUES (1,35,'NY','politics'),(2,45,'CA','sports');
SELECT r.state, AVG(r.age) FROM us_readers r WHERE r.news_preference = 'politics' GROUP BY r.state;
What is the total number of employees who identify as LGBTQ+, by department?
CREATE TABLE Employees (EmployeeID INT,Department VARCHAR(50),Identity VARCHAR(50));
SELECT e.Department, COUNT(DISTINCT e.EmployeeID) FROM Employees e WHERE e.Identity = 'LGBTQ+' GROUP BY e.Department;
How many space missions were carried out by China in 2022?
CREATE TABLE SpaceMissions(id INT,country VARCHAR(255),mission VARCHAR(255),year INT,success BOOLEAN); INSERT INTO SpaceMissions(id,country,mission,year,success) VALUES (1,'China','Mission 1',2021,true),(2,'USA','Mission 2',2022,false),(3,'China','Mission 3',2022,true),(4,'Russia','Mission 4',2021,true);
SELECT COUNT(*) FROM SpaceMissions WHERE country = 'China' AND year = 2022;
What is the average hotel rating for eco-friendly accommodations in Australia?
CREATE TABLE IF NOT EXISTS hotels (id INT PRIMARY KEY,name TEXT,country TEXT,is_eco_friendly BOOLEAN,rating FLOAT); INSERT INTO hotels (id,name,country,is_eco_friendly,rating) VALUES (1,'Eco-Retreat','Australia',true,4.6),(2,'GreenHotel','Australia',true,4.3),(3,'ResortAus','Australia',false,4.9);
SELECT AVG(rating) FROM hotels WHERE is_eco_friendly = true AND country = 'Australia';
What was the total revenue generated from 'Poetry Slam' and 'Film Screening' events in Q1 2022?
CREATE TABLE Revenues (revenue_id INT,event_id INT,amount DECIMAL(10,2),revenue_date DATE); INSERT INTO Revenues (revenue_id,event_id,amount,revenue_date) VALUES (1,6,800.00,'2022-01-05'),(2,7,1200.00,'2022-03-20');
SELECT SUM(amount) FROM Revenues WHERE event_id IN (6, 7) AND QUARTER(revenue_date) = 1 AND YEAR(revenue_date) = 2022;
What is the percentage of employees in the 'labor_rights' schema who are members of a union?
CREATE SCHEMA labor_rights; CREATE TABLE employees (id INT,name VARCHAR,union_member BOOLEAN); INSERT INTO employees VALUES (1,'Jane Smith',TRUE); CREATE TABLE unions (id INT,name VARCHAR); INSERT INTO unions VALUES (1,'Union X');
SELECT 100.0 * AVG(CASE WHEN union_member THEN 1 ELSE 0 END) AS union_membership_percentage FROM labor_rights.employees;
Identify the top 3 REE mining companies with the highest carbon emissions in 2019.
CREATE TABLE company_emissions (company_name VARCHAR(255),year INT,carbon_emissions INT); INSERT INTO company_emissions (company_name,year,carbon_emissions) VALUES ('Company A',2019,5000),('Company B',2019,6000),('Company C',2019,7000),('Company D',2019,8000),('Company E',2019,9000),('Company F',2019,10000);
SELECT company_name, carbon_emissions FROM company_emissions WHERE year = 2019 AND company_name IN (SELECT company_name FROM company_emissions WHERE year = 2019 GROUP BY company_name ORDER BY SUM(carbon_emissions) DESC LIMIT 3) ORDER BY carbon_emissions DESC;
Count the number of crop types per farm
CREATE TABLE crop_types (crop_type TEXT,farm_name TEXT); INSERT INTO crop_types (crop_type,farm_name) VALUES ('Corn','Farm A'),('Soybeans','Farm A'),('Cotton','Farm B');
SELECT farm_name, COUNT(crop_type) FROM crop_types GROUP BY farm_name;
How many artworks are there in 'Museum X'?
CREATE TABLE MuseumX (artwork VARCHAR(50),artist VARCHAR(50)); INSERT INTO MuseumX (artwork,artist) VALUES ('The Persistence of Memory','Dali'),('The Scream','Munch');
SELECT COUNT(artwork) FROM MuseumX;
What is the total donation amount and the number of donations made by top 5 donors?
CREATE TABLE Donations (id INT,donor_name TEXT,donation_amount FLOAT,donation_date DATE,state TEXT); INSERT INTO Donations (id,donor_name,donation_amount,donation_date,state) VALUES (1,'Aria',500,'2022-01-01','NY'),(2,'Benjamin',1000,'2022-02-02','CA');
SELECT donor_name, SUM(donation_amount), COUNT(*) FROM Donations GROUP BY donor_name ORDER BY SUM(donation_amount) DESC LIMIT 5;
List research vessels that are older than 25 years and their types
CREATE TABLE Research_Vessels (id INT,vessel_name VARCHAR(50),type VARCHAR(50),year INT); INSERT INTO Research_Vessels (id,vessel_name,type,year) VALUES (1,'Discovery','research',1985);
SELECT vessel_name, type FROM Research_Vessels WHERE year < 1997;
How many wildlife habitats are present in the Amazon rainforest?
CREATE TABLE WildlifeHabitats (id INT,name VARCHAR(255),region VARCHAR(255),description TEXT,area FLOAT); INSERT INTO WildlifeHabitats (id,name,region,description,area) VALUES (1,'Yasuni National Park','Amazon Rainforest','Home to many endangered species...',98200);
SELECT COUNT(*) FROM WildlifeHabitats WHERE region = 'Amazon Rainforest';
Update the birthdate of 'Yayoi Kusama' to 'March 22, 1929'
CREATE TABLE Artists (id INT,artist_name VARCHAR(255),birthdate DATE); INSERT INTO Artists (id,artist_name,birthdate) VALUES (1,'Yayoi Kusama','March 22,1930');
UPDATE Artists SET birthdate = 'March 22, 1929' WHERE artist_name = 'Yayoi Kusama';
How many electric cars are there in CityH?
CREATE TABLE CityH_Vehicles (vehicle_id INT,vehicle_type VARCHAR(20),is_electric BOOLEAN); INSERT INTO CityH_Vehicles (vehicle_id,vehicle_type,is_electric) VALUES (1,'Car',true),(2,'Bike',false),(3,'Car',true),(4,'Bus',false);
SELECT COUNT(*) FROM CityH_Vehicles WHERE vehicle_type = 'Car' AND is_electric = true;
What is the minimum depth of the ocean floor in the Arctic?
CREATE TABLE ocean_floor_depths (location TEXT,depth FLOAT); INSERT INTO ocean_floor_depths (location,depth) VALUES ('Arctic',4000.0),('Atlantic Ocean',8000.0),('Pacific Ocean',11000.0);
SELECT MIN(depth) FROM ocean_floor_depths WHERE location = 'Arctic';
What is the average age of patients who received medication-based treatment?
CREATE TABLE patients (patient_id INT,age INT,treatment_type VARCHAR(10)); INSERT INTO patients (patient_id,age,treatment_type) VALUES (1,30,'medication'),(2,45,'therapy'),(3,50,'medication'),(4,25,'therapy');
SELECT AVG(age) FROM patients WHERE treatment_type = 'medication';
Which artists have performed at more than one music festival?
CREATE TABLE Artists (ArtistID INT,ArtistName VARCHAR(100),Age INT,Genre VARCHAR(50)); INSERT INTO Artists VALUES (1,'Artist1',35,'Rock'); INSERT INTO Artists VALUES (2,'Artist2',45,'Rock'); CREATE TABLE Festivals (FestivalID INT,FestivalName VARCHAR(100),ArtistID INT); INSERT INTO Festivals VALUES (1,'Festival1',1); INSERT INTO Festivals VALUES (2,'Festival2',2); INSERT INTO Festivals VALUES (3,'Festival3',1);
SELECT A.ArtistName FROM Artists A INNER JOIN Festivals F ON A.ArtistID = F.ArtistID GROUP BY A.ArtistID HAVING COUNT(DISTINCT F.FestivalID) > 1;
Calculate the average speed of vessels in the 'vessel_performance' table
CREATE TABLE vessel_performance (vessel_id INT,speed FLOAT,timestamp TIMESTAMP);
SELECT AVG(speed) FROM vessel_performance;
What is the total revenue for each cuisine type, including the sum of sales for all menu items and additional charges?
CREATE TABLE Restaurants (RestaurantID int,RestaurantName varchar(255),Cuisine varchar(255)); CREATE TABLE MenuItems (MenuID int,MenuName varchar(255),RestaurantID int,Sales int); CREATE TABLE AdditionalCharges (ChargeID int,ChargeName varchar(255),RestaurantID int,ChargeAmt int);
SELECT R.Cuisine, SUM(M.Sales + AC.ChargeAmt) as TotalRevenue FROM Restaurants R INNER JOIN MenuItems M ON R.RestaurantID = M.RestaurantID INNER JOIN AdditionalCharges AC ON R.RestaurantID = AC.RestaurantID GROUP BY R.Cuisine;
What are the ages of investigative journalists in 'New York Times' and 'Los Angeles Times'?
CREATE TABLE NYT_Investigative(id INT,name VARCHAR(20),age INT,job VARCHAR(20));CREATE TABLE LAT_Investigative(id INT,name VARCHAR(20),age INT,job VARCHAR(20));
SELECT ny.age FROM NYT_Investigative ny JOIN LAT_Investigative lat ON ny.name = lat.name WHERE ny.job = 'investigative journalist' AND lat.job = 'investigative journalist';
Find the top 3 cities with the highest number of cultural heritage tours in Italy.
CREATE TABLE cultural_tours (tour_id INT,name TEXT,city TEXT,country TEXT); INSERT INTO cultural_tours (tour_id,name,city,country) VALUES (1,'Roman Colosseum Tour','Rome','Italy'),(2,'Uffizi Gallery Tour','Florence','Italy'),(3,'Pompeii Tour','Naples','Italy');
SELECT city, COUNT(*) as tour_count FROM cultural_tours WHERE country = 'Italy' GROUP BY city ORDER BY tour_count DESC LIMIT 3;
How many sustainable tourism packages are available in Africa?
CREATE TABLE tourism_packages (package_id INT,type TEXT,region TEXT); INSERT INTO tourism_packages (package_id,type,region) VALUES (1,'Sustainable','Africa'),(2,'Standard','Europe');
SELECT region, COUNT(*) FROM tourism_packages WHERE type = 'Sustainable' AND region = 'Africa';
How many graduate students have enrolled each year, broken down by year?
CREATE TABLE graduate_students (id INT,name VARCHAR(255),gender VARCHAR(10),enrollment_date DATE); INSERT INTO graduate_students (id,name,gender,enrollment_date) VALUES (1,'Ivan','Male','2019-08-24'),(2,'Judy','Female','2020-08-25'),(3,'Kevin','Male','2021-08-26'),(4,'Lily','Female','2021-08-27');
SELECT YEAR(enrollment_date) as year, COUNT(*) as enrollment_count FROM graduate_students GROUP BY year;
List all circular economy initiatives in the 'Agriculture' sector.
CREATE TABLE Sectors (id INT,sector VARCHAR(255)); INSERT INTO Sectors (id,sector) VALUES (1,'Energy'),(2,'Manufacturing'),(3,'Agriculture'); CREATE TABLE Initiatives (id INT,name VARCHAR(255),sector_id INT); INSERT INTO Initiatives (id,name,sector_id) VALUES (1,'ProjectA',1),(2,'ProjectB',2),(3,'ProjectC',3),(4,'ProjectD',3);
SELECT Initiatives.name FROM Initiatives JOIN Sectors ON Initiatives.sector_id = Sectors.id WHERE Sectors.sector = 'Agriculture';
What is the maximum snow depth and minimum wind speed recorded for each location in the past month?
CREATE TABLE WeatherData (Location VARCHAR(100),Date DATE,Depth INT,Speed FLOAT); INSERT INTO WeatherData (Location,Date,Depth,Speed) VALUES ('Location C','2022-06-01',20,15.5); INSERT INTO WeatherData (Location,Date,Depth,Speed) VALUES ('Location D','2022-06-05',25,16.5);
SELECT Location, MAX(Depth) OVER (PARTITION BY Location ORDER BY Location ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS MaxDepth, MIN(Speed) OVER (PARTITION BY Location ORDER BY Location ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS MinSpeed FROM WeatherData WHERE Date >= DATEADD(month, -1, GETDATE());
How many cases were won by attorneys from the 'Doe' law firm?
CREATE TABLE Attorneys (AttorneyID INT,Firm VARCHAR(255)); INSERT INTO Attorneys (AttorneyID,Firm) VALUES (1,'Doe Law Firm'),(2,'Smith Law Firm'),(3,'Doe Law Firm'); CREATE TABLE Cases (CaseID INT,AttorneyID INT,Outcome VARCHAR(255)); INSERT INTO Cases (CaseID,AttorneyID,Outcome) VALUES (101,1,'Won'),(102,1,'Lost'),(103,2,'Won'),(104,3,'Won');
SELECT COUNT(*) FROM Cases INNER JOIN Attorneys ON Cases.AttorneyID = Attorneys.AttorneyID WHERE Attorneys.Firm = 'Doe Law Firm' AND Outcome = 'Won';
What's the number of traditional art performances per city?
CREATE TABLE CityPerformances (City VARCHAR(20),ArtPerformances INT); INSERT INTO CityPerformances VALUES ('New York',3),('Los Angeles',2); CREATE VIEW ArtPerformanceCount AS SELECT City,COUNT(*) AS ArtPerformances FROM CityPerformances GROUP BY City;
SELECT v.City, v.ArtPerformances FROM CityPerformances c JOIN ArtPerformanceCount v ON c.City = v.City;
What is the maximum temperature recorded for each region in the past week?
CREATE TABLE weather_data (id INT,region VARCHAR(255),temperature INT,timestamp TIMESTAMP); INSERT INTO weather_data (id,region,temperature,timestamp) VALUES (1,'North America',25,'2022-01-01 10:00:00'),(2,'South America',30,'2022-01-01 10:00:00');
SELECT region, MAX(temperature) FROM weather_data WHERE timestamp >= DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 WEEK) GROUP BY region;
What is the maximum fare for buses in each city?
CREATE TABLE buses (route_id INT,fare DECIMAL(5,2),city VARCHAR(20)); CREATE TABLE routes (route_id INT,city VARCHAR(20));
SELECT r.city, MAX(b.fare) FROM buses b JOIN routes r ON b.route_id = r.route_id GROUP BY r.city;
How many movies were directed by individuals who identify as Latinx and released after 2010?
CREATE TABLE Directors (id INT,director_name VARCHAR(100),ethnicity VARCHAR(50)); CREATE TABLE Movies (id INT,title VARCHAR(100),director_id INT,release_year INT); INSERT INTO Directors (id,director_name,ethnicity) VALUES (1,'Director1','Latinx'),(2,'Director2','African American'),(3,'Director3','Caucasian'); INSERT INTO Movies (id,title,director_id,release_year) VALUES (1,'Movie1',1,2011),(2,'Movie2',1,2013),(3,'Movie3',2,2015),(4,'Movie4',3,2017);
SELECT COUNT(*) FROM Movies WHERE director_id IN (SELECT id FROM Directors WHERE ethnicity = 'Latinx') AND release_year > 2010;
What is the maximum altitude reached by the 'Hubble Space Telescope'?
CREATE TABLE AstrophysicsResearch (id INT,spacecraft VARCHAR(255),altitude FLOAT); INSERT INTO AstrophysicsResearch (id,spacecraft,altitude) VALUES (1,'Hubble Space Telescope',569000000.0),(2,'Spitzer Space Telescope',548000000.0);
SELECT MAX(altitude) FROM AstrophysicsResearch WHERE spacecraft = 'Hubble Space Telescope';
Who is the top garment manufacturer by quantity sold in 'Africa' in Q3 2022?
CREATE TABLE africa_sales(manufacturer VARCHAR(50),location VARCHAR(20),quantity INT,sale_date DATE); INSERT INTO africa_sales (manufacturer,location,quantity,sale_date) VALUES ('EcoStitch','Africa',150,'2022-07-01'); INSERT INTO africa_sales (manufacturer,location,quantity,sale_date) VALUES ('GreenThreads','Africa',120,'2022-07-02');
SELECT manufacturer, SUM(quantity) as total_quantity FROM africa_sales WHERE location = 'Africa' AND sale_date BETWEEN '2022-07-01' AND '2022-09-30' GROUP BY manufacturer ORDER BY total_quantity DESC LIMIT 1;
Delete records of employees who left the company
CREATE TABLE Employees (EmployeeID INT,FirstName VARCHAR(50),LastName VARCHAR(50),Department VARCHAR(50),Salary DECIMAL(10,2),LeftCompany BOOLEAN);
DELETE FROM Employees WHERE LeftCompany = TRUE;
Create a table for public awareness campaigns
CREATE TABLE public_awareness_campaigns (id INT PRIMARY KEY,name VARCHAR(255),description TEXT,start_date DATE,end_date DATE);
CREATE TABLE public_awareness_campaigns (id INT PRIMARY KEY, name VARCHAR(255), description TEXT, start_date DATE, end_date DATE);
Identify the win rate of players based on the champion they use in LoL
CREATE TABLE lolgames (game_id INT,champion VARCHAR(50),winner BOOLEAN); INSERT INTO lolgames (game_id,champion,winner) VALUES (1,'Ashe',true);
SELECT champion, AVG(winner) as win_rate, RANK() OVER (ORDER BY AVG(winner) DESC) as rank FROM lolgames GROUP BY champion
What is the average network latency for each country?
CREATE TABLE network (network_id INT,country VARCHAR(255),latency INT); INSERT INTO network (network_id,country,latency) VALUES (1,'US',30),(2,'Canada',40),(3,'Mexico',50),(4,'Brazil',60);
SELECT country, AVG(latency) as avg_latency FROM network GROUP BY country;
What is the oldest contemporary art piece?
CREATE TABLE ArtPieces (id INT,title VARCHAR(50),galleryId INT,year INT,style VARCHAR(20)); INSERT INTO ArtPieces (id,title,galleryId,year,style) VALUES (1,'Piece 1',1,2000,'Modern'),(2,'Piece 2',1,2010,'Contemporary'),(3,'Piece 3',2,2020,'Contemporary'),(4,'Piece 4',3,1990,'Modern'),(5,'Piece 5',NULL,1874,'Impressionism');
SELECT title, year FROM ArtPieces WHERE style = 'Contemporary' AND year = (SELECT MIN(year) FROM ArtPieces WHERE style = 'Contemporary') LIMIT 1;
List all hospitals in rural areas
CREATE TABLE rural_hospitals(hospital_id INT PRIMARY KEY,name VARCHAR(255),bed_count INT,rural_urban_classification VARCHAR(50))
SELECT * FROM rural_hospitals WHERE rural_urban_classification = 'Rural'
List the total number of gold medals won by athletes from the United States in the olympic_athletes table.
CREATE TABLE olympic_athletes (athlete_id INT,name VARCHAR(50),sport VARCHAR(20),country VARCHAR(50),gold_medals INT); INSERT INTO olympic_athletes (athlete_id,name,sport,country,gold_medals) VALUES (1,'Usain Bolt','Track and Field','Jamaica',8); INSERT INTO olympic_athletes (athlete_id,name,sport,country,gold_medals) VALUES (2,'Michael Phelps','Swimming','USA',23);
SELECT SUM(gold_medals) FROM olympic_athletes WHERE country = 'USA';
What is the number of volunteers and total hours volunteered for each program?
CREATE TABLE volunteers (id INT,name TEXT,program TEXT,hours_volunteered INT);
SELECT program, COUNT(*), SUM(hours_volunteered) FROM volunteers GROUP BY program;
What is the maximum age of members who have a 'Basic' membership?
CREATE TABLE Members (MemberID INT,Age INT,MembershipType VARCHAR(10)); INSERT INTO Members (MemberID,Age,MembershipType) VALUES (1,35,'Premium'),(2,28,'Basic'),(3,42,'Premium'),(4,22,'Basic'),(5,55,'Premium');
SELECT MAX(Age) FROM Members WHERE MembershipType = 'Basic';
What is the total number of employees in the 'mining_operations' table, grouped by their job titles, who were hired after 2010?
CREATE TABLE mining_operations (id INT,name VARCHAR(50),job_title VARCHAR(50),hire_date DATE); INSERT INTO mining_operations (id,name,job_title,hire_date) VALUES (1,'John Doe','Miner','2011-01-01'); INSERT INTO mining_operations (id,name,job_title,hire_date) VALUES (2,'Jane Smith','Engineer','2015-05-15');
SELECT job_title, COUNT(*) FROM mining_operations WHERE hire_date >= '2010-01-01' GROUP BY job_title;
Show the trend of approved and rejected socially responsible lending applications in the last 6 months.
CREATE TABLE lending_trend (application_date DATE,approved BOOLEAN); INSERT INTO lending_trend (application_date,approved) VALUES ('2021-04-02',FALSE),('2021-05-15',TRUE),('2021-06-01',FALSE),('2021-07-01',TRUE),('2021-08-15',FALSE),('2021-09-01',TRUE),('2021-10-15',FALSE),('2021-11-01',TRUE),('2021-12-15',FALSE);
SELECT MONTH(application_date) as month, YEAR(application_date) as year, SUM(approved) as num_approved, SUM(NOT approved) as num_rejected FROM lending_trend WHERE application_date >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH) GROUP BY YEAR(application_date), MONTH(application_date);
What is the average weight of spacecraft components manufactured by SpaceTech in France?
CREATE TABLE spacecraft_components (id INT,company VARCHAR(255),country VARCHAR(255),component_type VARCHAR(255),weight FLOAT); INSERT INTO spacecraft_components (id,company,country,component_type,weight) VALUES (1,'SpaceTech','France','Propulsion System',500.0),(2,'SpaceTech','France','Structure',3000.0);
SELECT AVG(weight) FROM spacecraft_components WHERE company = 'SpaceTech' AND country = 'France';
What is the current landfill capacity in Texas and the projected capacity in 2030?
CREATE TABLE landfill_capacity (location VARCHAR(50),current_capacity INT,projected_capacity INT,year INT); INSERT INTO landfill_capacity (location,current_capacity,projected_capacity,year) VALUES ('Texas',50000,60000,2030);
SELECT location, current_capacity, projected_capacity FROM landfill_capacity WHERE location = 'Texas' AND year = 2030;
How many health equity metric evaluations were conducted in each state over the past six months?
CREATE TABLE HealthEquityMetrics (EvaluationID INT,State VARCHAR(255),EvaluationDate DATE); INSERT INTO HealthEquityMetrics (EvaluationID,State,EvaluationDate) VALUES (1,'California','2022-01-10'),(2,'Texas','2022-03-15'),(3,'New York','2022-05-05'),(4,'Florida','2022-07-01'),(5,'Illinois','2022-09-12');
SELECT State, COUNT(*) as EvaluationCount FROM HealthEquityMetrics WHERE EvaluationDate >= DATEADD(month, -6, GETDATE()) GROUP BY State;
What is the average temperature per month and location in 'weather' table?
CREATE TABLE weather (location VARCHAR(50),temperature INT,record_date DATE); INSERT INTO weather VALUES ('Seattle',45,'2022-01-01'); INSERT INTO weather VALUES ('Seattle',50,'2022-02-01'); INSERT INTO weather VALUES ('Seattle',55,'2022-03-01'); INSERT INTO weather VALUES ('New York',30,'2022-01-01'); INSERT INTO weather VALUES ('New York',35,'2022-02-01'); INSERT INTO weather VALUES ('New York',40,'2022-03-01');
SELECT location, EXTRACT(MONTH FROM record_date) AS month, AVG(temperature) AS avg_temp FROM weather GROUP BY location, month;
List the top 3 cuisines with the highest average calorie content?
CREATE TABLE Dishes (DishID INT,DishName VARCHAR(50),Cuisine VARCHAR(50),Calories INT); INSERT INTO Dishes (DishID,DishName,Cuisine,Calories) VALUES (1,'Hummus','Mediterranean',250),(2,'Falafel','Mediterranean',350),(3,'Pizza','Italian',800),(4,'Pasta','Italian',700),(5,'Burger','American',600),(6,'Fries','American',400);
SELECT Cuisine, AVG(Calories) FROM Dishes GROUP BY Cuisine ORDER BY AVG(Calories) DESC LIMIT 3;
What is the total revenue generated from music streaming for a specific artist?
CREATE TABLE StreamingData (StreamID INT,UserID INT,SongID INT,StreamDate DATE,Revenue DECIMAL(10,2)); INSERT INTO StreamingData VALUES (1,1,1001,'2022-01-01',0.10); INSERT INTO StreamingData VALUES (2,2,1002,'2022-01-02',0.15); CREATE TABLE Songs (SongID INT,SongName VARCHAR(100),ArtistID INT); INSERT INTO Songs VALUES (1001,'Shake It Off',1); INSERT INTO Songs VALUES (1002,'Dynamite',1);
SELECT SUM(Revenue) FROM StreamingData JOIN Songs ON StreamingData.SongID = Songs.SongID WHERE Songs.ArtistID = 1;
What are the conservation statuses of marine species that are unique to the Southern Ocean?
CREATE TABLE marine_species_status (id INT,species_name VARCHAR(255),conservation_status VARCHAR(255)); INSERT INTO marine_species_status (id,species_name,conservation_status) VALUES (1,'Blue Whale','Endangered'); CREATE TABLE oceanography (id INT,species_name VARCHAR(255),location VARCHAR(255)); INSERT INTO oceanography (id,species_name,location) VALUES (1,'Blue Whale','Southern Ocean');
SELECT conservation_status FROM marine_species_status WHERE species_name NOT IN (SELECT species_name FROM oceanography WHERE location IN ('Atlantic Ocean', 'Pacific Ocean', 'Indian Ocean', 'Arctic Ocean')) AND species_name IN (SELECT species_name FROM oceanography WHERE location = 'Southern Ocean');
What is the total calorie count for dishes that contain both meat and dairy products?
CREATE TABLE Dishes (DishID INT,DishName VARCHAR(50),Type VARCHAR(20),Calories INT); INSERT INTO Dishes (DishID,DishName,Type,Calories) VALUES (1,'Beef Lasagna','Meat-dairy',800),(2,'Cheese Pizza','Dairy',600),(3,'Chicken Caesar Salad','Meat-dairy',500),(4,'Veggie Pizza','Dairy',700);
SELECT SUM(Calories) FROM Dishes WHERE Type = 'Meat-dairy';
List all volunteers who have participated in programs in both New York and California, along with their contact information.
CREATE TABLE Volunteers (VolunteerID INT,FirstName TEXT,LastName TEXT,Country TEXT); INSERT INTO Volunteers (VolunteerID,FirstName,LastName,Country) VALUES (1,'Alice','Williams','USA'),(2,'Bob','Jones','USA'),(3,'Charlie','Brown','USA'); CREATE TABLE VolunteerPrograms (VolunteerID INT,ProgramID INT,Location TEXT); INSERT INTO VolunteerPrograms (VolunteerID,ProgramID,Location) VALUES (1,101,'NY'),(1,102,'CA'),(2,101,'NY'),(3,102,'CA');
SELECT V.FirstName, V.LastName, V.Country FROM Volunteers V INNER JOIN VolunteerPrograms VP1 ON V.VolunteerID = VP1.VolunteerID AND VP1.Location = 'NY' INNER JOIN VolunteerPrograms VP2 ON V.VolunteerID = VP2.VolunteerID AND VP2.Location = 'CA';
Which countries have participated in more than 5 military innovation projects with the USA since 2010?
CREATE TABLE military_innovation (innovation_id INT,country1 TEXT,country2 TEXT,project TEXT,start_date DATE,end_date DATE); INSERT INTO military_innovation (innovation_id,country1,country2,project,start_date,end_date) VALUES (1,'USA','UK','Stealth Coating','2010-01-01','2012-12-31'),(2,'USA','Germany','AI-Driven Drones','2015-01-01','2017-12-31');
SELECT military_innovation.country2, COUNT(military_innovation.innovation_id) as project_count FROM military_innovation WHERE military_innovation.country1 = 'USA' AND military_innovation.start_date >= '2010-01-01' GROUP BY military_innovation.country2 HAVING project_count > 5;
Insert a new training record into the "training" table
CREATE TABLE training (id INT,employee_id INT,course_name VARCHAR(50),completed_date DATE);
INSERT INTO training (id, employee_id, course_name, completed_date) VALUES (1001, 101, 'Python Programming', '2022-07-15');
What is the average carbon footprint of flights from the USA to Asia?
CREATE TABLE flights (flight_id INT,airline TEXT,origin TEXT,destination TEXT,distance INT,co2_emission INT); INSERT INTO flights (flight_id,airline,origin,destination,distance,co2_emission) VALUES (1,'Delta','USA','China',12000,900),(2,'Air China','China','USA',12000,900);
SELECT AVG(co2_emission) FROM flights WHERE origin = 'USA' AND destination LIKE 'Asia%';
What is the average number of comments per post in the 'social_media' database?
CREATE TABLE posts (id INT,user_id INT,content TEXT,timestamp TIMESTAMP,comments INT);
SELECT AVG(COUNT(posts.comments)) AS avg_comments_per_post FROM posts GROUP BY posts.id;
Find the number of sustainable tourism businesses in New Zealand in 2020.
CREATE TABLE sustainable_tourism (country VARCHAR(20),year INT,num_businesses INT); INSERT INTO sustainable_tourism (country,year,num_businesses) VALUES ('New Zealand',2020,3500),('Australia',2020,5000);
SELECT num_businesses FROM sustainable_tourism WHERE country = 'New Zealand' AND year = 2020;
What is the total number of high severity vulnerabilities reported in the financial sector?
CREATE TABLE vulnerabilities (id INT,sector VARCHAR(255),severity VARCHAR(255)); INSERT INTO vulnerabilities (id,sector,severity) VALUES (1,'financial','high'),(2,'healthcare','medium'),(3,'financial','low');
SELECT COUNT(*) FROM vulnerabilities WHERE sector = 'financial' AND severity = 'high';
What is the total cost of SpaceX's Starship program?
CREATE TABLE ProjectCosts (id INT,project VARCHAR(100),company VARCHAR(100),cost FLOAT); INSERT INTO ProjectCosts (id,project,company,cost) VALUES (1,'Starship','SpaceX',10000000); INSERT INTO ProjectCosts (id,project,company,cost) VALUES (2,'Raptor Engine','SpaceX',2000000);
SELECT SUM(cost) FROM ProjectCosts WHERE project = 'Starship' AND company = 'SpaceX';
Insert a new sustainable attraction in Canada into the attractions table.
CREATE TABLE attractions (id INT,name TEXT,country TEXT,sustainable BOOLEAN);
INSERT INTO attractions (name, country, sustainable) VALUES ('Niagara Falls Eco-Park', 'Canada', 'true');
What is the average production cost of clothing items made with organic cotton?
CREATE TABLE OrganicCottonClothing (id INT,production_cost DECIMAL(5,2)); INSERT INTO OrganicCottonClothing VALUES (1,25.50),(2,30.00),(3,28.75);
SELECT AVG(production_cost) FROM OrganicCottonClothing;
What is the total number of female farmers who have received training in Ghana?
CREATE TABLE farmers (id INT,name VARCHAR(100),gender VARCHAR(10),training_completed INT,country VARCHAR(50)); INSERT INTO farmers (id,name,gender,training_completed,country) VALUES (1,'Abena','female',1,'Ghana');
SELECT SUM(training_completed) FROM farmers WHERE gender = 'female' AND country = 'Ghana';
What is the average ticket price for each team's home games, ordered by the highest average price?
CREATE TABLE Teams (TeamID INT,TeamName VARCHAR(50),Stadium VARCHAR(50)); INSERT INTO Teams (TeamID,TeamName,Stadium) VALUES (1,'TeamA','StadiumA'),(2,'TeamB','StadiumB'); CREATE TABLE Games (GameID INT,TeamID INT,TicketPrice DECIMAL(5,2)); INSERT INTO Games (GameID,TeamID,TicketPrice) VALUES (1,1,50.00),(2,1,55.00),(3,2,45.00),(4,2,50.00);
SELECT TeamID, AVG(TicketPrice) as AvgTicketPrice FROM Games GROUP BY TeamID ORDER BY AvgTicketPrice DESC;
What are the names and budgets of projects in 'Asia' with a budget greater than 1000000.00?
CREATE TABLE projects (id INT PRIMARY KEY,name VARCHAR(50),location VARCHAR(50),budget FLOAT); INSERT INTO projects (id,name,location,budget) VALUES (1,'Solar Farm Construction','Brazil',900000.00); INSERT INTO projects (id,name,location,budget) VALUES (2,'Wind Turbine Installation','Canada',750000.00); INSERT INTO projects (id,name,location,budget) VALUES (3,'Hydroelectric Dam Construction','China',1500000.00);
SELECT projects.name, projects.location, projects.budget FROM projects WHERE projects.location = 'Asia' AND projects.budget > 1000000.00;
List all space missions that include astronauts from the US and China with their medical records' last_checkup date.
CREATE TABLE SpaceMissions (mission_name VARCHAR(255),astronaut_id INT); CREATE TABLE AstronautMedicalData (astronaut_id INT,last_checkup DATE,country VARCHAR(255)); INSERT INTO SpaceMissions (mission_name,astronaut_id) VALUES ('Artemis I',1001),('Artemis I',1002),('Shenzhou 9',2001); INSERT INTO AstronautMedicalData (astronaut_id,last_checkup,country) VALUES (1001,'2022-01-01','US'),(1002,'2022-02-01','US'),(2001,'2022-03-01','China');
SELECT SpaceMissions.mission_name, AstronautMedicalData.last_checkup FROM SpaceMissions INNER JOIN AstronautMedicalData ON SpaceMissions.astronaut_id = AstronautMedicalData.astronaut_id WHERE AstronautMedicalData.country = 'US' OR AstronautMedicalData.country = 'China';
What is the maximum weekly working hours for female workers?
CREATE TABLE WorkingHoursData (EmployeeID INT,Gender VARCHAR(10),WeeklyHours DECIMAL(10,2)); INSERT INTO WorkingHoursData (EmployeeID,Gender,WeeklyHours) VALUES (1,'Female',40.00),(2,'Male',45.00),(3,'Female',50.00);
SELECT MAX(WeeklyHours) FROM WorkingHoursData WHERE Gender = 'Female';
What is the name and location of the top 3 heritage sites with the highest number of visitors in the Native American culture domain?
CREATE TABLE HeritageSites (SiteID int,SiteName varchar(255),SiteLocation varchar(255),CultureDomain varchar(255)); INSERT INTO HeritageSites (SiteID,SiteName,SiteLocation,CultureDomain) VALUES (1,'Mesa Verde National Park','Colorado,USA','Native American');
SELECT SiteName, SiteLocation FROM HeritageSites WHERE CultureDomain = 'Native American' ORDER BY COUNT(*) DESC LIMIT 3;
Find the average number of tickets sold and total number of home games played by the 'Golden State Warriors' in the 'Pacific' division for the year 2020. Assume the 'games' table has columns 'team_name', 'sale_year', 'num_tickets_sold', 'is_home_game'.
CREATE TABLE TEAMS (team_name VARCHAR(50),division VARCHAR(50)); INSERT INTO TEAMS (team_name,division) VALUES ('Golden State Warriors','Pacific'); CREATE TABLE games (team_name VARCHAR(50),sale_year INT,num_tickets_sold INT,is_home_game BOOLEAN); INSERT INTO games (team_name,sale_year,num_tickets_sold,is_home_game) VALUES ('Golden State Warriors',2020,20000,TRUE);
SELECT AVG(num_tickets_sold), COUNT(*) FROM games WHERE team_name = 'Golden State Warriors' AND sale_year = 2020 AND is_home_game = TRUE AND division = (SELECT division FROM TEAMS WHERE team_name = 'Golden State Warriors');
How many different types of sustainable fabrics are used in Paris?
CREATE TABLE FABRICS(city VARCHAR(20),fabric VARCHAR(20)); INSERT INTO FABRICS(city,fabric) VALUES('Paris','Organic Cotton'),('Paris','Tencel'),('Paris','Hemp'),('Rome','Polyester'),('Rome','Viscose');
SELECT COUNT(DISTINCT fabric) FROM FABRICS WHERE city = 'Paris';
What is the total number of marine species in the Atlantic Ocean that are affected by maritime safety issues?
CREATE TABLE marine_species (id INT,name TEXT,ocean TEXT,affected_by_safety_issues BOOLEAN); INSERT INTO marine_species (id,name,ocean,affected_by_safety_issues) VALUES (1,'Krill','Southern',TRUE),(2,'Blue Whale','Atlantic',FALSE),(3,'Penguin','Southern',TRUE),(4,'Squid','Atlantic',TRUE);
SELECT COUNT(*) FROM marine_species WHERE ocean = 'Atlantic' AND affected_by_safety_issues = TRUE;
What is the total number of hours contributed by volunteers to the 'Art Therapy' program?
CREATE TABLE volunteers (id INT PRIMARY KEY,name VARCHAR(50),hours_contributed INT,contribution_year INT); CREATE TABLE projects (id INT PRIMARY KEY,project_name VARCHAR(50),project_type VARCHAR(50));
SELECT SUM(hours_contributed) AS total_volunteer_hours FROM volunteers INNER JOIN projects ON volunteers.id = projects.id WHERE project_type = 'Art Therapy';
How many impact investments were made by Blue Capital in regions with high poverty rates?
CREATE TABLE Blue_Capital (id INT,region VARCHAR(20),impact_investment FLOAT); INSERT INTO Blue_Capital (id,region,impact_investment) VALUES (1,'Africa',200000),(2,'Asia',300000);
SELECT SUM(impact_investment) FROM Blue_Capital WHERE region IN ('Africa', 'Asia');
Add a new 'PollutionSources' table with 3 columns and insert 3 records
CREATE TABLE PollutionSources (id INT,source_name VARCHAR(50),location VARCHAR(50),type VARCHAR(50));
INSERT INTO PollutionSources (id, source_name, location, type) VALUES (1, 'Oil Rig A', 'Atlantic Ocean', 'Oil Spill'), (2, 'Factory Plant B', 'Pacific Ocean', 'Plastic Waste'), (3, 'Research Vessel C', 'Indian Ocean', 'Chemical Leakage');
What is the minimum training cost?
CREATE TABLE Trainings (TrainingID INT,Department VARCHAR(20),Cost FLOAT); INSERT INTO Trainings (TrainingID,Department,Cost) VALUES (1,'Sales',5000),(2,'IT',7000),(3,'Sales',6000),(4,'HR',4000);
SELECT MIN(Cost) FROM Trainings;
Find biosensor technology development projects in Southeast Asia.
CREATE TABLE biosensor_tech (id INT,project_name VARCHAR(100),location VARCHAR(50)); INSERT INTO biosensor_tech (id,project_name,location) VALUES (1,'BioSense X','Southeast Asia'); INSERT INTO biosensor_tech (id,project_name,location) VALUES (2,'Genomic Y','North America'); INSERT INTO biosensor_tech (id,project_name,location) VALUES (3,'BioMarker Z','Europe');
SELECT * FROM biosensor_tech WHERE location = 'Southeast Asia';
Update the salaries for workers in the 'TextileWorkers' table who have completed an apprenticeship program by 5%
CREATE TABLE TextileWorkers (WorkerID INT,Salary DECIMAL(5,2),ApprenticeshipProgram BOOLEAN);
UPDATE TextileWorkers SET Salary = Salary * 1.05 WHERE ApprenticeshipProgram = TRUE;
What is the average grant amount for a specific organization in a given year?
CREATE TABLE Grants (GrantID INT,OrgID INT,Amount FLOAT,GrantDate DATE); INSERT INTO Grants (GrantID,OrgID,Amount,GrantDate) VALUES (1,3,15000.00,'2020-01-01');
SELECT OrgID, AVG(Amount) FROM Grants WHERE YEAR(GrantDate) = 2020 AND OrgID = 3;
Delete all records from the flight_safety table where the last_inspection_date is before 2015-01-01
CREATE TABLE flight_safety (flight_number VARCHAR(50) PRIMARY KEY,safety_rating VARCHAR(20),last_inspection_date DATE);
DELETE FROM flight_safety WHERE last_inspection_date < '2015-01-01';
What is the average co-ownership cost per square foot in the 'urban_sustainability' table, ordered by cost?
CREATE TABLE urban_sustainability (id INT,city VARCHAR(255),co_ownership_cost DECIMAL(10,2),size INT); INSERT INTO urban_sustainability (id,city,co_ownership_cost,size) VALUES (1,'Seattle',550000,1200),(2,'Portland',420000,1500);
SELECT AVG(co_ownership_cost / size) OVER (ORDER BY co_ownership_cost) AS avg_cost_per_sqft FROM urban_sustainability;
What's the total waste generation in the 'urban' region for 2020?
CREATE TABLE waste_generation(region VARCHAR(10),year INT,amount INT); INSERT INTO waste_generation VALUES('urban',2019,1500),('urban',2020,1800),('rural',2019,800),('rural',2020,900);
SELECT SUM(amount) FROM waste_generation WHERE region = 'urban' AND year = 2020;
What is the total amount of research grants awarded to graduate students in the 'Electrical Engineering' department?
CREATE TABLE Students (StudentID int,Department varchar(50)); INSERT INTO Students (StudentID,Department) VALUES (1,'Computer Science'); INSERT INTO Students (StudentID,Department) VALUES (2,'Electrical Engineering'); CREATE TABLE Grants (GrantID int,StudentID int,Amount int); INSERT INTO Grants (GrantID,StudentID,Amount) VALUES (1,1,1000); INSERT INTO Grants (GrantID,StudentID,Amount) VALUES (2,2,2000);
SELECT SUM(Grants.Amount) FROM Students INNER JOIN Grants ON Students.StudentID = Grants.StudentID WHERE Students.Department = 'Electrical Engineering';
Determine the market share of each drug in a specific sales region.
CREATE TABLE sales_data (drug_name TEXT,region TEXT,sales INTEGER);
SELECT drug_name, SUM(sales) OVER (PARTITION BY region) / SUM(SUM(sales)) OVER () AS market_share FROM sales_data WHERE region = 'RegionA' GROUP BY drug_name;
Who is the manufacturer of 'DrugD'?
CREATE TABLE drug_info (drug_name TEXT,manufacturer TEXT);
SELECT manufacturer FROM drug_info WHERE drug_name = 'DrugD';
What is the distribution of healthcare facilities by type and patients served, for facilities serving over 7000 patients?
CREATE TABLE public.healthcare_access (id SERIAL PRIMARY KEY,state TEXT,city TEXT,facility_type TEXT,patients_served INT,rating INT); INSERT INTO public.healthcare_access (state,city,facility_type,patients_served,rating) VALUES ('California','San Francisco','Urgent Care',6000,6),('New York','New York City','Hospital',15000,9),('California','Los Angeles','Clinic',7500,7);
SELECT facility_type, patients_served, COUNT(*) FROM public.healthcare_access WHERE patients_served > 7000 GROUP BY facility_type, patients_served;
What is the total number of basketball games played by the Knicks at Madison Square Garden?
CREATE TABLE teams (team_id INT,team_name VARCHAR(255)); INSERT INTO teams (team_id,team_name) VALUES (1,'Knicks'); CREATE TABLE venues (venue_id INT,venue_name VARCHAR(255)); INSERT INTO venues (venue_id,venue_name) VALUES (1,'Madison Square Garden'); CREATE TABLE games (game_id INT,team_id INT,venue_id INT,game_date DATE); INSERT INTO games (game_id,team_id,venue_id,game_date) VALUES (1,1,1,'2020-01-01');
SELECT COUNT(*) FROM games INNER JOIN teams ON games.team_id = teams.team_id INNER JOIN venues ON games.venue_id = venues.venue_id WHERE teams.team_name = 'Knicks' AND venues.venue_name = 'Madison Square Garden';