db_id
stringlengths
4
28
question
stringlengths
24
325
evidence
stringlengths
0
673
SQL
stringlengths
23
804
schema
stringlengths
352
37.3k
music_platform_2
Of the arts-books and arts-design categories, which one has more podcasts and what is the numerical difference between them?
arts-books' and 'arts-design' are category; numerical difference = Subtract(Count(podcast_id(category = 'arts-books')), Count(podcast_id(category = 'arts-design'))); one has much more podcast refers to Max(Count(podcast_id))
SELECT ( SELECT category FROM categories WHERE category = 'arts-books' OR category = 'arts-design' GROUP BY category ORDER BY COUNT(podcast_id) DESC LIMIT 1 ) "has more podcasts" , ( SELECT SUM(CASE WHEN category = 'arts-books' THEN 1 ELSE 0 END) - SUM(CASE WHEN category = 'arts-design' THEN 1 ELSE 0 END) FROM categories ) "differenct BETWEEN arts-books and arts-design"
CREATE TABLE runs ( run_at text not null, max_rowid integer not null, reviews_added integer not null ); CREATE TABLE podcasts ( podcast_id text primary key, itunes_id integer not null, slug text not null, itunes_url text not null, title text not null ); CREATE TABLE IF NOT EXISTS "reviews" ( podcast_id TEXT not null constraint reviews_podcasts_podcast_id_fk references podcasts, title TEXT not null, content TEXT not null, rating INTEGER not null, author_id TEXT not null, created_at TEXT not null ); CREATE TABLE IF NOT EXISTS "categories" ( podcast_id TEXT not null constraint categories_podcasts_podcast_id_fk references podcasts, category TEXT not null, constraint "PRIMARY" primary key (podcast_id, category) ); CREATE INDEX category_podcast_id_idx on categories (podcast_id);
movies_4
List down the movies produced by Lucasfilm.
movies refers to title; produced by Lucasfil refers to company_name = 'Lucasfilm'
SELECT T3.title FROM production_company AS T1 INNER JOIN movie_company AS T2 ON T1.company_id = T2.company_id INNER JOIN movie AS T3 ON T2.movie_id = T3.movie_id WHERE T1.company_name = 'Lucasfilm'
CREATE TABLE country ( country_id INTEGER not null primary key, country_iso_code TEXT default NULL, country_name TEXT default NULL ); CREATE TABLE department ( department_id INTEGER not null primary key, department_name TEXT default NULL ); CREATE TABLE gender ( gender_id INTEGER not null primary key, gender TEXT default NULL ); CREATE TABLE genre ( genre_id INTEGER not null primary key, genre_name TEXT default NULL ); CREATE TABLE keyword ( keyword_id INTEGER not null primary key, keyword_name TEXT default NULL ); CREATE TABLE language ( language_id INTEGER not null primary key, language_code TEXT default NULL, language_name TEXT default NULL ); CREATE TABLE language_role ( role_id INTEGER not null primary key, language_role TEXT default NULL ); CREATE TABLE movie ( movie_id INTEGER not null primary key, title TEXT default NULL, budget INTEGER default NULL, homepage TEXT default NULL, overview TEXT default NULL, popularity REAL default NULL, release_date DATE default NULL, revenue INTEGER default NULL, runtime INTEGER default NULL, movie_status TEXT default NULL, tagline TEXT default NULL, vote_average REAL default NULL, vote_count INTEGER default NULL ); CREATE TABLE movie_genres ( movie_id INTEGER default NULL, genre_id INTEGER default NULL, foreign key (genre_id) references genre(genre_id), foreign key (movie_id) references movie(movie_id) ); CREATE TABLE movie_languages ( movie_id INTEGER default NULL, language_id INTEGER default NULL, language_role_id INTEGER default NULL, foreign key (language_id) references language(language_id), foreign key (movie_id) references movie(movie_id), foreign key (language_role_id) references language_role(role_id) ); CREATE TABLE person ( person_id INTEGER not null primary key, person_name TEXT default NULL ); CREATE TABLE movie_crew ( movie_id INTEGER default NULL, person_id INTEGER default NULL, department_id INTEGER default NULL, job TEXT default NULL, foreign key (department_id) references department(department_id), foreign key (movie_id) references movie(movie_id), foreign key (person_id) references person(person_id) ); CREATE TABLE production_company ( company_id INTEGER not null primary key, company_name TEXT default NULL ); CREATE TABLE production_country ( movie_id INTEGER default NULL, country_id INTEGER default NULL, foreign key (country_id) references country(country_id), foreign key (movie_id) references movie(movie_id) ); CREATE TABLE movie_cast ( movie_id INTEGER default NULL, person_id INTEGER default NULL, character_name TEXT default NULL, gender_id INTEGER default NULL, cast_order INTEGER default NULL, foreign key (gender_id) references gender(gender_id), foreign key (movie_id) references movie(movie_id), foreign key (person_id) references person(person_id) ); CREATE TABLE IF NOT EXISTS "movie_keywords" ( movie_id INTEGER default NULL references movie, keyword_id INTEGER default NULL references keyword ); CREATE TABLE IF NOT EXISTS "movie_company" ( movie_id INTEGER default NULL references movie, company_id INTEGER default NULL references production_company );
movielens
Among the action movies from the USA, how many of them are not in English?
USA is a country; not in English can be represented by isEnglish = 'F'
SELECT COUNT(T1.movieid) FROM movies AS T1 INNER JOIN movies2directors AS T2 ON T1.movieid = T2.movieid WHERE T1.country = 'USA' AND T1.isEnglish = 'F' AND T2.genre = 'Action'
CREATE TABLE users ( userid INTEGER default 0 not null primary key, age TEXT not null, u_gender TEXT not null, occupation TEXT not null ); CREATE TABLE IF NOT EXISTS "directors" ( directorid INTEGER not null primary key, d_quality INTEGER not null, avg_revenue INTEGER not null ); CREATE INDEX avg_revenue on directors (avg_revenue); CREATE INDEX d_quality on directors (d_quality); CREATE TABLE IF NOT EXISTS "actors" ( actorid INTEGER not null primary key, a_gender TEXT not null, a_quality INTEGER not null ); CREATE TABLE IF NOT EXISTS "movies" ( movieid INTEGER default 0 not null primary key, year INTEGER not null, isEnglish TEXT not null, country TEXT not null, runningtime INTEGER not null ); CREATE TABLE IF NOT EXISTS "movies2actors" ( movieid INTEGER not null references movies on update cascade on delete cascade, actorid INTEGER not null references actors on update cascade on delete cascade, cast_num INTEGER not null, primary key (movieid, actorid) ); CREATE TABLE IF NOT EXISTS "movies2directors" ( movieid INTEGER not null references movies on update cascade on delete cascade, directorid INTEGER not null references directors on update cascade on delete cascade, genre TEXT not null, primary key (movieid, directorid) ); CREATE TABLE IF NOT EXISTS "u2base" ( userid INTEGER default 0 not null references users on update cascade on delete cascade, movieid INTEGER not null references movies on update cascade on delete cascade, rating TEXT not null, primary key (userid, movieid) );
public_review_platform
How long does Yelp_Business no.1 open on Tuesdays?
"How long" and "how much time" are synonyms; how much time does this business open refers to subtract(closing_time, opening_time); Yelp_Business no.1 refers to business_id = 1; Tuesdays refers to day_of_week = 'Tuesday'
SELECT T1.closing_time - T1.opening_time AS "opening hours" FROM Business_Hours AS T1 INNER JOIN Days AS T2 ON T1.day_id = T2.day_id WHERE T2.day_of_week LIKE 'Tuesday' AND T1.business_id = 1
CREATE TABLE Attributes ( attribute_id INTEGER constraint Attributes_pk primary key, attribute_name TEXT ); CREATE TABLE Categories ( category_id INTEGER constraint Categories_pk primary key, category_name TEXT ); CREATE TABLE Compliments ( compliment_id INTEGER constraint Compliments_pk primary key, compliment_type TEXT ); CREATE TABLE Days ( day_id INTEGER constraint Days_pk primary key, day_of_week TEXT ); CREATE TABLE Years ( year_id INTEGER constraint Years_pk primary key, actual_year INTEGER ); CREATE TABLE IF NOT EXISTS "Business_Attributes" ( attribute_id INTEGER constraint Business_Attributes_Attributes_attribute_id_fk references Attributes, business_id INTEGER constraint Business_Attributes_Business_business_id_fk references Business, attribute_value TEXT, constraint Business_Attributes_pk primary key (attribute_id, business_id) ); CREATE TABLE IF NOT EXISTS "Business_Categories" ( business_id INTEGER constraint Business_Categories_Business_business_id_fk references Business, category_id INTEGER constraint Business_Categories_Categories_category_id_fk references Categories, constraint Business_Categories_pk primary key (business_id, category_id) ); CREATE TABLE IF NOT EXISTS "Business_Hours" ( business_id INTEGER constraint Business_Hours_Business_business_id_fk references Business, day_id INTEGER constraint Business_Hours_Days_day_id_fk references Days, opening_time TEXT, closing_time TEXT, constraint Business_Hours_pk primary key (business_id, day_id) ); CREATE TABLE IF NOT EXISTS "Checkins" ( business_id INTEGER constraint Checkins_Business_business_id_fk references Business, day_id INTEGER constraint Checkins_Days_day_id_fk references Days, label_time_0 TEXT, label_time_1 TEXT, label_time_2 TEXT, label_time_3 TEXT, label_time_4 TEXT, label_time_5 TEXT, label_time_6 TEXT, label_time_7 TEXT, label_time_8 TEXT, label_time_9 TEXT, label_time_10 TEXT, label_time_11 TEXT, label_time_12 TEXT, label_time_13 TEXT, label_time_14 TEXT, label_time_15 TEXT, label_time_16 TEXT, label_time_17 TEXT, label_time_18 TEXT, label_time_19 TEXT, label_time_20 TEXT, label_time_21 TEXT, label_time_22 TEXT, label_time_23 TEXT, constraint Checkins_pk primary key (business_id, day_id) ); CREATE TABLE IF NOT EXISTS "Elite" ( user_id INTEGER constraint Elite_Users_user_id_fk references Users, year_id INTEGER constraint Elite_Years_year_id_fk references Years, constraint Elite_pk primary key (user_id, year_id) ); CREATE TABLE IF NOT EXISTS "Reviews" ( business_id INTEGER constraint Reviews_Business_business_id_fk references Business, user_id INTEGER constraint Reviews_Users_user_id_fk references Users, review_stars INTEGER, review_votes_funny TEXT, review_votes_useful TEXT, review_votes_cool TEXT, review_length TEXT, constraint Reviews_pk primary key (business_id, user_id) ); CREATE TABLE IF NOT EXISTS "Tips" ( business_id INTEGER constraint Tips_Business_business_id_fk references Business, user_id INTEGER constraint Tips_Users_user_id_fk references Users, likes INTEGER, tip_length TEXT, constraint Tips_pk primary key (business_id, user_id) ); CREATE TABLE IF NOT EXISTS "Users_Compliments" ( compliment_id INTEGER constraint Users_Compliments_Compliments_compliment_id_fk references Compliments, user_id INTEGER constraint Users_Compliments_Users_user_id_fk references Users, number_of_compliments TEXT, constraint Users_Compliments_pk primary key (compliment_id, user_id) ); CREATE TABLE IF NOT EXISTS "Business" ( business_id INTEGER constraint Business_pk primary key, active TEXT, city TEXT, state TEXT, stars REAL, review_count TEXT ); CREATE TABLE IF NOT EXISTS "Users" ( user_id INTEGER constraint Users_pk primary key, user_yelping_since_year INTEGER, user_average_stars TEXT, user_votes_funny TEXT, user_votes_useful TEXT, user_votes_cool TEXT, user_review_count TEXT, user_fans TEXT );
public_review_platform
Among the stopped businesses in San Tan Valley city, list down the user ID and review length of who had great experience.
stop businesses refers to active = 'false'; great experience refers to review_stars = 5
SELECT T2.user_id, T2.review_length FROM Business AS T1 INNER JOIN Reviews AS T2 ON T1.business_id = T2.business_id WHERE T1.city = 'San Tan Valley' AND T1.active = 'false' AND T2.review_stars = 5
CREATE TABLE Attributes ( attribute_id INTEGER constraint Attributes_pk primary key, attribute_name TEXT ); CREATE TABLE Categories ( category_id INTEGER constraint Categories_pk primary key, category_name TEXT ); CREATE TABLE Compliments ( compliment_id INTEGER constraint Compliments_pk primary key, compliment_type TEXT ); CREATE TABLE Days ( day_id INTEGER constraint Days_pk primary key, day_of_week TEXT ); CREATE TABLE Years ( year_id INTEGER constraint Years_pk primary key, actual_year INTEGER ); CREATE TABLE IF NOT EXISTS "Business_Attributes" ( attribute_id INTEGER constraint Business_Attributes_Attributes_attribute_id_fk references Attributes, business_id INTEGER constraint Business_Attributes_Business_business_id_fk references Business, attribute_value TEXT, constraint Business_Attributes_pk primary key (attribute_id, business_id) ); CREATE TABLE IF NOT EXISTS "Business_Categories" ( business_id INTEGER constraint Business_Categories_Business_business_id_fk references Business, category_id INTEGER constraint Business_Categories_Categories_category_id_fk references Categories, constraint Business_Categories_pk primary key (business_id, category_id) ); CREATE TABLE IF NOT EXISTS "Business_Hours" ( business_id INTEGER constraint Business_Hours_Business_business_id_fk references Business, day_id INTEGER constraint Business_Hours_Days_day_id_fk references Days, opening_time TEXT, closing_time TEXT, constraint Business_Hours_pk primary key (business_id, day_id) ); CREATE TABLE IF NOT EXISTS "Checkins" ( business_id INTEGER constraint Checkins_Business_business_id_fk references Business, day_id INTEGER constraint Checkins_Days_day_id_fk references Days, label_time_0 TEXT, label_time_1 TEXT, label_time_2 TEXT, label_time_3 TEXT, label_time_4 TEXT, label_time_5 TEXT, label_time_6 TEXT, label_time_7 TEXT, label_time_8 TEXT, label_time_9 TEXT, label_time_10 TEXT, label_time_11 TEXT, label_time_12 TEXT, label_time_13 TEXT, label_time_14 TEXT, label_time_15 TEXT, label_time_16 TEXT, label_time_17 TEXT, label_time_18 TEXT, label_time_19 TEXT, label_time_20 TEXT, label_time_21 TEXT, label_time_22 TEXT, label_time_23 TEXT, constraint Checkins_pk primary key (business_id, day_id) ); CREATE TABLE IF NOT EXISTS "Elite" ( user_id INTEGER constraint Elite_Users_user_id_fk references Users, year_id INTEGER constraint Elite_Years_year_id_fk references Years, constraint Elite_pk primary key (user_id, year_id) ); CREATE TABLE IF NOT EXISTS "Reviews" ( business_id INTEGER constraint Reviews_Business_business_id_fk references Business, user_id INTEGER constraint Reviews_Users_user_id_fk references Users, review_stars INTEGER, review_votes_funny TEXT, review_votes_useful TEXT, review_votes_cool TEXT, review_length TEXT, constraint Reviews_pk primary key (business_id, user_id) ); CREATE TABLE IF NOT EXISTS "Tips" ( business_id INTEGER constraint Tips_Business_business_id_fk references Business, user_id INTEGER constraint Tips_Users_user_id_fk references Users, likes INTEGER, tip_length TEXT, constraint Tips_pk primary key (business_id, user_id) ); CREATE TABLE IF NOT EXISTS "Users_Compliments" ( compliment_id INTEGER constraint Users_Compliments_Compliments_compliment_id_fk references Compliments, user_id INTEGER constraint Users_Compliments_Users_user_id_fk references Users, number_of_compliments TEXT, constraint Users_Compliments_pk primary key (compliment_id, user_id) ); CREATE TABLE IF NOT EXISTS "Business" ( business_id INTEGER constraint Business_pk primary key, active TEXT, city TEXT, state TEXT, stars REAL, review_count TEXT ); CREATE TABLE IF NOT EXISTS "Users" ( user_id INTEGER constraint Users_pk primary key, user_yelping_since_year INTEGER, user_average_stars TEXT, user_votes_funny TEXT, user_votes_useful TEXT, user_votes_cool TEXT, user_review_count TEXT, user_fans TEXT );
books
Who is the author of the book The Mystery in the Rocky Mountains?
author refers to author_name; 'The Mystery in the Rocky Mountains' is the title of the book
SELECT T3.author_name FROM book AS T1 INNER JOIN book_author AS T2 ON T1.book_id = T2.book_id INNER JOIN author AS T3 ON T3.author_id = T2.author_id WHERE T1.title = 'The Mystery in the Rocky Mountains'
CREATE TABLE address_status ( status_id INTEGER primary key, address_status TEXT ); CREATE TABLE author ( author_id INTEGER primary key, author_name TEXT ); CREATE TABLE book_language ( language_id INTEGER primary key, language_code TEXT, language_name TEXT ); CREATE TABLE country ( country_id INTEGER primary key, country_name TEXT ); CREATE TABLE address ( address_id INTEGER primary key, street_number TEXT, street_name TEXT, city TEXT, country_id INTEGER, foreign key (country_id) references country(country_id) ); CREATE TABLE customer ( customer_id INTEGER primary key, first_name TEXT, last_name TEXT, email TEXT ); CREATE TABLE customer_address ( customer_id INTEGER, address_id INTEGER, status_id INTEGER, primary key (customer_id, address_id), foreign key (address_id) references address(address_id), foreign key (customer_id) references customer(customer_id) ); CREATE TABLE order_status ( status_id INTEGER primary key, status_value TEXT ); CREATE TABLE publisher ( publisher_id INTEGER primary key, publisher_name TEXT ); CREATE TABLE book ( book_id INTEGER primary key, title TEXT, isbn13 TEXT, language_id INTEGER, num_pages INTEGER, publication_date DATE, publisher_id INTEGER, foreign key (language_id) references book_language(language_id), foreign key (publisher_id) references publisher(publisher_id) ); CREATE TABLE book_author ( book_id INTEGER, author_id INTEGER, primary key (book_id, author_id), foreign key (author_id) references author(author_id), foreign key (book_id) references book(book_id) ); CREATE TABLE shipping_method ( method_id INTEGER primary key, method_name TEXT, cost REAL ); CREATE TABLE IF NOT EXISTS "cust_order" ( order_id INTEGER primary key autoincrement, order_date DATETIME, customer_id INTEGER references customer, shipping_method_id INTEGER references shipping_method, dest_address_id INTEGER references address ); CREATE TABLE sqlite_sequence(name,seq); CREATE TABLE IF NOT EXISTS "order_history" ( history_id INTEGER primary key autoincrement, order_id INTEGER references cust_order, status_id INTEGER references order_status, status_date DATETIME ); CREATE TABLE IF NOT EXISTS "order_line" ( line_id INTEGER primary key autoincrement, order_id INTEGER references cust_order, book_id INTEGER references book, price REAL );
food_inspection
List the inspection dates, scores and inspection types for the eateries with tax code AA.
eateries with tax code AA refer to business_id where tax_code = 'AA';
SELECT T1.`date`, T1.score, T1.type FROM inspections AS T1 INNER JOIN businesses AS T2 ON T1.business_id = T2.business_id WHERE T2.tax_code = 'AA'
CREATE TABLE `businesses` ( `business_id` INTEGER NOT NULL, `name` TEXT NOT NULL, `address` TEXT DEFAULT NULL, `city` TEXT DEFAULT NULL, `postal_code` TEXT DEFAULT NULL, `latitude` REAL DEFAULT NULL, `longitude` REAL DEFAULT NULL, `phone_number` INTEGER DEFAULT NULL, `tax_code` TEXT DEFAULT NULL, `business_certificate` INTEGER NOT NULL, `application_date` DATE DEFAULT NULL, `owner_name` TEXT NOT NULL, `owner_address` TEXT DEFAULT NULL, `owner_city` TEXT DEFAULT NULL, `owner_state` TEXT DEFAULT NULL, `owner_zip` TEXT DEFAULT NULL, PRIMARY KEY (`business_id`) ); CREATE TABLE `inspections` ( `business_id` INTEGER NOT NULL, `score` INTEGER DEFAULT NULL, `date` DATE NOT NULL, `type` TEXT NOT NULL, FOREIGN KEY (`business_id`) REFERENCES `businesses` (`business_id`) ); CREATE TABLE `violations` ( `business_id` INTEGER NOT NULL, `date` DATE NOT NULL, `violation_type_id` TEXT NOT NULL, `risk_category` TEXT NOT NULL, `description` TEXT NOT NULL, FOREIGN KEY (`business_id`) REFERENCES `businesses` (`business_id`) );
soccer_2016
What is the batting hand of MK Pandey?
MK Pandey refers to Player_Name = 'MK Pandey'
SELECT T2.Batting_hand FROM Player AS T1 INNER JOIN Batting_Style AS T2 ON T1.Batting_hand = T2.Batting_Id WHERE T1.Player_Name = 'MK Pandey'
CREATE TABLE Batting_Style ( Batting_Id INTEGER primary key, Batting_hand TEXT ); CREATE TABLE Bowling_Style ( Bowling_Id INTEGER primary key, Bowling_skill TEXT ); CREATE TABLE City ( City_Id INTEGER primary key, City_Name TEXT, Country_id INTEGER ); CREATE TABLE Country ( Country_Id INTEGER primary key, Country_Name TEXT, foreign key (Country_Id) references Country(Country_Id) ); CREATE TABLE Extra_Type ( Extra_Id INTEGER primary key, Extra_Name TEXT ); CREATE TABLE Extra_Runs ( Match_Id INTEGER, Over_Id INTEGER, Ball_Id INTEGER, Extra_Type_Id INTEGER, Extra_Runs INTEGER, Innings_No INTEGER, primary key (Match_Id, Over_Id, Ball_Id, Innings_No), foreign key (Extra_Type_Id) references Extra_Type(Extra_Id) ); CREATE TABLE Out_Type ( Out_Id INTEGER primary key, Out_Name TEXT ); CREATE TABLE Outcome ( Outcome_Id INTEGER primary key, Outcome_Type TEXT ); CREATE TABLE Player ( Player_Id INTEGER primary key, Player_Name TEXT, DOB DATE, Batting_hand INTEGER, Bowling_skill INTEGER, Country_Name INTEGER, foreign key (Batting_hand) references Batting_Style(Batting_Id), foreign key (Bowling_skill) references Bowling_Style(Bowling_Id), foreign key (Country_Name) references Country(Country_Id) ); CREATE TABLE Rolee ( Role_Id INTEGER primary key, Role_Desc TEXT ); CREATE TABLE Season ( Season_Id INTEGER primary key, Man_of_the_Series INTEGER, Orange_Cap INTEGER, Purple_Cap INTEGER, Season_Year INTEGER ); CREATE TABLE Team ( Team_Id INTEGER primary key, Team_Name TEXT ); CREATE TABLE Toss_Decision ( Toss_Id INTEGER primary key, Toss_Name TEXT ); CREATE TABLE Umpire ( Umpire_Id INTEGER primary key, Umpire_Name TEXT, Umpire_Country INTEGER, foreign key (Umpire_Country) references Country(Country_Id) ); CREATE TABLE Venue ( Venue_Id INTEGER primary key, Venue_Name TEXT, City_Id INTEGER, foreign key (City_Id) references City(City_Id) ); CREATE TABLE Win_By ( Win_Id INTEGER primary key, Win_Type TEXT ); CREATE TABLE Match ( Match_Id INTEGER primary key, Team_1 INTEGER, Team_2 INTEGER, Match_Date DATE, Season_Id INTEGER, Venue_Id INTEGER, Toss_Winner INTEGER, Toss_Decide INTEGER, Win_Type INTEGER, Win_Margin INTEGER, Outcome_type INTEGER, Match_Winner INTEGER, Man_of_the_Match INTEGER, foreign key (Team_1) references Team(Team_Id), foreign key (Team_2) references Team(Team_Id), foreign key (Season_Id) references Season(Season_Id), foreign key (Venue_Id) references Venue(Venue_Id), foreign key (Toss_Winner) references Team(Team_Id), foreign key (Toss_Decide) references Toss_Decision(Toss_Id), foreign key (Win_Type) references Win_By(Win_Id), foreign key (Outcome_type) references Out_Type(Out_Id), foreign key (Match_Winner) references Team(Team_Id), foreign key (Man_of_the_Match) references Player(Player_Id) ); CREATE TABLE Ball_by_Ball ( Match_Id INTEGER, Over_Id INTEGER, Ball_Id INTEGER, Innings_No INTEGER, Team_Batting INTEGER, Team_Bowling INTEGER, Striker_Batting_Position INTEGER, Striker INTEGER, Non_Striker INTEGER, Bowler INTEGER, primary key (Match_Id, Over_Id, Ball_Id, Innings_No), foreign key (Match_Id) references Match(Match_Id) ); CREATE TABLE Batsman_Scored ( Match_Id INTEGER, Over_Id INTEGER, Ball_Id INTEGER, Runs_Scored INTEGER, Innings_No INTEGER, primary key (Match_Id, Over_Id, Ball_Id, Innings_No), foreign key (Match_Id) references Match(Match_Id) ); CREATE TABLE Player_Match ( Match_Id INTEGER, Player_Id INTEGER, Role_Id INTEGER, Team_Id INTEGER, primary key (Match_Id, Player_Id, Role_Id), foreign key (Match_Id) references Match(Match_Id), foreign key (Player_Id) references Player(Player_Id), foreign key (Team_Id) references Team(Team_Id), foreign key (Role_Id) references Rolee(Role_Id) ); CREATE TABLE Wicket_Taken ( Match_Id INTEGER, Over_Id INTEGER, Ball_Id INTEGER, Player_Out INTEGER, Kind_Out INTEGER, Fielders INTEGER, Innings_No INTEGER, primary key (Match_Id, Over_Id, Ball_Id, Innings_No), foreign key (Match_Id) references Match(Match_Id), foreign key (Player_Out) references Player(Player_Id), foreign key (Kind_Out) references Out_Type(Out_Id), foreign key (Fielders) references Player(Player_Id) );
food_inspection_2
List the names of employees involved in an inspection with the Display of Inspection Report Summary category.
name refers to first_name, last_name; Display of Inspection Report Summary category refers to category = 'Display of Inspection Report Summary'
SELECT DISTINCT T1.first_name, T1.last_name FROM employee AS T1 INNER JOIN inspection AS T2 ON T1.employee_id = T2.employee_id INNER JOIN violation AS T3 ON T2.inspection_id = T3.inspection_id INNER JOIN inspection_point AS T4 ON T3.point_id = T4.point_id WHERE T4.category = 'Display of Inspection Report Summary'
CREATE TABLE employee ( employee_id INTEGER primary key, first_name TEXT, last_name TEXT, address TEXT, city TEXT, state TEXT, zip INTEGER, phone TEXT, title TEXT, salary INTEGER, supervisor INTEGER, foreign key (supervisor) references employee(employee_id) ); CREATE TABLE establishment ( license_no INTEGER primary key, dba_name TEXT, aka_name TEXT, facility_type TEXT, risk_level INTEGER, address TEXT, city TEXT, state TEXT, zip INTEGER, latitude REAL, longitude REAL, ward INTEGER ); CREATE TABLE inspection ( inspection_id INTEGER primary key, inspection_date DATE, inspection_type TEXT, results TEXT, employee_id INTEGER, license_no INTEGER, followup_to INTEGER, foreign key (employee_id) references employee(employee_id), foreign key (license_no) references establishment(license_no), foreign key (followup_to) references inspection(inspection_id) ); CREATE TABLE inspection_point ( point_id INTEGER primary key, Description TEXT, category TEXT, code TEXT, fine INTEGER, point_level TEXT ); CREATE TABLE violation ( inspection_id INTEGER, point_id INTEGER, fine INTEGER, inspector_comment TEXT, primary key (inspection_id, point_id), foreign key (inspection_id) references inspection(inspection_id), foreign key (point_id) references inspection_point(point_id) );
works_cycles
What is the average age of employee in Adventure Works?
average age = AVG(subtract(year(now), year(HireDate)))
SELECT AVG(STRFTIME('%Y', CURRENT_TIMESTAMP) - STRFTIME('%Y', BirthDate)) FROM Employee
CREATE TABLE sqlite_sequence(name,seq); CREATE TABLE CountryRegion ( CountryRegionCode TEXT not null primary key, Name TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE Culture ( CultureID TEXT not null primary key, Name TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE Currency ( CurrencyCode TEXT not null primary key, Name TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE CountryRegionCurrency ( CountryRegionCode TEXT not null, CurrencyCode TEXT not null, ModifiedDate DATETIME default current_timestamp not null, primary key (CountryRegionCode, CurrencyCode), foreign key (CountryRegionCode) references CountryRegion(CountryRegionCode), foreign key (CurrencyCode) references Currency(CurrencyCode) ); CREATE TABLE Person ( BusinessEntityID INTEGER not null primary key, PersonType TEXT not null, NameStyle INTEGER default 0 not null, Title TEXT, FirstName TEXT not null, MiddleName TEXT, LastName TEXT not null, Suffix TEXT, EmailPromotion INTEGER default 0 not null, AdditionalContactInfo TEXT, Demographics TEXT, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null, foreign key (BusinessEntityID) references BusinessEntity(BusinessEntityID) ); CREATE TABLE BusinessEntityContact ( BusinessEntityID INTEGER not null, PersonID INTEGER not null, ContactTypeID INTEGER not null, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null, primary key (BusinessEntityID, PersonID, ContactTypeID), foreign key (BusinessEntityID) references BusinessEntity(BusinessEntityID), foreign key (ContactTypeID) references ContactType(ContactTypeID), foreign key (PersonID) references Person(BusinessEntityID) ); CREATE TABLE EmailAddress ( BusinessEntityID INTEGER not null, EmailAddressID INTEGER, EmailAddress TEXT, rowguid TEXT not null, ModifiedDate DATETIME default current_timestamp not null, primary key (EmailAddressID, BusinessEntityID), foreign key (BusinessEntityID) references Person(BusinessEntityID) ); CREATE TABLE Employee ( BusinessEntityID INTEGER not null primary key, NationalIDNumber TEXT not null unique, LoginID TEXT not null unique, OrganizationNode TEXT, OrganizationLevel INTEGER, JobTitle TEXT not null, BirthDate DATE not null, MaritalStatus TEXT not null, Gender TEXT not null, HireDate DATE not null, SalariedFlag INTEGER default 1 not null, VacationHours INTEGER default 0 not null, SickLeaveHours INTEGER default 0 not null, CurrentFlag INTEGER default 1 not null, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null, foreign key (BusinessEntityID) references Person(BusinessEntityID) ); CREATE TABLE Password ( BusinessEntityID INTEGER not null primary key, PasswordHash TEXT not null, PasswordSalt TEXT not null, rowguid TEXT not null, ModifiedDate DATETIME default current_timestamp not null, foreign key (BusinessEntityID) references Person(BusinessEntityID) ); CREATE TABLE PersonCreditCard ( BusinessEntityID INTEGER not null, CreditCardID INTEGER not null, ModifiedDate DATETIME default current_timestamp not null, primary key (BusinessEntityID, CreditCardID), foreign key (CreditCardID) references CreditCard(CreditCardID), foreign key (BusinessEntityID) references Person(BusinessEntityID) ); CREATE TABLE ProductCategory ( ProductCategoryID INTEGER primary key autoincrement, Name TEXT not null unique, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE ProductDescription ( ProductDescriptionID INTEGER primary key autoincrement, Description TEXT not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE ProductModel ( ProductModelID INTEGER primary key autoincrement, Name TEXT not null unique, CatalogDescription TEXT, Instructions TEXT, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE ProductModelProductDescriptionCulture ( ProductModelID INTEGER not null, ProductDescriptionID INTEGER not null, CultureID TEXT not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (ProductModelID, ProductDescriptionID, CultureID), foreign key (ProductModelID) references ProductModel(ProductModelID), foreign key (ProductDescriptionID) references ProductDescription(ProductDescriptionID), foreign key (CultureID) references Culture(CultureID) ); CREATE TABLE ProductPhoto ( ProductPhotoID INTEGER primary key autoincrement, ThumbNailPhoto BLOB, ThumbnailPhotoFileName TEXT, LargePhoto BLOB, LargePhotoFileName TEXT, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE ProductSubcategory ( ProductSubcategoryID INTEGER primary key autoincrement, ProductCategoryID INTEGER not null, Name TEXT not null unique, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (ProductCategoryID) references ProductCategory(ProductCategoryID) ); CREATE TABLE SalesReason ( SalesReasonID INTEGER primary key autoincrement, Name TEXT not null, ReasonType TEXT not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE SalesTerritory ( TerritoryID INTEGER primary key autoincrement, Name TEXT not null unique, CountryRegionCode TEXT not null, "Group" TEXT not null, SalesYTD REAL default 0.0000 not null, SalesLastYear REAL default 0.0000 not null, CostYTD REAL default 0.0000 not null, CostLastYear REAL default 0.0000 not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (CountryRegionCode) references CountryRegion(CountryRegionCode) ); CREATE TABLE SalesPerson ( BusinessEntityID INTEGER not null primary key, TerritoryID INTEGER, SalesQuota REAL, Bonus REAL default 0.0000 not null, CommissionPct REAL default 0.0000 not null, SalesYTD REAL default 0.0000 not null, SalesLastYear REAL default 0.0000 not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (BusinessEntityID) references Employee(BusinessEntityID), foreign key (TerritoryID) references SalesTerritory(TerritoryID) ); CREATE TABLE SalesPersonQuotaHistory ( BusinessEntityID INTEGER not null, QuotaDate DATETIME not null, SalesQuota REAL not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (BusinessEntityID, QuotaDate), foreign key (BusinessEntityID) references SalesPerson(BusinessEntityID) ); CREATE TABLE SalesTerritoryHistory ( BusinessEntityID INTEGER not null, TerritoryID INTEGER not null, StartDate DATETIME not null, EndDate DATETIME, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (BusinessEntityID, StartDate, TerritoryID), foreign key (BusinessEntityID) references SalesPerson(BusinessEntityID), foreign key (TerritoryID) references SalesTerritory(TerritoryID) ); CREATE TABLE ScrapReason ( ScrapReasonID INTEGER primary key autoincrement, Name TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE Shift ( ShiftID INTEGER primary key autoincrement, Name TEXT not null unique, StartTime TEXT not null, EndTime TEXT not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, unique (StartTime, EndTime) ); CREATE TABLE ShipMethod ( ShipMethodID INTEGER primary key autoincrement, Name TEXT not null unique, ShipBase REAL default 0.0000 not null, ShipRate REAL default 0.0000 not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE SpecialOffer ( SpecialOfferID INTEGER primary key autoincrement, Description TEXT not null, DiscountPct REAL default 0.0000 not null, Type TEXT not null, Category TEXT not null, StartDate DATETIME not null, EndDate DATETIME not null, MinQty INTEGER default 0 not null, MaxQty INTEGER, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE BusinessEntityAddress ( BusinessEntityID INTEGER not null, AddressID INTEGER not null, AddressTypeID INTEGER not null, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null, primary key (BusinessEntityID, AddressID, AddressTypeID), foreign key (AddressID) references Address(AddressID), foreign key (AddressTypeID) references AddressType(AddressTypeID), foreign key (BusinessEntityID) references BusinessEntity(BusinessEntityID) ); CREATE TABLE SalesTaxRate ( SalesTaxRateID INTEGER primary key autoincrement, StateProvinceID INTEGER not null, TaxType INTEGER not null, TaxRate REAL default 0.0000 not null, Name TEXT not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, unique (StateProvinceID, TaxType), foreign key (StateProvinceID) references StateProvince(StateProvinceID) ); CREATE TABLE Store ( BusinessEntityID INTEGER not null primary key, Name TEXT not null, SalesPersonID INTEGER, Demographics TEXT, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (BusinessEntityID) references BusinessEntity(BusinessEntityID), foreign key (SalesPersonID) references SalesPerson(BusinessEntityID) ); CREATE TABLE SalesOrderHeaderSalesReason ( SalesOrderID INTEGER not null, SalesReasonID INTEGER not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (SalesOrderID, SalesReasonID), foreign key (SalesOrderID) references SalesOrderHeader(SalesOrderID), foreign key (SalesReasonID) references SalesReason(SalesReasonID) ); CREATE TABLE TransactionHistoryArchive ( TransactionID INTEGER not null primary key, ProductID INTEGER not null, ReferenceOrderID INTEGER not null, ReferenceOrderLineID INTEGER default 0 not null, TransactionDate DATETIME default CURRENT_TIMESTAMP not null, TransactionType TEXT not null, Quantity INTEGER not null, ActualCost REAL not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE UnitMeasure ( UnitMeasureCode TEXT not null primary key, Name TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE ProductCostHistory ( ProductID INTEGER not null, StartDate DATE not null, EndDate DATE, StandardCost REAL not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (ProductID, StartDate), foreign key (ProductID) references Product(ProductID) ); CREATE TABLE ProductDocument ( ProductID INTEGER not null, DocumentNode TEXT not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (ProductID, DocumentNode), foreign key (ProductID) references Product(ProductID), foreign key (DocumentNode) references Document(DocumentNode) ); CREATE TABLE ProductInventory ( ProductID INTEGER not null, LocationID INTEGER not null, Shelf TEXT not null, Bin INTEGER not null, Quantity INTEGER default 0 not null, rowguid TEXT not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (ProductID, LocationID), foreign key (ProductID) references Product(ProductID), foreign key (LocationID) references Location(LocationID) ); CREATE TABLE ProductProductPhoto ( ProductID INTEGER not null, ProductPhotoID INTEGER not null, "Primary" INTEGER default 0 not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (ProductID, ProductPhotoID), foreign key (ProductID) references Product(ProductID), foreign key (ProductPhotoID) references ProductPhoto(ProductPhotoID) ); CREATE TABLE ProductReview ( ProductReviewID INTEGER primary key autoincrement, ProductID INTEGER not null, ReviewerName TEXT not null, ReviewDate DATETIME default CURRENT_TIMESTAMP not null, EmailAddress TEXT not null, Rating INTEGER not null, Comments TEXT, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (ProductID) references Product(ProductID) ); CREATE TABLE ShoppingCartItem ( ShoppingCartItemID INTEGER primary key autoincrement, ShoppingCartID TEXT not null, Quantity INTEGER default 1 not null, ProductID INTEGER not null, DateCreated DATETIME default CURRENT_TIMESTAMP not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (ProductID) references Product(ProductID) ); CREATE TABLE SpecialOfferProduct ( SpecialOfferID INTEGER not null, ProductID INTEGER not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (SpecialOfferID, ProductID), foreign key (SpecialOfferID) references SpecialOffer(SpecialOfferID), foreign key (ProductID) references Product(ProductID) ); CREATE TABLE SalesOrderDetail ( SalesOrderID INTEGER not null, SalesOrderDetailID INTEGER primary key autoincrement, CarrierTrackingNumber TEXT, OrderQty INTEGER not null, ProductID INTEGER not null, SpecialOfferID INTEGER not null, UnitPrice REAL not null, UnitPriceDiscount REAL default 0.0000 not null, LineTotal REAL not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (SalesOrderID) references SalesOrderHeader(SalesOrderID), foreign key (SpecialOfferID, ProductID) references SpecialOfferProduct(SpecialOfferID, ProductID) ); CREATE TABLE TransactionHistory ( TransactionID INTEGER primary key autoincrement, ProductID INTEGER not null, ReferenceOrderID INTEGER not null, ReferenceOrderLineID INTEGER default 0 not null, TransactionDate DATETIME default CURRENT_TIMESTAMP not null, TransactionType TEXT not null, Quantity INTEGER not null, ActualCost REAL not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (ProductID) references Product(ProductID) ); CREATE TABLE Vendor ( BusinessEntityID INTEGER not null primary key, AccountNumber TEXT not null unique, Name TEXT not null, CreditRating INTEGER not null, PreferredVendorStatus INTEGER default 1 not null, ActiveFlag INTEGER default 1 not null, PurchasingWebServiceURL TEXT, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (BusinessEntityID) references BusinessEntity(BusinessEntityID) ); CREATE TABLE ProductVendor ( ProductID INTEGER not null, BusinessEntityID INTEGER not null, AverageLeadTime INTEGER not null, StandardPrice REAL not null, LastReceiptCost REAL, LastReceiptDate DATETIME, MinOrderQty INTEGER not null, MaxOrderQty INTEGER not null, OnOrderQty INTEGER, UnitMeasureCode TEXT not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (ProductID, BusinessEntityID), foreign key (ProductID) references Product(ProductID), foreign key (BusinessEntityID) references Vendor(BusinessEntityID), foreign key (UnitMeasureCode) references UnitMeasure(UnitMeasureCode) ); CREATE TABLE PurchaseOrderHeader ( PurchaseOrderID INTEGER primary key autoincrement, RevisionNumber INTEGER default 0 not null, Status INTEGER default 1 not null, EmployeeID INTEGER not null, VendorID INTEGER not null, ShipMethodID INTEGER not null, OrderDate DATETIME default CURRENT_TIMESTAMP not null, ShipDate DATETIME, SubTotal REAL default 0.0000 not null, TaxAmt REAL default 0.0000 not null, Freight REAL default 0.0000 not null, TotalDue REAL not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (EmployeeID) references Employee(BusinessEntityID), foreign key (VendorID) references Vendor(BusinessEntityID), foreign key (ShipMethodID) references ShipMethod(ShipMethodID) ); CREATE TABLE PurchaseOrderDetail ( PurchaseOrderID INTEGER not null, PurchaseOrderDetailID INTEGER primary key autoincrement, DueDate DATETIME not null, OrderQty INTEGER not null, ProductID INTEGER not null, UnitPrice REAL not null, LineTotal REAL not null, ReceivedQty REAL not null, RejectedQty REAL not null, StockedQty REAL not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (PurchaseOrderID) references PurchaseOrderHeader(PurchaseOrderID), foreign key (ProductID) references Product(ProductID) ); CREATE TABLE WorkOrder ( WorkOrderID INTEGER primary key autoincrement, ProductID INTEGER not null, OrderQty INTEGER not null, StockedQty INTEGER not null, ScrappedQty INTEGER not null, StartDate DATETIME not null, EndDate DATETIME, DueDate DATETIME not null, ScrapReasonID INTEGER, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (ProductID) references Product(ProductID), foreign key (ScrapReasonID) references ScrapReason(ScrapReasonID) ); CREATE TABLE WorkOrderRouting ( WorkOrderID INTEGER not null, ProductID INTEGER not null, OperationSequence INTEGER not null, LocationID INTEGER not null, ScheduledStartDate DATETIME not null, ScheduledEndDate DATETIME not null, ActualStartDate DATETIME, ActualEndDate DATETIME, ActualResourceHrs REAL, PlannedCost REAL not null, ActualCost REAL, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (WorkOrderID, ProductID, OperationSequence), foreign key (WorkOrderID) references WorkOrder(WorkOrderID), foreign key (LocationID) references Location(LocationID) ); CREATE TABLE Customer ( CustomerID INTEGER primary key, PersonID INTEGER, StoreID INTEGER, TerritoryID INTEGER, AccountNumber TEXT not null unique, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null, foreign key (PersonID) references Person(BusinessEntityID), foreign key (TerritoryID) references SalesTerritory(TerritoryID), foreign key (StoreID) references Store(BusinessEntityID) ); CREATE TABLE ProductListPriceHistory ( ProductID INTEGER not null, StartDate DATE not null, EndDate DATE, ListPrice REAL not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (ProductID, StartDate), foreign key (ProductID) references Product(ProductID) ); CREATE TABLE IF NOT EXISTS "Address" ( AddressID INTEGER primary key autoincrement, AddressLine1 TEXT not null, AddressLine2 TEXT, City TEXT not null, StateProvinceID INTEGER not null references StateProvince, PostalCode TEXT not null, SpatialLocation TEXT, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null, unique (AddressLine1, AddressLine2, City, StateProvinceID, PostalCode) ); CREATE TABLE IF NOT EXISTS "AddressType" ( AddressTypeID INTEGER primary key autoincrement, Name TEXT not null unique, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "BillOfMaterials" ( BillOfMaterialsID INTEGER primary key autoincrement, ProductAssemblyID INTEGER references Product, ComponentID INTEGER not null references Product, StartDate DATETIME default current_timestamp not null, EndDate DATETIME, UnitMeasureCode TEXT not null references UnitMeasure, BOMLevel INTEGER not null, PerAssemblyQty REAL default 1.00 not null, ModifiedDate DATETIME default current_timestamp not null, unique (ProductAssemblyID, ComponentID, StartDate) ); CREATE TABLE IF NOT EXISTS "BusinessEntity" ( BusinessEntityID INTEGER primary key autoincrement, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "ContactType" ( ContactTypeID INTEGER primary key autoincrement, Name TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "CurrencyRate" ( CurrencyRateID INTEGER primary key autoincrement, CurrencyRateDate DATETIME not null, FromCurrencyCode TEXT not null references Currency, ToCurrencyCode TEXT not null references Currency, AverageRate REAL not null, EndOfDayRate REAL not null, ModifiedDate DATETIME default current_timestamp not null, unique (CurrencyRateDate, FromCurrencyCode, ToCurrencyCode) ); CREATE TABLE IF NOT EXISTS "Department" ( DepartmentID INTEGER primary key autoincrement, Name TEXT not null unique, GroupName TEXT not null, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "EmployeeDepartmentHistory" ( BusinessEntityID INTEGER not null references Employee, DepartmentID INTEGER not null references Department, ShiftID INTEGER not null references Shift, StartDate DATE not null, EndDate DATE, ModifiedDate DATETIME default current_timestamp not null, primary key (BusinessEntityID, StartDate, DepartmentID, ShiftID) ); CREATE TABLE IF NOT EXISTS "EmployeePayHistory" ( BusinessEntityID INTEGER not null references Employee, RateChangeDate DATETIME not null, Rate REAL not null, PayFrequency INTEGER not null, ModifiedDate DATETIME default current_timestamp not null, primary key (BusinessEntityID, RateChangeDate) ); CREATE TABLE IF NOT EXISTS "JobCandidate" ( JobCandidateID INTEGER primary key autoincrement, BusinessEntityID INTEGER references Employee, Resume TEXT, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "Location" ( LocationID INTEGER primary key autoincrement, Name TEXT not null unique, CostRate REAL default 0.0000 not null, Availability REAL default 0.00 not null, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "PhoneNumberType" ( PhoneNumberTypeID INTEGER primary key autoincrement, Name TEXT not null, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "Product" ( ProductID INTEGER primary key autoincrement, Name TEXT not null unique, ProductNumber TEXT not null unique, MakeFlag INTEGER default 1 not null, FinishedGoodsFlag INTEGER default 1 not null, Color TEXT, SafetyStockLevel INTEGER not null, ReorderPoint INTEGER not null, StandardCost REAL not null, ListPrice REAL not null, Size TEXT, SizeUnitMeasureCode TEXT references UnitMeasure, WeightUnitMeasureCode TEXT references UnitMeasure, Weight REAL, DaysToManufacture INTEGER not null, ProductLine TEXT, Class TEXT, Style TEXT, ProductSubcategoryID INTEGER references ProductSubcategory, ProductModelID INTEGER references ProductModel, SellStartDate DATETIME not null, SellEndDate DATETIME, DiscontinuedDate DATETIME, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "Document" ( DocumentNode TEXT not null primary key, DocumentLevel INTEGER, Title TEXT not null, Owner INTEGER not null references Employee, FolderFlag INTEGER default 0 not null, FileName TEXT not null, FileExtension TEXT not null, Revision TEXT not null, ChangeNumber INTEGER default 0 not null, Status INTEGER not null, DocumentSummary TEXT, Document BLOB, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null, unique (DocumentLevel, DocumentNode) ); CREATE TABLE IF NOT EXISTS "StateProvince" ( StateProvinceID INTEGER primary key autoincrement, StateProvinceCode TEXT not null, CountryRegionCode TEXT not null references CountryRegion, IsOnlyStateProvinceFlag INTEGER default 1 not null, Name TEXT not null unique, TerritoryID INTEGER not null references SalesTerritory, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, unique (StateProvinceCode, CountryRegionCode) ); CREATE TABLE IF NOT EXISTS "CreditCard" ( CreditCardID INTEGER primary key autoincrement, CardType TEXT not null, CardNumber TEXT not null unique, ExpMonth INTEGER not null, ExpYear INTEGER not null, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "SalesOrderHeader" ( SalesOrderID INTEGER primary key autoincrement, RevisionNumber INTEGER default 0 not null, OrderDate DATETIME default CURRENT_TIMESTAMP not null, DueDate DATETIME not null, ShipDate DATETIME, Status INTEGER default 1 not null, OnlineOrderFlag INTEGER default 1 not null, SalesOrderNumber TEXT not null unique, PurchaseOrderNumber TEXT, AccountNumber TEXT, CustomerID INTEGER not null references Customer, SalesPersonID INTEGER references SalesPerson, TerritoryID INTEGER references SalesTerritory, BillToAddressID INTEGER not null references Address, ShipToAddressID INTEGER not null references Address, ShipMethodID INTEGER not null references Address, CreditCardID INTEGER references CreditCard, CreditCardApprovalCode TEXT, CurrencyRateID INTEGER references CurrencyRate, SubTotal REAL default 0.0000 not null, TaxAmt REAL default 0.0000 not null, Freight REAL default 0.0000 not null, TotalDue REAL not null, Comment TEXT, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null );
world_development_indicators
Please list the countries in Latin America & Caribbean with a note on the series code SM.POP.TOTL.
Countries refer to the ShortName; Latin America & Caribbean is the name of the region
SELECT T1.SHORTNAME, T2.Description FROM Country AS T1 INNER JOIN CountryNotes AS T2 ON T1.CountryCode = T2.Countrycode WHERE T1.Region = 'Latin America & Caribbean' AND T2.Seriescode = 'SM.POP.TOTL'
CREATE TABLE IF NOT EXISTS "Country" ( CountryCode TEXT not null primary key, ShortName TEXT, TableName TEXT, LongName TEXT, Alpha2Code TEXT, CurrencyUnit TEXT, SpecialNotes TEXT, Region TEXT, IncomeGroup TEXT, Wb2Code TEXT, NationalAccountsBaseYear TEXT, NationalAccountsReferenceYear TEXT, SnaPriceValuation TEXT, LendingCategory TEXT, OtherGroups TEXT, SystemOfNationalAccounts TEXT, AlternativeConversionFactor TEXT, PppSurveyYear TEXT, BalanceOfPaymentsManualInUse TEXT, ExternalDebtReportingStatus TEXT, SystemOfTrade TEXT, GovernmentAccountingConcept TEXT, ImfDataDisseminationStandard TEXT, LatestPopulationCensus TEXT, LatestHouseholdSurvey TEXT, SourceOfMostRecentIncomeAndExpenditureData TEXT, VitalRegistrationComplete TEXT, LatestAgriculturalCensus TEXT, LatestIndustrialData INTEGER, LatestTradeData INTEGER, LatestWaterWithdrawalData INTEGER ); CREATE TABLE IF NOT EXISTS "Series" ( SeriesCode TEXT not null primary key, Topic TEXT, IndicatorName TEXT, ShortDefinition TEXT, LongDefinition TEXT, UnitOfMeasure TEXT, Periodicity TEXT, BasePeriod TEXT, OtherNotes INTEGER, AggregationMethod TEXT, LimitationsAndExceptions TEXT, NotesFromOriginalSource TEXT, GeneralComments TEXT, Source TEXT, StatisticalConceptAndMethodology TEXT, DevelopmentRelevance TEXT, RelatedSourceLinks TEXT, OtherWebLinks INTEGER, RelatedIndicators INTEGER, LicenseType TEXT ); CREATE TABLE CountryNotes ( Countrycode TEXT NOT NULL , Seriescode TEXT NOT NULL , Description TEXT, primary key (Countrycode, Seriescode), FOREIGN KEY (Seriescode) REFERENCES Series(SeriesCode), FOREIGN KEY (Countrycode) REFERENCES Country(CountryCode) ); CREATE TABLE Footnotes ( Countrycode TEXT NOT NULL , Seriescode TEXT NOT NULL , Year TEXT, Description TEXT, primary key (Countrycode, Seriescode, Year), FOREIGN KEY (Seriescode) REFERENCES Series(SeriesCode), FOREIGN KEY (Countrycode) REFERENCES Country(CountryCode) ); CREATE TABLE Indicators ( CountryName TEXT, CountryCode TEXT NOT NULL , IndicatorName TEXT, IndicatorCode TEXT NOT NULL , Year INTEGER NOT NULL , Value INTEGER, primary key (CountryCode, IndicatorCode, Year), FOREIGN KEY (CountryCode) REFERENCES Country(CountryCode) ); CREATE TABLE SeriesNotes ( Seriescode TEXT not null , Year TEXT not null , Description TEXT, primary key (Seriescode, Year), foreign key (Seriescode) references Series(SeriesCode) );
world
What country declared its independence in 1994?
declared independence in 1994 refers to IndepYear = 1994;
SELECT Name FROM Country WHERE IndepYear = 1994
CREATE TABLE sqlite_sequence(name,seq); CREATE TABLE `City` ( `ID` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, `Name` TEXT NOT NULL DEFAULT '', `CountryCode` TEXT NOT NULL DEFAULT '', `District` TEXT NOT NULL DEFAULT '', `Population` INTEGER NOT NULL DEFAULT 0, FOREIGN KEY (`CountryCode`) REFERENCES `Country` (`Code`) ); CREATE TABLE `Country` ( `Code` TEXT NOT NULL DEFAULT '', `Name` TEXT NOT NULL DEFAULT '', `Continent` TEXT NOT NULL DEFAULT 'Asia', `Region` TEXT NOT NULL DEFAULT '', `SurfaceArea` REAL NOT NULL DEFAULT 0.00, `IndepYear` INTEGER DEFAULT NULL, `Population` INTEGER NOT NULL DEFAULT 0, `LifeExpectancy` REAL DEFAULT NULL, `GNP` REAL DEFAULT NULL, `GNPOld` REAL DEFAULT NULL, `LocalName` TEXT NOT NULL DEFAULT '', `GovernmentForm` TEXT NOT NULL DEFAULT '', `HeadOfState` TEXT DEFAULT NULL, `Capital` INTEGER DEFAULT NULL, `Code2` TEXT NOT NULL DEFAULT '', PRIMARY KEY (`Code`) ); CREATE TABLE `CountryLanguage` ( `CountryCode` TEXT NOT NULL DEFAULT '', `Language` TEXT NOT NULL DEFAULT '', `IsOfficial`TEXT NOT NULL DEFAULT 'F', `Percentage` REAL NOT NULL DEFAULT 0.0, PRIMARY KEY (`CountryCode`,`Language`), FOREIGN KEY (`CountryCode`) REFERENCES `Country` (`Code`) );
books
What is the book with the most orders?
books refers to title; the most orders refers to Max(Count(order_id))
SELECT T2.title FROM order_line AS T1 INNER JOIN book AS T2 ON T1.book_id = T2.book_id GROUP BY T2.title ORDER BY COUNT(T1.book_id) DESC LIMIT 1
CREATE TABLE address_status ( status_id INTEGER primary key, address_status TEXT ); CREATE TABLE author ( author_id INTEGER primary key, author_name TEXT ); CREATE TABLE book_language ( language_id INTEGER primary key, language_code TEXT, language_name TEXT ); CREATE TABLE country ( country_id INTEGER primary key, country_name TEXT ); CREATE TABLE address ( address_id INTEGER primary key, street_number TEXT, street_name TEXT, city TEXT, country_id INTEGER, foreign key (country_id) references country(country_id) ); CREATE TABLE customer ( customer_id INTEGER primary key, first_name TEXT, last_name TEXT, email TEXT ); CREATE TABLE customer_address ( customer_id INTEGER, address_id INTEGER, status_id INTEGER, primary key (customer_id, address_id), foreign key (address_id) references address(address_id), foreign key (customer_id) references customer(customer_id) ); CREATE TABLE order_status ( status_id INTEGER primary key, status_value TEXT ); CREATE TABLE publisher ( publisher_id INTEGER primary key, publisher_name TEXT ); CREATE TABLE book ( book_id INTEGER primary key, title TEXT, isbn13 TEXT, language_id INTEGER, num_pages INTEGER, publication_date DATE, publisher_id INTEGER, foreign key (language_id) references book_language(language_id), foreign key (publisher_id) references publisher(publisher_id) ); CREATE TABLE book_author ( book_id INTEGER, author_id INTEGER, primary key (book_id, author_id), foreign key (author_id) references author(author_id), foreign key (book_id) references book(book_id) ); CREATE TABLE shipping_method ( method_id INTEGER primary key, method_name TEXT, cost REAL ); CREATE TABLE IF NOT EXISTS "cust_order" ( order_id INTEGER primary key autoincrement, order_date DATETIME, customer_id INTEGER references customer, shipping_method_id INTEGER references shipping_method, dest_address_id INTEGER references address ); CREATE TABLE sqlite_sequence(name,seq); CREATE TABLE IF NOT EXISTS "order_history" ( history_id INTEGER primary key autoincrement, order_id INTEGER references cust_order, status_id INTEGER references order_status, status_date DATETIME ); CREATE TABLE IF NOT EXISTS "order_line" ( line_id INTEGER primary key autoincrement, order_id INTEGER references cust_order, book_id INTEGER references book, price REAL );
simpson_episodes
What is the character that won the award in Primetime Emmy 2009?
won the award in Primetime Emmy 2009 refers to award_category = 'Primetime Emmy' and year = 2009
SELECT DISTINCT T2.character FROM Award AS T1 INNER JOIN Character_Award AS T2 ON T1.award_id = T2.award_id WHERE T1.award_category = 'Primetime Emmy' AND T1.year = 2009 AND T1.result = 'Winner';
CREATE TABLE IF NOT EXISTS "Episode" ( episode_id TEXT constraint Episode_pk primary key, season INTEGER, episode INTEGER, number_in_series INTEGER, title TEXT, summary TEXT, air_date TEXT, episode_image TEXT, rating REAL, votes INTEGER ); CREATE TABLE Person ( name TEXT constraint Person_pk primary key, birthdate TEXT, birth_name TEXT, birth_place TEXT, birth_region TEXT, birth_country TEXT, height_meters REAL, nickname TEXT ); CREATE TABLE Award ( award_id INTEGER primary key, organization TEXT, year INTEGER, award_category TEXT, award TEXT, person TEXT, role TEXT, episode_id TEXT, season TEXT, song TEXT, result TEXT, foreign key (person) references Person(name), foreign key (episode_id) references Episode(episode_id) ); CREATE TABLE Character_Award ( award_id INTEGER, character TEXT, foreign key (award_id) references Award(award_id) ); CREATE TABLE Credit ( episode_id TEXT, category TEXT, person TEXT, role TEXT, credited TEXT, foreign key (episode_id) references Episode(episode_id), foreign key (person) references Person(name) ); CREATE TABLE Keyword ( episode_id TEXT, keyword TEXT, primary key (episode_id, keyword), foreign key (episode_id) references Episode(episode_id) ); CREATE TABLE Vote ( episode_id TEXT, stars INTEGER, votes INTEGER, percent REAL, foreign key (episode_id) references Episode(episode_id) );
legislator
What is the religion with the most occurrrence of the current legislators?
religion with the most occurrrence of the current legislators refers to MAX(count(religion_bio));
SELECT religion_bio FROM current GROUP BY religion_bio ORDER BY COUNT(religion_bio) DESC LIMIT 1
CREATE TABLE current ( ballotpedia_id TEXT, bioguide_id TEXT, birthday_bio DATE, cspan_id REAL, fec_id TEXT, first_name TEXT, gender_bio TEXT, google_entity_id_id TEXT, govtrack_id INTEGER, house_history_id REAL, icpsr_id REAL, last_name TEXT, lis_id TEXT, maplight_id REAL, middle_name TEXT, nickname_name TEXT, official_full_name TEXT, opensecrets_id TEXT, religion_bio TEXT, suffix_name TEXT, thomas_id INTEGER, votesmart_id REAL, wikidata_id TEXT, wikipedia_id TEXT, primary key (bioguide_id, cspan_id) ); CREATE TABLE IF NOT EXISTS "current-terms" ( address TEXT, bioguide TEXT, caucus TEXT, chamber TEXT, class REAL, contact_form TEXT, district REAL, end TEXT, fax TEXT, last TEXT, name TEXT, office TEXT, party TEXT, party_affiliations TEXT, phone TEXT, relation TEXT, rss_url TEXT, start TEXT, state TEXT, state_rank TEXT, title TEXT, type TEXT, url TEXT, primary key (bioguide, end), foreign key (bioguide) references current(bioguide_id) ); CREATE TABLE historical ( ballotpedia_id TEXT, bioguide_id TEXT primary key, bioguide_previous_id TEXT, birthday_bio TEXT, cspan_id TEXT, fec_id TEXT, first_name TEXT, gender_bio TEXT, google_entity_id_id TEXT, govtrack_id INTEGER, house_history_alternate_id TEXT, house_history_id REAL, icpsr_id REAL, last_name TEXT, lis_id TEXT, maplight_id TEXT, middle_name TEXT, nickname_name TEXT, official_full_name TEXT, opensecrets_id TEXT, religion_bio TEXT, suffix_name TEXT, thomas_id TEXT, votesmart_id TEXT, wikidata_id TEXT, wikipedia_id TEXT ); CREATE TABLE IF NOT EXISTS "historical-terms" ( address TEXT, bioguide TEXT primary key, chamber TEXT, class REAL, contact_form TEXT, district REAL, end TEXT, fax TEXT, last TEXT, middle TEXT, name TEXT, office TEXT, party TEXT, party_affiliations TEXT, phone TEXT, relation TEXT, rss_url TEXT, start TEXT, state TEXT, state_rank TEXT, title TEXT, type TEXT, url TEXT, foreign key (bioguide) references historical(bioguide_id) ); CREATE TABLE IF NOT EXISTS "social-media" ( bioguide TEXT primary key, facebook TEXT, facebook_id REAL, govtrack REAL, instagram TEXT, instagram_id REAL, thomas INTEGER, twitter TEXT, twitter_id REAL, youtube TEXT, youtube_id TEXT, foreign key (bioguide) references current(bioguide_id) );
works_cycles
List all the names of the products with the price of more than 1000$.
ListPrice>1000;
SELECT DISTINCT T2.Name FROM ProductListPriceHistory AS T1 INNER JOIN Product AS T2 ON T1.ProductID = T2.ProductID WHERE T1.ListPrice > 1000
CREATE TABLE sqlite_sequence(name,seq); CREATE TABLE CountryRegion ( CountryRegionCode TEXT not null primary key, Name TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE Culture ( CultureID TEXT not null primary key, Name TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE Currency ( CurrencyCode TEXT not null primary key, Name TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE CountryRegionCurrency ( CountryRegionCode TEXT not null, CurrencyCode TEXT not null, ModifiedDate DATETIME default current_timestamp not null, primary key (CountryRegionCode, CurrencyCode), foreign key (CountryRegionCode) references CountryRegion(CountryRegionCode), foreign key (CurrencyCode) references Currency(CurrencyCode) ); CREATE TABLE Person ( BusinessEntityID INTEGER not null primary key, PersonType TEXT not null, NameStyle INTEGER default 0 not null, Title TEXT, FirstName TEXT not null, MiddleName TEXT, LastName TEXT not null, Suffix TEXT, EmailPromotion INTEGER default 0 not null, AdditionalContactInfo TEXT, Demographics TEXT, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null, foreign key (BusinessEntityID) references BusinessEntity(BusinessEntityID) ); CREATE TABLE BusinessEntityContact ( BusinessEntityID INTEGER not null, PersonID INTEGER not null, ContactTypeID INTEGER not null, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null, primary key (BusinessEntityID, PersonID, ContactTypeID), foreign key (BusinessEntityID) references BusinessEntity(BusinessEntityID), foreign key (ContactTypeID) references ContactType(ContactTypeID), foreign key (PersonID) references Person(BusinessEntityID) ); CREATE TABLE EmailAddress ( BusinessEntityID INTEGER not null, EmailAddressID INTEGER, EmailAddress TEXT, rowguid TEXT not null, ModifiedDate DATETIME default current_timestamp not null, primary key (EmailAddressID, BusinessEntityID), foreign key (BusinessEntityID) references Person(BusinessEntityID) ); CREATE TABLE Employee ( BusinessEntityID INTEGER not null primary key, NationalIDNumber TEXT not null unique, LoginID TEXT not null unique, OrganizationNode TEXT, OrganizationLevel INTEGER, JobTitle TEXT not null, BirthDate DATE not null, MaritalStatus TEXT not null, Gender TEXT not null, HireDate DATE not null, SalariedFlag INTEGER default 1 not null, VacationHours INTEGER default 0 not null, SickLeaveHours INTEGER default 0 not null, CurrentFlag INTEGER default 1 not null, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null, foreign key (BusinessEntityID) references Person(BusinessEntityID) ); CREATE TABLE Password ( BusinessEntityID INTEGER not null primary key, PasswordHash TEXT not null, PasswordSalt TEXT not null, rowguid TEXT not null, ModifiedDate DATETIME default current_timestamp not null, foreign key (BusinessEntityID) references Person(BusinessEntityID) ); CREATE TABLE PersonCreditCard ( BusinessEntityID INTEGER not null, CreditCardID INTEGER not null, ModifiedDate DATETIME default current_timestamp not null, primary key (BusinessEntityID, CreditCardID), foreign key (CreditCardID) references CreditCard(CreditCardID), foreign key (BusinessEntityID) references Person(BusinessEntityID) ); CREATE TABLE ProductCategory ( ProductCategoryID INTEGER primary key autoincrement, Name TEXT not null unique, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE ProductDescription ( ProductDescriptionID INTEGER primary key autoincrement, Description TEXT not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE ProductModel ( ProductModelID INTEGER primary key autoincrement, Name TEXT not null unique, CatalogDescription TEXT, Instructions TEXT, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE ProductModelProductDescriptionCulture ( ProductModelID INTEGER not null, ProductDescriptionID INTEGER not null, CultureID TEXT not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (ProductModelID, ProductDescriptionID, CultureID), foreign key (ProductModelID) references ProductModel(ProductModelID), foreign key (ProductDescriptionID) references ProductDescription(ProductDescriptionID), foreign key (CultureID) references Culture(CultureID) ); CREATE TABLE ProductPhoto ( ProductPhotoID INTEGER primary key autoincrement, ThumbNailPhoto BLOB, ThumbnailPhotoFileName TEXT, LargePhoto BLOB, LargePhotoFileName TEXT, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE ProductSubcategory ( ProductSubcategoryID INTEGER primary key autoincrement, ProductCategoryID INTEGER not null, Name TEXT not null unique, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (ProductCategoryID) references ProductCategory(ProductCategoryID) ); CREATE TABLE SalesReason ( SalesReasonID INTEGER primary key autoincrement, Name TEXT not null, ReasonType TEXT not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE SalesTerritory ( TerritoryID INTEGER primary key autoincrement, Name TEXT not null unique, CountryRegionCode TEXT not null, "Group" TEXT not null, SalesYTD REAL default 0.0000 not null, SalesLastYear REAL default 0.0000 not null, CostYTD REAL default 0.0000 not null, CostLastYear REAL default 0.0000 not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (CountryRegionCode) references CountryRegion(CountryRegionCode) ); CREATE TABLE SalesPerson ( BusinessEntityID INTEGER not null primary key, TerritoryID INTEGER, SalesQuota REAL, Bonus REAL default 0.0000 not null, CommissionPct REAL default 0.0000 not null, SalesYTD REAL default 0.0000 not null, SalesLastYear REAL default 0.0000 not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (BusinessEntityID) references Employee(BusinessEntityID), foreign key (TerritoryID) references SalesTerritory(TerritoryID) ); CREATE TABLE SalesPersonQuotaHistory ( BusinessEntityID INTEGER not null, QuotaDate DATETIME not null, SalesQuota REAL not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (BusinessEntityID, QuotaDate), foreign key (BusinessEntityID) references SalesPerson(BusinessEntityID) ); CREATE TABLE SalesTerritoryHistory ( BusinessEntityID INTEGER not null, TerritoryID INTEGER not null, StartDate DATETIME not null, EndDate DATETIME, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (BusinessEntityID, StartDate, TerritoryID), foreign key (BusinessEntityID) references SalesPerson(BusinessEntityID), foreign key (TerritoryID) references SalesTerritory(TerritoryID) ); CREATE TABLE ScrapReason ( ScrapReasonID INTEGER primary key autoincrement, Name TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE Shift ( ShiftID INTEGER primary key autoincrement, Name TEXT not null unique, StartTime TEXT not null, EndTime TEXT not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, unique (StartTime, EndTime) ); CREATE TABLE ShipMethod ( ShipMethodID INTEGER primary key autoincrement, Name TEXT not null unique, ShipBase REAL default 0.0000 not null, ShipRate REAL default 0.0000 not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE SpecialOffer ( SpecialOfferID INTEGER primary key autoincrement, Description TEXT not null, DiscountPct REAL default 0.0000 not null, Type TEXT not null, Category TEXT not null, StartDate DATETIME not null, EndDate DATETIME not null, MinQty INTEGER default 0 not null, MaxQty INTEGER, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE BusinessEntityAddress ( BusinessEntityID INTEGER not null, AddressID INTEGER not null, AddressTypeID INTEGER not null, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null, primary key (BusinessEntityID, AddressID, AddressTypeID), foreign key (AddressID) references Address(AddressID), foreign key (AddressTypeID) references AddressType(AddressTypeID), foreign key (BusinessEntityID) references BusinessEntity(BusinessEntityID) ); CREATE TABLE SalesTaxRate ( SalesTaxRateID INTEGER primary key autoincrement, StateProvinceID INTEGER not null, TaxType INTEGER not null, TaxRate REAL default 0.0000 not null, Name TEXT not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, unique (StateProvinceID, TaxType), foreign key (StateProvinceID) references StateProvince(StateProvinceID) ); CREATE TABLE Store ( BusinessEntityID INTEGER not null primary key, Name TEXT not null, SalesPersonID INTEGER, Demographics TEXT, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (BusinessEntityID) references BusinessEntity(BusinessEntityID), foreign key (SalesPersonID) references SalesPerson(BusinessEntityID) ); CREATE TABLE SalesOrderHeaderSalesReason ( SalesOrderID INTEGER not null, SalesReasonID INTEGER not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (SalesOrderID, SalesReasonID), foreign key (SalesOrderID) references SalesOrderHeader(SalesOrderID), foreign key (SalesReasonID) references SalesReason(SalesReasonID) ); CREATE TABLE TransactionHistoryArchive ( TransactionID INTEGER not null primary key, ProductID INTEGER not null, ReferenceOrderID INTEGER not null, ReferenceOrderLineID INTEGER default 0 not null, TransactionDate DATETIME default CURRENT_TIMESTAMP not null, TransactionType TEXT not null, Quantity INTEGER not null, ActualCost REAL not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE UnitMeasure ( UnitMeasureCode TEXT not null primary key, Name TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE ProductCostHistory ( ProductID INTEGER not null, StartDate DATE not null, EndDate DATE, StandardCost REAL not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (ProductID, StartDate), foreign key (ProductID) references Product(ProductID) ); CREATE TABLE ProductDocument ( ProductID INTEGER not null, DocumentNode TEXT not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (ProductID, DocumentNode), foreign key (ProductID) references Product(ProductID), foreign key (DocumentNode) references Document(DocumentNode) ); CREATE TABLE ProductInventory ( ProductID INTEGER not null, LocationID INTEGER not null, Shelf TEXT not null, Bin INTEGER not null, Quantity INTEGER default 0 not null, rowguid TEXT not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (ProductID, LocationID), foreign key (ProductID) references Product(ProductID), foreign key (LocationID) references Location(LocationID) ); CREATE TABLE ProductProductPhoto ( ProductID INTEGER not null, ProductPhotoID INTEGER not null, "Primary" INTEGER default 0 not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (ProductID, ProductPhotoID), foreign key (ProductID) references Product(ProductID), foreign key (ProductPhotoID) references ProductPhoto(ProductPhotoID) ); CREATE TABLE ProductReview ( ProductReviewID INTEGER primary key autoincrement, ProductID INTEGER not null, ReviewerName TEXT not null, ReviewDate DATETIME default CURRENT_TIMESTAMP not null, EmailAddress TEXT not null, Rating INTEGER not null, Comments TEXT, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (ProductID) references Product(ProductID) ); CREATE TABLE ShoppingCartItem ( ShoppingCartItemID INTEGER primary key autoincrement, ShoppingCartID TEXT not null, Quantity INTEGER default 1 not null, ProductID INTEGER not null, DateCreated DATETIME default CURRENT_TIMESTAMP not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (ProductID) references Product(ProductID) ); CREATE TABLE SpecialOfferProduct ( SpecialOfferID INTEGER not null, ProductID INTEGER not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (SpecialOfferID, ProductID), foreign key (SpecialOfferID) references SpecialOffer(SpecialOfferID), foreign key (ProductID) references Product(ProductID) ); CREATE TABLE SalesOrderDetail ( SalesOrderID INTEGER not null, SalesOrderDetailID INTEGER primary key autoincrement, CarrierTrackingNumber TEXT, OrderQty INTEGER not null, ProductID INTEGER not null, SpecialOfferID INTEGER not null, UnitPrice REAL not null, UnitPriceDiscount REAL default 0.0000 not null, LineTotal REAL not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (SalesOrderID) references SalesOrderHeader(SalesOrderID), foreign key (SpecialOfferID, ProductID) references SpecialOfferProduct(SpecialOfferID, ProductID) ); CREATE TABLE TransactionHistory ( TransactionID INTEGER primary key autoincrement, ProductID INTEGER not null, ReferenceOrderID INTEGER not null, ReferenceOrderLineID INTEGER default 0 not null, TransactionDate DATETIME default CURRENT_TIMESTAMP not null, TransactionType TEXT not null, Quantity INTEGER not null, ActualCost REAL not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (ProductID) references Product(ProductID) ); CREATE TABLE Vendor ( BusinessEntityID INTEGER not null primary key, AccountNumber TEXT not null unique, Name TEXT not null, CreditRating INTEGER not null, PreferredVendorStatus INTEGER default 1 not null, ActiveFlag INTEGER default 1 not null, PurchasingWebServiceURL TEXT, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (BusinessEntityID) references BusinessEntity(BusinessEntityID) ); CREATE TABLE ProductVendor ( ProductID INTEGER not null, BusinessEntityID INTEGER not null, AverageLeadTime INTEGER not null, StandardPrice REAL not null, LastReceiptCost REAL, LastReceiptDate DATETIME, MinOrderQty INTEGER not null, MaxOrderQty INTEGER not null, OnOrderQty INTEGER, UnitMeasureCode TEXT not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (ProductID, BusinessEntityID), foreign key (ProductID) references Product(ProductID), foreign key (BusinessEntityID) references Vendor(BusinessEntityID), foreign key (UnitMeasureCode) references UnitMeasure(UnitMeasureCode) ); CREATE TABLE PurchaseOrderHeader ( PurchaseOrderID INTEGER primary key autoincrement, RevisionNumber INTEGER default 0 not null, Status INTEGER default 1 not null, EmployeeID INTEGER not null, VendorID INTEGER not null, ShipMethodID INTEGER not null, OrderDate DATETIME default CURRENT_TIMESTAMP not null, ShipDate DATETIME, SubTotal REAL default 0.0000 not null, TaxAmt REAL default 0.0000 not null, Freight REAL default 0.0000 not null, TotalDue REAL not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (EmployeeID) references Employee(BusinessEntityID), foreign key (VendorID) references Vendor(BusinessEntityID), foreign key (ShipMethodID) references ShipMethod(ShipMethodID) ); CREATE TABLE PurchaseOrderDetail ( PurchaseOrderID INTEGER not null, PurchaseOrderDetailID INTEGER primary key autoincrement, DueDate DATETIME not null, OrderQty INTEGER not null, ProductID INTEGER not null, UnitPrice REAL not null, LineTotal REAL not null, ReceivedQty REAL not null, RejectedQty REAL not null, StockedQty REAL not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (PurchaseOrderID) references PurchaseOrderHeader(PurchaseOrderID), foreign key (ProductID) references Product(ProductID) ); CREATE TABLE WorkOrder ( WorkOrderID INTEGER primary key autoincrement, ProductID INTEGER not null, OrderQty INTEGER not null, StockedQty INTEGER not null, ScrappedQty INTEGER not null, StartDate DATETIME not null, EndDate DATETIME, DueDate DATETIME not null, ScrapReasonID INTEGER, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (ProductID) references Product(ProductID), foreign key (ScrapReasonID) references ScrapReason(ScrapReasonID) ); CREATE TABLE WorkOrderRouting ( WorkOrderID INTEGER not null, ProductID INTEGER not null, OperationSequence INTEGER not null, LocationID INTEGER not null, ScheduledStartDate DATETIME not null, ScheduledEndDate DATETIME not null, ActualStartDate DATETIME, ActualEndDate DATETIME, ActualResourceHrs REAL, PlannedCost REAL not null, ActualCost REAL, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (WorkOrderID, ProductID, OperationSequence), foreign key (WorkOrderID) references WorkOrder(WorkOrderID), foreign key (LocationID) references Location(LocationID) ); CREATE TABLE Customer ( CustomerID INTEGER primary key, PersonID INTEGER, StoreID INTEGER, TerritoryID INTEGER, AccountNumber TEXT not null unique, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null, foreign key (PersonID) references Person(BusinessEntityID), foreign key (TerritoryID) references SalesTerritory(TerritoryID), foreign key (StoreID) references Store(BusinessEntityID) ); CREATE TABLE ProductListPriceHistory ( ProductID INTEGER not null, StartDate DATE not null, EndDate DATE, ListPrice REAL not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (ProductID, StartDate), foreign key (ProductID) references Product(ProductID) ); CREATE TABLE IF NOT EXISTS "Address" ( AddressID INTEGER primary key autoincrement, AddressLine1 TEXT not null, AddressLine2 TEXT, City TEXT not null, StateProvinceID INTEGER not null references StateProvince, PostalCode TEXT not null, SpatialLocation TEXT, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null, unique (AddressLine1, AddressLine2, City, StateProvinceID, PostalCode) ); CREATE TABLE IF NOT EXISTS "AddressType" ( AddressTypeID INTEGER primary key autoincrement, Name TEXT not null unique, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "BillOfMaterials" ( BillOfMaterialsID INTEGER primary key autoincrement, ProductAssemblyID INTEGER references Product, ComponentID INTEGER not null references Product, StartDate DATETIME default current_timestamp not null, EndDate DATETIME, UnitMeasureCode TEXT not null references UnitMeasure, BOMLevel INTEGER not null, PerAssemblyQty REAL default 1.00 not null, ModifiedDate DATETIME default current_timestamp not null, unique (ProductAssemblyID, ComponentID, StartDate) ); CREATE TABLE IF NOT EXISTS "BusinessEntity" ( BusinessEntityID INTEGER primary key autoincrement, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "ContactType" ( ContactTypeID INTEGER primary key autoincrement, Name TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "CurrencyRate" ( CurrencyRateID INTEGER primary key autoincrement, CurrencyRateDate DATETIME not null, FromCurrencyCode TEXT not null references Currency, ToCurrencyCode TEXT not null references Currency, AverageRate REAL not null, EndOfDayRate REAL not null, ModifiedDate DATETIME default current_timestamp not null, unique (CurrencyRateDate, FromCurrencyCode, ToCurrencyCode) ); CREATE TABLE IF NOT EXISTS "Department" ( DepartmentID INTEGER primary key autoincrement, Name TEXT not null unique, GroupName TEXT not null, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "EmployeeDepartmentHistory" ( BusinessEntityID INTEGER not null references Employee, DepartmentID INTEGER not null references Department, ShiftID INTEGER not null references Shift, StartDate DATE not null, EndDate DATE, ModifiedDate DATETIME default current_timestamp not null, primary key (BusinessEntityID, StartDate, DepartmentID, ShiftID) ); CREATE TABLE IF NOT EXISTS "EmployeePayHistory" ( BusinessEntityID INTEGER not null references Employee, RateChangeDate DATETIME not null, Rate REAL not null, PayFrequency INTEGER not null, ModifiedDate DATETIME default current_timestamp not null, primary key (BusinessEntityID, RateChangeDate) ); CREATE TABLE IF NOT EXISTS "JobCandidate" ( JobCandidateID INTEGER primary key autoincrement, BusinessEntityID INTEGER references Employee, Resume TEXT, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "Location" ( LocationID INTEGER primary key autoincrement, Name TEXT not null unique, CostRate REAL default 0.0000 not null, Availability REAL default 0.00 not null, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "PhoneNumberType" ( PhoneNumberTypeID INTEGER primary key autoincrement, Name TEXT not null, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "Product" ( ProductID INTEGER primary key autoincrement, Name TEXT not null unique, ProductNumber TEXT not null unique, MakeFlag INTEGER default 1 not null, FinishedGoodsFlag INTEGER default 1 not null, Color TEXT, SafetyStockLevel INTEGER not null, ReorderPoint INTEGER not null, StandardCost REAL not null, ListPrice REAL not null, Size TEXT, SizeUnitMeasureCode TEXT references UnitMeasure, WeightUnitMeasureCode TEXT references UnitMeasure, Weight REAL, DaysToManufacture INTEGER not null, ProductLine TEXT, Class TEXT, Style TEXT, ProductSubcategoryID INTEGER references ProductSubcategory, ProductModelID INTEGER references ProductModel, SellStartDate DATETIME not null, SellEndDate DATETIME, DiscontinuedDate DATETIME, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "Document" ( DocumentNode TEXT not null primary key, DocumentLevel INTEGER, Title TEXT not null, Owner INTEGER not null references Employee, FolderFlag INTEGER default 0 not null, FileName TEXT not null, FileExtension TEXT not null, Revision TEXT not null, ChangeNumber INTEGER default 0 not null, Status INTEGER not null, DocumentSummary TEXT, Document BLOB, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null, unique (DocumentLevel, DocumentNode) ); CREATE TABLE IF NOT EXISTS "StateProvince" ( StateProvinceID INTEGER primary key autoincrement, StateProvinceCode TEXT not null, CountryRegionCode TEXT not null references CountryRegion, IsOnlyStateProvinceFlag INTEGER default 1 not null, Name TEXT not null unique, TerritoryID INTEGER not null references SalesTerritory, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, unique (StateProvinceCode, CountryRegionCode) ); CREATE TABLE IF NOT EXISTS "CreditCard" ( CreditCardID INTEGER primary key autoincrement, CardType TEXT not null, CardNumber TEXT not null unique, ExpMonth INTEGER not null, ExpYear INTEGER not null, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "SalesOrderHeader" ( SalesOrderID INTEGER primary key autoincrement, RevisionNumber INTEGER default 0 not null, OrderDate DATETIME default CURRENT_TIMESTAMP not null, DueDate DATETIME not null, ShipDate DATETIME, Status INTEGER default 1 not null, OnlineOrderFlag INTEGER default 1 not null, SalesOrderNumber TEXT not null unique, PurchaseOrderNumber TEXT, AccountNumber TEXT, CustomerID INTEGER not null references Customer, SalesPersonID INTEGER references SalesPerson, TerritoryID INTEGER references SalesTerritory, BillToAddressID INTEGER not null references Address, ShipToAddressID INTEGER not null references Address, ShipMethodID INTEGER not null references Address, CreditCardID INTEGER references CreditCard, CreditCardApprovalCode TEXT, CurrencyRateID INTEGER references CurrencyRate, SubTotal REAL default 0.0000 not null, TaxAmt REAL default 0.0000 not null, Freight REAL default 0.0000 not null, TotalDue REAL not null, Comment TEXT, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null );
cookbook
What are the names of the recipes that will cause stomach pain?
cause stomach pain refers to iron > 20
SELECT T1.title FROM Recipe AS T1 INNER JOIN Nutrition AS T2 ON T1.recipe_id = T2.recipe_id WHERE T2.iron > 20
CREATE TABLE Ingredient ( ingredient_id INTEGER primary key, category TEXT, name TEXT, plural TEXT ); CREATE TABLE Recipe ( recipe_id INTEGER primary key, title TEXT, subtitle TEXT, servings INTEGER, yield_unit TEXT, prep_min INTEGER, cook_min INTEGER, stnd_min INTEGER, source TEXT, intro TEXT, directions TEXT ); CREATE TABLE Nutrition ( recipe_id INTEGER primary key, protein REAL, carbo REAL, alcohol REAL, total_fat REAL, sat_fat REAL, cholestrl REAL, sodium REAL, iron REAL, vitamin_c REAL, vitamin_a REAL, fiber REAL, pcnt_cal_carb REAL, pcnt_cal_fat REAL, pcnt_cal_prot REAL, calories REAL, foreign key (recipe_id) references Recipe(recipe_id) ); CREATE TABLE Quantity ( quantity_id INTEGER primary key, recipe_id INTEGER, ingredient_id INTEGER, max_qty REAL, min_qty REAL, unit TEXT, preparation TEXT, optional TEXT, foreign key (recipe_id) references Recipe(recipe_id), foreign key (ingredient_id) references Ingredient(ingredient_id), foreign key (recipe_id) references Nutrition(recipe_id) );
movie_platform
What is Jeannot Szwarc's most popular movie and what is its average rating score?
Jeannot Szwarc's refers to director_name = 'Jeannot Szwarc'; most popular movie refers to MAX(movie_popularity); average rating score refers to avg(rating_score)
SELECT T2.movie_title, AVG(T1.rating_score) FROM ratings AS T1 INNER JOIN movies AS T2 ON T1.movie_id = T2.movie_id WHERE T2.director_name = 'Jeannot Szwarc' ORDER BY T2.movie_popularity DESC LIMIT 1
CREATE TABLE IF NOT EXISTS "lists" ( user_id INTEGER references lists_users (user_id), list_id INTEGER not null primary key, list_title TEXT, list_movie_number INTEGER, list_update_timestamp_utc TEXT, list_creation_timestamp_utc TEXT, list_followers INTEGER, list_url TEXT, list_comments INTEGER, list_description TEXT, list_cover_image_url TEXT, list_first_image_url TEXT, list_second_image_url TEXT, list_third_image_url TEXT ); CREATE TABLE IF NOT EXISTS "movies" ( movie_id INTEGER not null primary key, movie_title TEXT, movie_release_year INTEGER, movie_url TEXT, movie_title_language TEXT, movie_popularity INTEGER, movie_image_url TEXT, director_id TEXT, director_name TEXT, director_url TEXT ); CREATE TABLE IF NOT EXISTS "ratings_users" ( user_id INTEGER references lists_users (user_id), rating_date_utc TEXT, user_trialist INTEGER, user_subscriber INTEGER, user_avatar_image_url TEXT, user_cover_image_url TEXT, user_eligible_for_trial INTEGER, user_has_payment_method INTEGER ); CREATE TABLE lists_users ( user_id INTEGER not null , list_id INTEGER not null , list_update_date_utc TEXT, list_creation_date_utc TEXT, user_trialist INTEGER, user_subscriber INTEGER, user_avatar_image_url TEXT, user_cover_image_url TEXT, user_eligible_for_trial TEXT, user_has_payment_method TEXT, primary key (user_id, list_id), foreign key (list_id) references lists(list_id), foreign key (user_id) references lists(user_id) ); CREATE TABLE ratings ( movie_id INTEGER, rating_id INTEGER, rating_url TEXT, rating_score INTEGER, rating_timestamp_utc TEXT, critic TEXT, critic_likes INTEGER, critic_comments INTEGER, user_id INTEGER, user_trialist INTEGER, user_subscriber INTEGER, user_eligible_for_trial INTEGER, user_has_payment_method INTEGER, foreign key (movie_id) references movies(movie_id), foreign key (user_id) references lists_users(user_id), foreign key (rating_id) references ratings(rating_id), foreign key (user_id) references ratings_users(user_id) );
talkingdata
How many of the apps belong in the "Equity Fund" category?
SELECT COUNT(T1.app_id) FROM app_labels AS T1 INNER JOIN label_categories AS T2 ON T1.label_id = T2.label_id WHERE T2.category = 'Equity Fund'
CREATE TABLE `app_all` ( `app_id` INTEGER NOT NULL, PRIMARY KEY (`app_id`) ); CREATE TABLE `app_events` ( `event_id` INTEGER NOT NULL, `app_id` INTEGER NOT NULL, `is_installed` INTEGER NOT NULL, `is_active` INTEGER NOT NULL, PRIMARY KEY (`event_id`,`app_id`), FOREIGN KEY (`event_id`) REFERENCES `events` (`event_id`) ON DELETE CASCADE ON UPDATE CASCADE ); CREATE TABLE `app_events_relevant` ( `event_id` INTEGER NOT NULL, `app_id` INTEGER NOT NULL, `is_installed` INTEGER DEFAULT NULL, `is_active` INTEGER DEFAULT NULL, PRIMARY KEY (`event_id`,`app_id`), FOREIGN KEY (`event_id`) REFERENCES `events_relevant` (`event_id`) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (`app_id`) REFERENCES `app_all` (`app_id`) ON DELETE CASCADE ON UPDATE CASCADE ); CREATE TABLE `app_labels` ( `app_id` INTEGER NOT NULL, `label_id` INTEGER NOT NULL, FOREIGN KEY (`label_id`) REFERENCES `label_categories` (`label_id`) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (`app_id`) REFERENCES `app_all` (`app_id`) ON DELETE CASCADE ON UPDATE CASCADE ); CREATE TABLE `events` ( `event_id` INTEGER NOT NULL, `device_id` INTEGER DEFAULT NULL, `timestamp` DATETIME DEFAULT NULL, `longitude` REAL DEFAULT NULL, `latitude` REAL DEFAULT NULL, PRIMARY KEY (`event_id`) ); CREATE TABLE `events_relevant` ( `event_id` INTEGER NOT NULL, `device_id` INTEGER DEFAULT NULL, `timestamp` DATETIME NOT NULL, `longitude` REAL NOT NULL, `latitude` REAL NOT NULL, PRIMARY KEY (`event_id`), FOREIGN KEY (`device_id`) REFERENCES `gender_age` (`device_id`) ON DELETE CASCADE ON UPDATE CASCADE ); CREATE TABLE `gender_age` ( `device_id` INTEGER NOT NULL, `gender` TEXT DEFAULT NULL, `age` INTEGER DEFAULT NULL, `group` TEXT DEFAULT NULL, PRIMARY KEY (`device_id`), FOREIGN KEY (`device_id`) REFERENCES `phone_brand_device_model2` (`device_id`) ON DELETE CASCADE ON UPDATE CASCADE ); CREATE TABLE `gender_age_test` ( `device_id` INTEGER NOT NULL, PRIMARY KEY (`device_id`) ); CREATE TABLE `gender_age_train` ( `device_id` INTEGER NOT NULL, `gender` TEXT DEFAULT NULL, `age` INTEGER DEFAULT NULL, `group` TEXT DEFAULT NULL, PRIMARY KEY (`device_id`) ); CREATE TABLE `label_categories` ( `label_id` INTEGER NOT NULL, `category` TEXT DEFAULT NULL, PRIMARY KEY (`label_id`) ); CREATE TABLE `phone_brand_device_model2` ( `device_id` INTEGER NOT NULL, `phone_brand` TEXT NOT NULL, `device_model` TEXT NOT NULL, PRIMARY KEY (`device_id`,`phone_brand`,`device_model`) ); CREATE TABLE `sample_submission` ( `device_id` INTEGER NOT NULL, `F23-` REAL DEFAULT NULL, `F24-26` REAL DEFAULT NULL, `F27-28` REAL DEFAULT NULL, `F29-32` REAL DEFAULT NULL, `F33-42` REAL DEFAULT NULL, `F43+` REAL DEFAULT NULL, `M22-` REAL DEFAULT NULL, `M23-26` REAL DEFAULT NULL, `M27-28` REAL DEFAULT NULL, `M29-31` REAL DEFAULT NULL, `M32-38` REAL DEFAULT NULL, `M39+` REAL DEFAULT NULL, PRIMARY KEY (`device_id`) );
restaurant
List the food type of the restaurant located in 22779 6th St., Hayward City.
22779 refers to street_num = 22779; 6th St. refers to street_name = '6th St'
SELECT T2.food_type FROM location AS T1 INNER JOIN generalinfo AS T2 ON T1.id_restaurant = T2.id_restaurant WHERE T1.street_num = 22779 AND T1.street_name = '6th St' AND T2.city = 'hayward'
CREATE TABLE geographic ( city TEXT not null primary key, county TEXT null, region TEXT null ); CREATE TABLE generalinfo ( id_restaurant INTEGER not null primary key, label TEXT null, food_type TEXT null, city TEXT null, review REAL null, foreign key (city) references geographic(city) on update cascade on delete cascade ); CREATE TABLE location ( id_restaurant INTEGER not null primary key, street_num INTEGER null, street_name TEXT null, city TEXT null, foreign key (city) references geographic (city) on update cascade on delete cascade, foreign key (id_restaurant) references generalinfo (id_restaurant) on update cascade on delete cascade );
music_tracker
How many releases are tagged "1980s"?
tag = '1980s';
SELECT COUNT(id) FROM tags WHERE tag LIKE '1980s'
CREATE TABLE IF NOT EXISTS "torrents" ( groupName TEXT, totalSnatched INTEGER, artist TEXT, groupYear INTEGER, releaseType TEXT, groupId INTEGER, id INTEGER constraint torrents_pk primary key ); CREATE TABLE IF NOT EXISTS "tags" ( "index" INTEGER constraint tags_pk primary key, id INTEGER constraint tags_torrents_id_fk references torrents, tag TEXT ); CREATE INDEX ix_tags_index on tags ("index");
works_cycles
Among the vendors with maximum orders betweeen 500 to 750, which vendor has the 10th highest profit on net?
maximum orders refers to MaxOrderQty; MaxOrderQty BETWEEN '500' AND '750'; profit on net = SUBTRACT(LastReceiptCost, StandardPrice);
SELECT T2.Name FROM ProductVendor AS T1 INNER JOIN Vendor AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID WHERE T1.MaxOrderQty BETWEEN 500 AND 750 ORDER BY T1.LastReceiptCost - T1.StandardPrice DESC LIMIT 9, 1
CREATE TABLE sqlite_sequence(name,seq); CREATE TABLE CountryRegion ( CountryRegionCode TEXT not null primary key, Name TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE Culture ( CultureID TEXT not null primary key, Name TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE Currency ( CurrencyCode TEXT not null primary key, Name TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE CountryRegionCurrency ( CountryRegionCode TEXT not null, CurrencyCode TEXT not null, ModifiedDate DATETIME default current_timestamp not null, primary key (CountryRegionCode, CurrencyCode), foreign key (CountryRegionCode) references CountryRegion(CountryRegionCode), foreign key (CurrencyCode) references Currency(CurrencyCode) ); CREATE TABLE Person ( BusinessEntityID INTEGER not null primary key, PersonType TEXT not null, NameStyle INTEGER default 0 not null, Title TEXT, FirstName TEXT not null, MiddleName TEXT, LastName TEXT not null, Suffix TEXT, EmailPromotion INTEGER default 0 not null, AdditionalContactInfo TEXT, Demographics TEXT, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null, foreign key (BusinessEntityID) references BusinessEntity(BusinessEntityID) ); CREATE TABLE BusinessEntityContact ( BusinessEntityID INTEGER not null, PersonID INTEGER not null, ContactTypeID INTEGER not null, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null, primary key (BusinessEntityID, PersonID, ContactTypeID), foreign key (BusinessEntityID) references BusinessEntity(BusinessEntityID), foreign key (ContactTypeID) references ContactType(ContactTypeID), foreign key (PersonID) references Person(BusinessEntityID) ); CREATE TABLE EmailAddress ( BusinessEntityID INTEGER not null, EmailAddressID INTEGER, EmailAddress TEXT, rowguid TEXT not null, ModifiedDate DATETIME default current_timestamp not null, primary key (EmailAddressID, BusinessEntityID), foreign key (BusinessEntityID) references Person(BusinessEntityID) ); CREATE TABLE Employee ( BusinessEntityID INTEGER not null primary key, NationalIDNumber TEXT not null unique, LoginID TEXT not null unique, OrganizationNode TEXT, OrganizationLevel INTEGER, JobTitle TEXT not null, BirthDate DATE not null, MaritalStatus TEXT not null, Gender TEXT not null, HireDate DATE not null, SalariedFlag INTEGER default 1 not null, VacationHours INTEGER default 0 not null, SickLeaveHours INTEGER default 0 not null, CurrentFlag INTEGER default 1 not null, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null, foreign key (BusinessEntityID) references Person(BusinessEntityID) ); CREATE TABLE Password ( BusinessEntityID INTEGER not null primary key, PasswordHash TEXT not null, PasswordSalt TEXT not null, rowguid TEXT not null, ModifiedDate DATETIME default current_timestamp not null, foreign key (BusinessEntityID) references Person(BusinessEntityID) ); CREATE TABLE PersonCreditCard ( BusinessEntityID INTEGER not null, CreditCardID INTEGER not null, ModifiedDate DATETIME default current_timestamp not null, primary key (BusinessEntityID, CreditCardID), foreign key (CreditCardID) references CreditCard(CreditCardID), foreign key (BusinessEntityID) references Person(BusinessEntityID) ); CREATE TABLE ProductCategory ( ProductCategoryID INTEGER primary key autoincrement, Name TEXT not null unique, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE ProductDescription ( ProductDescriptionID INTEGER primary key autoincrement, Description TEXT not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE ProductModel ( ProductModelID INTEGER primary key autoincrement, Name TEXT not null unique, CatalogDescription TEXT, Instructions TEXT, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE ProductModelProductDescriptionCulture ( ProductModelID INTEGER not null, ProductDescriptionID INTEGER not null, CultureID TEXT not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (ProductModelID, ProductDescriptionID, CultureID), foreign key (ProductModelID) references ProductModel(ProductModelID), foreign key (ProductDescriptionID) references ProductDescription(ProductDescriptionID), foreign key (CultureID) references Culture(CultureID) ); CREATE TABLE ProductPhoto ( ProductPhotoID INTEGER primary key autoincrement, ThumbNailPhoto BLOB, ThumbnailPhotoFileName TEXT, LargePhoto BLOB, LargePhotoFileName TEXT, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE ProductSubcategory ( ProductSubcategoryID INTEGER primary key autoincrement, ProductCategoryID INTEGER not null, Name TEXT not null unique, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (ProductCategoryID) references ProductCategory(ProductCategoryID) ); CREATE TABLE SalesReason ( SalesReasonID INTEGER primary key autoincrement, Name TEXT not null, ReasonType TEXT not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE SalesTerritory ( TerritoryID INTEGER primary key autoincrement, Name TEXT not null unique, CountryRegionCode TEXT not null, "Group" TEXT not null, SalesYTD REAL default 0.0000 not null, SalesLastYear REAL default 0.0000 not null, CostYTD REAL default 0.0000 not null, CostLastYear REAL default 0.0000 not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (CountryRegionCode) references CountryRegion(CountryRegionCode) ); CREATE TABLE SalesPerson ( BusinessEntityID INTEGER not null primary key, TerritoryID INTEGER, SalesQuota REAL, Bonus REAL default 0.0000 not null, CommissionPct REAL default 0.0000 not null, SalesYTD REAL default 0.0000 not null, SalesLastYear REAL default 0.0000 not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (BusinessEntityID) references Employee(BusinessEntityID), foreign key (TerritoryID) references SalesTerritory(TerritoryID) ); CREATE TABLE SalesPersonQuotaHistory ( BusinessEntityID INTEGER not null, QuotaDate DATETIME not null, SalesQuota REAL not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (BusinessEntityID, QuotaDate), foreign key (BusinessEntityID) references SalesPerson(BusinessEntityID) ); CREATE TABLE SalesTerritoryHistory ( BusinessEntityID INTEGER not null, TerritoryID INTEGER not null, StartDate DATETIME not null, EndDate DATETIME, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (BusinessEntityID, StartDate, TerritoryID), foreign key (BusinessEntityID) references SalesPerson(BusinessEntityID), foreign key (TerritoryID) references SalesTerritory(TerritoryID) ); CREATE TABLE ScrapReason ( ScrapReasonID INTEGER primary key autoincrement, Name TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE Shift ( ShiftID INTEGER primary key autoincrement, Name TEXT not null unique, StartTime TEXT not null, EndTime TEXT not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, unique (StartTime, EndTime) ); CREATE TABLE ShipMethod ( ShipMethodID INTEGER primary key autoincrement, Name TEXT not null unique, ShipBase REAL default 0.0000 not null, ShipRate REAL default 0.0000 not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE SpecialOffer ( SpecialOfferID INTEGER primary key autoincrement, Description TEXT not null, DiscountPct REAL default 0.0000 not null, Type TEXT not null, Category TEXT not null, StartDate DATETIME not null, EndDate DATETIME not null, MinQty INTEGER default 0 not null, MaxQty INTEGER, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE BusinessEntityAddress ( BusinessEntityID INTEGER not null, AddressID INTEGER not null, AddressTypeID INTEGER not null, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null, primary key (BusinessEntityID, AddressID, AddressTypeID), foreign key (AddressID) references Address(AddressID), foreign key (AddressTypeID) references AddressType(AddressTypeID), foreign key (BusinessEntityID) references BusinessEntity(BusinessEntityID) ); CREATE TABLE SalesTaxRate ( SalesTaxRateID INTEGER primary key autoincrement, StateProvinceID INTEGER not null, TaxType INTEGER not null, TaxRate REAL default 0.0000 not null, Name TEXT not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, unique (StateProvinceID, TaxType), foreign key (StateProvinceID) references StateProvince(StateProvinceID) ); CREATE TABLE Store ( BusinessEntityID INTEGER not null primary key, Name TEXT not null, SalesPersonID INTEGER, Demographics TEXT, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (BusinessEntityID) references BusinessEntity(BusinessEntityID), foreign key (SalesPersonID) references SalesPerson(BusinessEntityID) ); CREATE TABLE SalesOrderHeaderSalesReason ( SalesOrderID INTEGER not null, SalesReasonID INTEGER not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (SalesOrderID, SalesReasonID), foreign key (SalesOrderID) references SalesOrderHeader(SalesOrderID), foreign key (SalesReasonID) references SalesReason(SalesReasonID) ); CREATE TABLE TransactionHistoryArchive ( TransactionID INTEGER not null primary key, ProductID INTEGER not null, ReferenceOrderID INTEGER not null, ReferenceOrderLineID INTEGER default 0 not null, TransactionDate DATETIME default CURRENT_TIMESTAMP not null, TransactionType TEXT not null, Quantity INTEGER not null, ActualCost REAL not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE UnitMeasure ( UnitMeasureCode TEXT not null primary key, Name TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE ProductCostHistory ( ProductID INTEGER not null, StartDate DATE not null, EndDate DATE, StandardCost REAL not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (ProductID, StartDate), foreign key (ProductID) references Product(ProductID) ); CREATE TABLE ProductDocument ( ProductID INTEGER not null, DocumentNode TEXT not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (ProductID, DocumentNode), foreign key (ProductID) references Product(ProductID), foreign key (DocumentNode) references Document(DocumentNode) ); CREATE TABLE ProductInventory ( ProductID INTEGER not null, LocationID INTEGER not null, Shelf TEXT not null, Bin INTEGER not null, Quantity INTEGER default 0 not null, rowguid TEXT not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (ProductID, LocationID), foreign key (ProductID) references Product(ProductID), foreign key (LocationID) references Location(LocationID) ); CREATE TABLE ProductProductPhoto ( ProductID INTEGER not null, ProductPhotoID INTEGER not null, "Primary" INTEGER default 0 not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (ProductID, ProductPhotoID), foreign key (ProductID) references Product(ProductID), foreign key (ProductPhotoID) references ProductPhoto(ProductPhotoID) ); CREATE TABLE ProductReview ( ProductReviewID INTEGER primary key autoincrement, ProductID INTEGER not null, ReviewerName TEXT not null, ReviewDate DATETIME default CURRENT_TIMESTAMP not null, EmailAddress TEXT not null, Rating INTEGER not null, Comments TEXT, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (ProductID) references Product(ProductID) ); CREATE TABLE ShoppingCartItem ( ShoppingCartItemID INTEGER primary key autoincrement, ShoppingCartID TEXT not null, Quantity INTEGER default 1 not null, ProductID INTEGER not null, DateCreated DATETIME default CURRENT_TIMESTAMP not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (ProductID) references Product(ProductID) ); CREATE TABLE SpecialOfferProduct ( SpecialOfferID INTEGER not null, ProductID INTEGER not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (SpecialOfferID, ProductID), foreign key (SpecialOfferID) references SpecialOffer(SpecialOfferID), foreign key (ProductID) references Product(ProductID) ); CREATE TABLE SalesOrderDetail ( SalesOrderID INTEGER not null, SalesOrderDetailID INTEGER primary key autoincrement, CarrierTrackingNumber TEXT, OrderQty INTEGER not null, ProductID INTEGER not null, SpecialOfferID INTEGER not null, UnitPrice REAL not null, UnitPriceDiscount REAL default 0.0000 not null, LineTotal REAL not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (SalesOrderID) references SalesOrderHeader(SalesOrderID), foreign key (SpecialOfferID, ProductID) references SpecialOfferProduct(SpecialOfferID, ProductID) ); CREATE TABLE TransactionHistory ( TransactionID INTEGER primary key autoincrement, ProductID INTEGER not null, ReferenceOrderID INTEGER not null, ReferenceOrderLineID INTEGER default 0 not null, TransactionDate DATETIME default CURRENT_TIMESTAMP not null, TransactionType TEXT not null, Quantity INTEGER not null, ActualCost REAL not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (ProductID) references Product(ProductID) ); CREATE TABLE Vendor ( BusinessEntityID INTEGER not null primary key, AccountNumber TEXT not null unique, Name TEXT not null, CreditRating INTEGER not null, PreferredVendorStatus INTEGER default 1 not null, ActiveFlag INTEGER default 1 not null, PurchasingWebServiceURL TEXT, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (BusinessEntityID) references BusinessEntity(BusinessEntityID) ); CREATE TABLE ProductVendor ( ProductID INTEGER not null, BusinessEntityID INTEGER not null, AverageLeadTime INTEGER not null, StandardPrice REAL not null, LastReceiptCost REAL, LastReceiptDate DATETIME, MinOrderQty INTEGER not null, MaxOrderQty INTEGER not null, OnOrderQty INTEGER, UnitMeasureCode TEXT not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (ProductID, BusinessEntityID), foreign key (ProductID) references Product(ProductID), foreign key (BusinessEntityID) references Vendor(BusinessEntityID), foreign key (UnitMeasureCode) references UnitMeasure(UnitMeasureCode) ); CREATE TABLE PurchaseOrderHeader ( PurchaseOrderID INTEGER primary key autoincrement, RevisionNumber INTEGER default 0 not null, Status INTEGER default 1 not null, EmployeeID INTEGER not null, VendorID INTEGER not null, ShipMethodID INTEGER not null, OrderDate DATETIME default CURRENT_TIMESTAMP not null, ShipDate DATETIME, SubTotal REAL default 0.0000 not null, TaxAmt REAL default 0.0000 not null, Freight REAL default 0.0000 not null, TotalDue REAL not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (EmployeeID) references Employee(BusinessEntityID), foreign key (VendorID) references Vendor(BusinessEntityID), foreign key (ShipMethodID) references ShipMethod(ShipMethodID) ); CREATE TABLE PurchaseOrderDetail ( PurchaseOrderID INTEGER not null, PurchaseOrderDetailID INTEGER primary key autoincrement, DueDate DATETIME not null, OrderQty INTEGER not null, ProductID INTEGER not null, UnitPrice REAL not null, LineTotal REAL not null, ReceivedQty REAL not null, RejectedQty REAL not null, StockedQty REAL not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (PurchaseOrderID) references PurchaseOrderHeader(PurchaseOrderID), foreign key (ProductID) references Product(ProductID) ); CREATE TABLE WorkOrder ( WorkOrderID INTEGER primary key autoincrement, ProductID INTEGER not null, OrderQty INTEGER not null, StockedQty INTEGER not null, ScrappedQty INTEGER not null, StartDate DATETIME not null, EndDate DATETIME, DueDate DATETIME not null, ScrapReasonID INTEGER, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (ProductID) references Product(ProductID), foreign key (ScrapReasonID) references ScrapReason(ScrapReasonID) ); CREATE TABLE WorkOrderRouting ( WorkOrderID INTEGER not null, ProductID INTEGER not null, OperationSequence INTEGER not null, LocationID INTEGER not null, ScheduledStartDate DATETIME not null, ScheduledEndDate DATETIME not null, ActualStartDate DATETIME, ActualEndDate DATETIME, ActualResourceHrs REAL, PlannedCost REAL not null, ActualCost REAL, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (WorkOrderID, ProductID, OperationSequence), foreign key (WorkOrderID) references WorkOrder(WorkOrderID), foreign key (LocationID) references Location(LocationID) ); CREATE TABLE Customer ( CustomerID INTEGER primary key, PersonID INTEGER, StoreID INTEGER, TerritoryID INTEGER, AccountNumber TEXT not null unique, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null, foreign key (PersonID) references Person(BusinessEntityID), foreign key (TerritoryID) references SalesTerritory(TerritoryID), foreign key (StoreID) references Store(BusinessEntityID) ); CREATE TABLE ProductListPriceHistory ( ProductID INTEGER not null, StartDate DATE not null, EndDate DATE, ListPrice REAL not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (ProductID, StartDate), foreign key (ProductID) references Product(ProductID) ); CREATE TABLE IF NOT EXISTS "Address" ( AddressID INTEGER primary key autoincrement, AddressLine1 TEXT not null, AddressLine2 TEXT, City TEXT not null, StateProvinceID INTEGER not null references StateProvince, PostalCode TEXT not null, SpatialLocation TEXT, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null, unique (AddressLine1, AddressLine2, City, StateProvinceID, PostalCode) ); CREATE TABLE IF NOT EXISTS "AddressType" ( AddressTypeID INTEGER primary key autoincrement, Name TEXT not null unique, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "BillOfMaterials" ( BillOfMaterialsID INTEGER primary key autoincrement, ProductAssemblyID INTEGER references Product, ComponentID INTEGER not null references Product, StartDate DATETIME default current_timestamp not null, EndDate DATETIME, UnitMeasureCode TEXT not null references UnitMeasure, BOMLevel INTEGER not null, PerAssemblyQty REAL default 1.00 not null, ModifiedDate DATETIME default current_timestamp not null, unique (ProductAssemblyID, ComponentID, StartDate) ); CREATE TABLE IF NOT EXISTS "BusinessEntity" ( BusinessEntityID INTEGER primary key autoincrement, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "ContactType" ( ContactTypeID INTEGER primary key autoincrement, Name TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "CurrencyRate" ( CurrencyRateID INTEGER primary key autoincrement, CurrencyRateDate DATETIME not null, FromCurrencyCode TEXT not null references Currency, ToCurrencyCode TEXT not null references Currency, AverageRate REAL not null, EndOfDayRate REAL not null, ModifiedDate DATETIME default current_timestamp not null, unique (CurrencyRateDate, FromCurrencyCode, ToCurrencyCode) ); CREATE TABLE IF NOT EXISTS "Department" ( DepartmentID INTEGER primary key autoincrement, Name TEXT not null unique, GroupName TEXT not null, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "EmployeeDepartmentHistory" ( BusinessEntityID INTEGER not null references Employee, DepartmentID INTEGER not null references Department, ShiftID INTEGER not null references Shift, StartDate DATE not null, EndDate DATE, ModifiedDate DATETIME default current_timestamp not null, primary key (BusinessEntityID, StartDate, DepartmentID, ShiftID) ); CREATE TABLE IF NOT EXISTS "EmployeePayHistory" ( BusinessEntityID INTEGER not null references Employee, RateChangeDate DATETIME not null, Rate REAL not null, PayFrequency INTEGER not null, ModifiedDate DATETIME default current_timestamp not null, primary key (BusinessEntityID, RateChangeDate) ); CREATE TABLE IF NOT EXISTS "JobCandidate" ( JobCandidateID INTEGER primary key autoincrement, BusinessEntityID INTEGER references Employee, Resume TEXT, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "Location" ( LocationID INTEGER primary key autoincrement, Name TEXT not null unique, CostRate REAL default 0.0000 not null, Availability REAL default 0.00 not null, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "PhoneNumberType" ( PhoneNumberTypeID INTEGER primary key autoincrement, Name TEXT not null, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "Product" ( ProductID INTEGER primary key autoincrement, Name TEXT not null unique, ProductNumber TEXT not null unique, MakeFlag INTEGER default 1 not null, FinishedGoodsFlag INTEGER default 1 not null, Color TEXT, SafetyStockLevel INTEGER not null, ReorderPoint INTEGER not null, StandardCost REAL not null, ListPrice REAL not null, Size TEXT, SizeUnitMeasureCode TEXT references UnitMeasure, WeightUnitMeasureCode TEXT references UnitMeasure, Weight REAL, DaysToManufacture INTEGER not null, ProductLine TEXT, Class TEXT, Style TEXT, ProductSubcategoryID INTEGER references ProductSubcategory, ProductModelID INTEGER references ProductModel, SellStartDate DATETIME not null, SellEndDate DATETIME, DiscontinuedDate DATETIME, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "Document" ( DocumentNode TEXT not null primary key, DocumentLevel INTEGER, Title TEXT not null, Owner INTEGER not null references Employee, FolderFlag INTEGER default 0 not null, FileName TEXT not null, FileExtension TEXT not null, Revision TEXT not null, ChangeNumber INTEGER default 0 not null, Status INTEGER not null, DocumentSummary TEXT, Document BLOB, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null, unique (DocumentLevel, DocumentNode) ); CREATE TABLE IF NOT EXISTS "StateProvince" ( StateProvinceID INTEGER primary key autoincrement, StateProvinceCode TEXT not null, CountryRegionCode TEXT not null references CountryRegion, IsOnlyStateProvinceFlag INTEGER default 1 not null, Name TEXT not null unique, TerritoryID INTEGER not null references SalesTerritory, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, unique (StateProvinceCode, CountryRegionCode) ); CREATE TABLE IF NOT EXISTS "CreditCard" ( CreditCardID INTEGER primary key autoincrement, CardType TEXT not null, CardNumber TEXT not null unique, ExpMonth INTEGER not null, ExpYear INTEGER not null, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "SalesOrderHeader" ( SalesOrderID INTEGER primary key autoincrement, RevisionNumber INTEGER default 0 not null, OrderDate DATETIME default CURRENT_TIMESTAMP not null, DueDate DATETIME not null, ShipDate DATETIME, Status INTEGER default 1 not null, OnlineOrderFlag INTEGER default 1 not null, SalesOrderNumber TEXT not null unique, PurchaseOrderNumber TEXT, AccountNumber TEXT, CustomerID INTEGER not null references Customer, SalesPersonID INTEGER references SalesPerson, TerritoryID INTEGER references SalesTerritory, BillToAddressID INTEGER not null references Address, ShipToAddressID INTEGER not null references Address, ShipMethodID INTEGER not null references Address, CreditCardID INTEGER references CreditCard, CreditCardApprovalCode TEXT, CurrencyRateID INTEGER references CurrencyRate, SubTotal REAL default 0.0000 not null, TaxAmt REAL default 0.0000 not null, Freight REAL default 0.0000 not null, TotalDue REAL not null, Comment TEXT, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null );
european_football_1
In how many matches in the Seria A division did both teams have equal goals?
Seria A is a name of division; equal goals refers to FTR = 'D', where D stands for draft;
SELECT COUNT(T1.FTR) FROM matchs AS T1 INNER JOIN divisions AS T2 ON T1.Div = T2.division WHERE T2.name = 'Seria A' AND T1.FTR = 'D'
CREATE TABLE divisions ( division TEXT not null primary key, name TEXT, country TEXT ); CREATE TABLE matchs ( Div TEXT, Date DATE, HomeTeam TEXT, AwayTeam TEXT, FTHG INTEGER, FTAG INTEGER, FTR TEXT, season INTEGER, foreign key (Div) references divisions(division) );
social_media
Tweets that were posted from Brazil are in what languague?
"Brazil" is the Country; language refers to Lang
SELECT DISTINCT T1.Lang FROM twitter AS T1 INNER JOIN location AS T2 ON T1.LocationID = T2.LocationID WHERE T2.Country = 'Brazil'
CREATE TABLE location ( LocationID INTEGER constraint location_pk primary key, Country TEXT, State TEXT, StateCode TEXT, City TEXT ); CREATE TABLE user ( UserID TEXT constraint user_pk primary key, Gender TEXT ); CREATE TABLE twitter ( TweetID TEXT primary key, Weekday TEXT, Hour INTEGER, Day INTEGER, Lang TEXT, IsReshare TEXT, Reach INTEGER, RetweetCount INTEGER, Likes INTEGER, Klout INTEGER, Sentiment REAL, "text" TEXT, LocationID INTEGER, UserID TEXT, foreign key (LocationID) references location(LocationID), foreign key (UserID) references user(UserID) );
bike_share_1
Find the longest ride on foggy day. What were the mean visibility, mean wind speed, and weather event during that ride? Also, list the coordinates and names of the start and end stations.
foggy day refers to events = 'fog'; longest ride on a foggy day refers to MAX(duration) where events = 'fog'; mean visibility refers to mean_visibility_miles; mean wind speed refers to mean_wind_speed_mph; weather event refers to events; coordinates refers to (lat, long); start station refers to start_station_id; end station refers to end_station_id;
SELECT T3.mean_visibility_miles, T3.mean_wind_speed_mph, T3.events, T1.lat, T1.long , T2.start_station_name, T2.end_station_name FROM station AS T1 INNER JOIN trip AS T2 ON T2.start_station_name = T1.name INNER JOIN weather AS T3 ON T3.zip_code = T2.zip_code WHERE T3.events = 'Fog' ORDER BY T2.duration DESC LIMIT 1
CREATE TABLE IF NOT EXISTS "station" ( id INTEGER not null primary key, name TEXT, lat REAL, long REAL, dock_count INTEGER, city TEXT, installation_date TEXT ); CREATE TABLE IF NOT EXISTS "status" ( station_id INTEGER, bikes_available INTEGER, docks_available INTEGER, time TEXT ); CREATE TABLE IF NOT EXISTS "trip" ( id INTEGER not null primary key, duration INTEGER, start_date TEXT, start_station_name TEXT, start_station_id INTEGER, end_date TEXT, end_station_name TEXT, end_station_id INTEGER, bike_id INTEGER, subscription_type TEXT, zip_code INTEGER ); CREATE TABLE IF NOT EXISTS "weather" ( date TEXT, max_temperature_f INTEGER, mean_temperature_f INTEGER, min_temperature_f INTEGER, max_dew_point_f INTEGER, mean_dew_point_f INTEGER, min_dew_point_f INTEGER, max_humidity INTEGER, mean_humidity INTEGER, min_humidity INTEGER, max_sea_level_pressure_inches REAL, mean_sea_level_pressure_inches REAL, min_sea_level_pressure_inches REAL, max_visibility_miles INTEGER, mean_visibility_miles INTEGER, min_visibility_miles INTEGER, max_wind_Speed_mph INTEGER, mean_wind_speed_mph INTEGER, max_gust_speed_mph INTEGER, precipitation_inches TEXT, cloud_cover INTEGER, events TEXT, wind_dir_degrees INTEGER, zip_code TEXT );
beer_factory
What credit card is the most used in the purchase of non-alcoholic beer?
credit card that is the most used refers to MAX(COUNT(CreditCardType)); non-alcoholic beer refers to Alcoholic = 'FALSE';
SELECT T2.CreditCardType FROM rootbeer AS T1 INNER JOIN `transaction` AS T2 ON T1.RootBeerID = T2.RootBeerID INNER JOIN rootbeerbrand AS T3 ON T1.BrandID = T3.BrandID WHERE T3.Alcoholic = 'FALSE' GROUP BY T2.CreditCardType ORDER BY COUNT(T2.CreditCardType) DESC LIMIT 1
CREATE TABLE customers ( CustomerID INTEGER primary key, First TEXT, Last TEXT, StreetAddress TEXT, City TEXT, State TEXT, ZipCode INTEGER, Email TEXT, PhoneNumber TEXT, FirstPurchaseDate DATE, SubscribedToEmailList TEXT, Gender TEXT ); CREATE TABLE geolocation ( LocationID INTEGER primary key, Latitude REAL, Longitude REAL, foreign key (LocationID) references location(LocationID) ); CREATE TABLE location ( LocationID INTEGER primary key, LocationName TEXT, StreetAddress TEXT, City TEXT, State TEXT, ZipCode INTEGER, foreign key (LocationID) references geolocation(LocationID) ); CREATE TABLE rootbeerbrand ( BrandID INTEGER primary key, BrandName TEXT, FirstBrewedYear INTEGER, BreweryName TEXT, City TEXT, State TEXT, Country TEXT, Description TEXT, CaneSugar TEXT, CornSyrup TEXT, Honey TEXT, ArtificialSweetener TEXT, Caffeinated TEXT, Alcoholic TEXT, AvailableInCans TEXT, AvailableInBottles TEXT, AvailableInKegs TEXT, Website TEXT, FacebookPage TEXT, Twitter TEXT, WholesaleCost REAL, CurrentRetailPrice REAL ); CREATE TABLE rootbeer ( RootBeerID INTEGER primary key, BrandID INTEGER, ContainerType TEXT, LocationID INTEGER, PurchaseDate DATE, foreign key (LocationID) references geolocation(LocationID), foreign key (LocationID) references location(LocationID), foreign key (BrandID) references rootbeerbrand(BrandID) ); CREATE TABLE rootbeerreview ( CustomerID INTEGER, BrandID INTEGER, StarRating INTEGER, ReviewDate DATE, Review TEXT, primary key (CustomerID, BrandID), foreign key (CustomerID) references customers(CustomerID), foreign key (BrandID) references rootbeerbrand(BrandID) ); CREATE TABLE IF NOT EXISTS "transaction" ( TransactionID INTEGER primary key, CreditCardNumber INTEGER, CustomerID INTEGER, TransactionDate DATE, CreditCardType TEXT, LocationID INTEGER, RootBeerID INTEGER, PurchasePrice REAL, foreign key (CustomerID) references customers(CustomerID), foreign key (LocationID) references location(LocationID), foreign key (RootBeerID) references rootbeer(RootBeerID) );
food_inspection_2
What is the full name of the employee who gave the highest amount of fine of all time?
full name refers to first_name, last_name; the highest amount of fine refers to max(sum(fine))
SELECT T.first_name, T.last_name FROM ( SELECT T1.first_name, T1.last_name, SUM(T3.fine) FROM employee AS T1 INNER JOIN inspection AS T2 ON T1.employee_id = T2.employee_id INNER JOIN violation AS T3 ON T2.inspection_id = T3.inspection_id GROUP BY T1.first_name, T1.last_name ORDER BY SUM(T3.fine) DESC LIMIT 1 ) t
CREATE TABLE employee ( employee_id INTEGER primary key, first_name TEXT, last_name TEXT, address TEXT, city TEXT, state TEXT, zip INTEGER, phone TEXT, title TEXT, salary INTEGER, supervisor INTEGER, foreign key (supervisor) references employee(employee_id) ); CREATE TABLE establishment ( license_no INTEGER primary key, dba_name TEXT, aka_name TEXT, facility_type TEXT, risk_level INTEGER, address TEXT, city TEXT, state TEXT, zip INTEGER, latitude REAL, longitude REAL, ward INTEGER ); CREATE TABLE inspection ( inspection_id INTEGER primary key, inspection_date DATE, inspection_type TEXT, results TEXT, employee_id INTEGER, license_no INTEGER, followup_to INTEGER, foreign key (employee_id) references employee(employee_id), foreign key (license_no) references establishment(license_no), foreign key (followup_to) references inspection(inspection_id) ); CREATE TABLE inspection_point ( point_id INTEGER primary key, Description TEXT, category TEXT, code TEXT, fine INTEGER, point_level TEXT ); CREATE TABLE violation ( inspection_id INTEGER, point_id INTEGER, fine INTEGER, inspector_comment TEXT, primary key (inspection_id, point_id), foreign key (inspection_id) references inspection(inspection_id), foreign key (point_id) references inspection_point(point_id) );
retails
Among the customers in Asia, how many customers are in debt?
customers in Asia refer to n_name where r_name = 'ASIA'; customers in debt refer to c_acctbal < 0;
SELECT COUNT(T1.n_name) FROM nation AS T1 INNER JOIN customer AS T2 ON T1.n_nationkey = T2.c_nationkey INNER JOIN region AS T3 ON T1.n_regionkey = T3.r_regionkey WHERE T2.c_acctbal < 0 AND T3.r_name = 'ASIA'
CREATE TABLE `customer` ( `c_custkey` INTEGER NOT NULL, `c_mktsegment` TEXT DEFAULT NULL, `c_nationkey` INTEGER DEFAULT NULL, `c_name` TEXT DEFAULT NULL, `c_address` TEXT DEFAULT NULL, `c_phone` TEXT DEFAULT NULL, `c_acctbal` REAL DEFAULT NULL, `c_comment` TEXT DEFAULT NULL, PRIMARY KEY (`c_custkey`), FOREIGN KEY (`c_nationkey`) REFERENCES `nation` (`n_nationkey`) ON DELETE CASCADE ON UPDATE CASCADE ); CREATE TABLE lineitem ( l_shipdate DATE null, l_orderkey INTEGER not null, l_discount REAL not null, l_extendedprice REAL not null, l_suppkey INTEGER not null, l_quantity INTEGER not null, l_returnflag TEXT null, l_partkey INTEGER not null, l_linestatus TEXT null, l_tax REAL not null, l_commitdate DATE null, l_receiptdate DATE null, l_shipmode TEXT null, l_linenumber INTEGER not null, l_shipinstruct TEXT null, l_comment TEXT null, primary key (l_orderkey, l_linenumber), foreign key (l_orderkey) references orders (o_orderkey) on update cascade on delete cascade, foreign key (l_partkey, l_suppkey) references partsupp (ps_partkey, ps_suppkey) on update cascade on delete cascade ); CREATE TABLE nation ( n_nationkey INTEGER not null primary key, n_name TEXT null, n_regionkey INTEGER null, n_comment TEXT null, foreign key (n_regionkey) references region (r_regionkey) on update cascade on delete cascade ); CREATE TABLE orders ( o_orderdate DATE null, o_orderkey INTEGER not null primary key, o_custkey INTEGER not null, o_orderpriority TEXT null, o_shippriority INTEGER null, o_clerk TEXT null, o_orderstatus TEXT null, o_totalprice REAL null, o_comment TEXT null, foreign key (o_custkey) references customer (c_custkey) on update cascade on delete cascade ); CREATE TABLE part ( p_partkey INTEGER not null primary key, p_type TEXT null, p_size INTEGER null, p_brand TEXT null, p_name TEXT null, p_container TEXT null, p_mfgr TEXT null, p_retailprice REAL null, p_comment TEXT null ); CREATE TABLE partsupp ( ps_partkey INTEGER not null, ps_suppkey INTEGER not null, ps_supplycost REAL not null, ps_availqty INTEGER null, ps_comment TEXT null, primary key (ps_partkey, ps_suppkey), foreign key (ps_partkey) references part (p_partkey) on update cascade on delete cascade, foreign key (ps_suppkey) references supplier (s_suppkey) on update cascade on delete cascade ); CREATE TABLE region ( r_regionkey INTEGER not null primary key, r_name TEXT null, r_comment TEXT null ); CREATE TABLE supplier ( s_suppkey INTEGER not null primary key, s_nationkey INTEGER null, s_comment TEXT null, s_name TEXT null, s_address TEXT null, s_phone TEXT null, s_acctbal REAL null, foreign key (s_nationkey) references nation (n_nationkey) );
talkingdata
What are the categories that app user ID7324884708820020000 belongs to?
app user ID refers to app_id; app_id = 7324884708820020000;
SELECT T1.category FROM label_categories AS T1 INNER JOIN app_labels AS T2 ON T1.label_id = T2.label_id WHERE T2.app_id = 7324884708820020000
CREATE TABLE `app_all` ( `app_id` INTEGER NOT NULL, PRIMARY KEY (`app_id`) ); CREATE TABLE `app_events` ( `event_id` INTEGER NOT NULL, `app_id` INTEGER NOT NULL, `is_installed` INTEGER NOT NULL, `is_active` INTEGER NOT NULL, PRIMARY KEY (`event_id`,`app_id`), FOREIGN KEY (`event_id`) REFERENCES `events` (`event_id`) ON DELETE CASCADE ON UPDATE CASCADE ); CREATE TABLE `app_events_relevant` ( `event_id` INTEGER NOT NULL, `app_id` INTEGER NOT NULL, `is_installed` INTEGER DEFAULT NULL, `is_active` INTEGER DEFAULT NULL, PRIMARY KEY (`event_id`,`app_id`), FOREIGN KEY (`event_id`) REFERENCES `events_relevant` (`event_id`) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (`app_id`) REFERENCES `app_all` (`app_id`) ON DELETE CASCADE ON UPDATE CASCADE ); CREATE TABLE `app_labels` ( `app_id` INTEGER NOT NULL, `label_id` INTEGER NOT NULL, FOREIGN KEY (`label_id`) REFERENCES `label_categories` (`label_id`) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (`app_id`) REFERENCES `app_all` (`app_id`) ON DELETE CASCADE ON UPDATE CASCADE ); CREATE TABLE `events` ( `event_id` INTEGER NOT NULL, `device_id` INTEGER DEFAULT NULL, `timestamp` DATETIME DEFAULT NULL, `longitude` REAL DEFAULT NULL, `latitude` REAL DEFAULT NULL, PRIMARY KEY (`event_id`) ); CREATE TABLE `events_relevant` ( `event_id` INTEGER NOT NULL, `device_id` INTEGER DEFAULT NULL, `timestamp` DATETIME NOT NULL, `longitude` REAL NOT NULL, `latitude` REAL NOT NULL, PRIMARY KEY (`event_id`), FOREIGN KEY (`device_id`) REFERENCES `gender_age` (`device_id`) ON DELETE CASCADE ON UPDATE CASCADE ); CREATE TABLE `gender_age` ( `device_id` INTEGER NOT NULL, `gender` TEXT DEFAULT NULL, `age` INTEGER DEFAULT NULL, `group` TEXT DEFAULT NULL, PRIMARY KEY (`device_id`), FOREIGN KEY (`device_id`) REFERENCES `phone_brand_device_model2` (`device_id`) ON DELETE CASCADE ON UPDATE CASCADE ); CREATE TABLE `gender_age_test` ( `device_id` INTEGER NOT NULL, PRIMARY KEY (`device_id`) ); CREATE TABLE `gender_age_train` ( `device_id` INTEGER NOT NULL, `gender` TEXT DEFAULT NULL, `age` INTEGER DEFAULT NULL, `group` TEXT DEFAULT NULL, PRIMARY KEY (`device_id`) ); CREATE TABLE `label_categories` ( `label_id` INTEGER NOT NULL, `category` TEXT DEFAULT NULL, PRIMARY KEY (`label_id`) ); CREATE TABLE `phone_brand_device_model2` ( `device_id` INTEGER NOT NULL, `phone_brand` TEXT NOT NULL, `device_model` TEXT NOT NULL, PRIMARY KEY (`device_id`,`phone_brand`,`device_model`) ); CREATE TABLE `sample_submission` ( `device_id` INTEGER NOT NULL, `F23-` REAL DEFAULT NULL, `F24-26` REAL DEFAULT NULL, `F27-28` REAL DEFAULT NULL, `F29-32` REAL DEFAULT NULL, `F33-42` REAL DEFAULT NULL, `F43+` REAL DEFAULT NULL, `M22-` REAL DEFAULT NULL, `M23-26` REAL DEFAULT NULL, `M27-28` REAL DEFAULT NULL, `M29-31` REAL DEFAULT NULL, `M32-38` REAL DEFAULT NULL, `M39+` REAL DEFAULT NULL, PRIMARY KEY (`device_id`) );
sales
In customers with the first name of Erica, how many of them bought a quantity below 200?
quantity below 200 refers to quantity < 200;
SELECT COUNT(T1.ProductID) FROM Sales AS T1 INNER JOIN Customers AS T2 ON T1.CustomerID = T2.CustomerID WHERE T2.FirstName = 'Erica' AND T1.Quantity < 200
CREATE TABLE Customers ( CustomerID INTEGER not null primary key, FirstName TEXT not null, MiddleInitial TEXT null, LastName TEXT not null ); CREATE TABLE Employees ( EmployeeID INTEGER not null primary key, FirstName TEXT not null, MiddleInitial TEXT null, LastName TEXT not null ); CREATE TABLE Products ( ProductID INTEGER not null primary key, Name TEXT not null, Price REAL null ); CREATE TABLE Sales ( SalesID INTEGER not null primary key, SalesPersonID INTEGER not null, CustomerID INTEGER not null, ProductID INTEGER not null, Quantity INTEGER not null, foreign key (SalesPersonID) references Employees (EmployeeID) on update cascade on delete cascade, foreign key (CustomerID) references Customers (CustomerID) on update cascade on delete cascade, foreign key (ProductID) references Products (ProductID) on update cascade on delete cascade );
image_and_language
What is the relationship between object sample no.12 and no.8 of image no.2345511?
relationship refers to PRED_CLASS; object sample no.12 and no.8 of image no.2345511 refers to IMG_ID = 2345511 AND OBJ1_SAMPLE_ID = 12 AND OBJ2_SAMPLE_ID = 8
SELECT T1.PRED_CLASS FROM PRED_CLASSES AS T1 INNER JOIN IMG_REL AS T2 ON T1.PRED_CLASS_ID = T2.PRED_CLASS_ID WHERE T2.IMG_ID = 2345511 AND T2.OBJ1_SAMPLE_ID = 12 AND T2.OBJ2_SAMPLE_ID = 8
CREATE TABLE ATT_CLASSES ( ATT_CLASS_ID INTEGER default 0 not null primary key, ATT_CLASS TEXT not null ); CREATE TABLE OBJ_CLASSES ( OBJ_CLASS_ID INTEGER default 0 not null primary key, OBJ_CLASS TEXT not null ); CREATE TABLE IMG_OBJ ( IMG_ID INTEGER default 0 not null, OBJ_SAMPLE_ID INTEGER default 0 not null, OBJ_CLASS_ID INTEGER null, X INTEGER null, Y INTEGER null, W INTEGER null, H INTEGER null, primary key (IMG_ID, OBJ_SAMPLE_ID), foreign key (OBJ_CLASS_ID) references OBJ_CLASSES (OBJ_CLASS_ID) ); CREATE TABLE IMG_OBJ_ATT ( IMG_ID INTEGER default 0 not null, ATT_CLASS_ID INTEGER default 0 not null, OBJ_SAMPLE_ID INTEGER default 0 not null, primary key (IMG_ID, ATT_CLASS_ID, OBJ_SAMPLE_ID), foreign key (ATT_CLASS_ID) references ATT_CLASSES (ATT_CLASS_ID), foreign key (IMG_ID, OBJ_SAMPLE_ID) references IMG_OBJ (IMG_ID, OBJ_SAMPLE_ID) ); CREATE TABLE PRED_CLASSES ( PRED_CLASS_ID INTEGER default 0 not null primary key, PRED_CLASS TEXT not null ); CREATE TABLE IMG_REL ( IMG_ID INTEGER default 0 not null, PRED_CLASS_ID INTEGER default 0 not null, OBJ1_SAMPLE_ID INTEGER default 0 not null, OBJ2_SAMPLE_ID INTEGER default 0 not null, primary key (IMG_ID, PRED_CLASS_ID, OBJ1_SAMPLE_ID, OBJ2_SAMPLE_ID), foreign key (PRED_CLASS_ID) references PRED_CLASSES (PRED_CLASS_ID), foreign key (IMG_ID, OBJ1_SAMPLE_ID) references IMG_OBJ (IMG_ID, OBJ_SAMPLE_ID), foreign key (IMG_ID, OBJ2_SAMPLE_ID) references IMG_OBJ (IMG_ID, OBJ_SAMPLE_ID) );
app_store
List down the rating for the App Learn C++.
FALSE;
SELECT DISTINCT Rating FROM playstore WHERE App = 'Learn C++'
CREATE TABLE IF NOT EXISTS "playstore" ( App TEXT, Category TEXT, Rating REAL, Reviews INTEGER, Size TEXT, Installs TEXT, Type TEXT, Price TEXT, "Content Rating" TEXT, Genres TEXT ); CREATE TABLE IF NOT EXISTS "user_reviews" ( App TEXT references "playstore" (App), Translated_Review TEXT, Sentiment TEXT, Sentiment_Polarity TEXT, Sentiment_Subjectivity TEXT );
chicago_crime
What is the general description for case number JB106010?
general description refers to primary_description
SELECT T1.primary_description FROM IUCR AS T1 INNER JOIN Crime AS T2 ON T1.iucr_no = T2.iucr_no WHERE T2.case_number = 'JB106010'
CREATE TABLE Community_Area ( community_area_no INTEGER primary key, community_area_name TEXT, side TEXT, population TEXT ); CREATE TABLE District ( district_no INTEGER primary key, district_name TEXT, address TEXT, zip_code INTEGER, commander TEXT, email TEXT, phone TEXT, fax TEXT, tty TEXT, twitter TEXT ); CREATE TABLE FBI_Code ( fbi_code_no TEXT primary key, title TEXT, description TEXT, crime_against TEXT ); CREATE TABLE IUCR ( iucr_no TEXT primary key, primary_description TEXT, secondary_description TEXT, index_code TEXT ); CREATE TABLE Neighborhood ( neighborhood_name TEXT primary key, community_area_no INTEGER, foreign key (community_area_no) references Community_Area(community_area_no) ); CREATE TABLE Ward ( ward_no INTEGER primary key, alderman_first_name TEXT, alderman_last_name TEXT, alderman_name_suffix TEXT, ward_office_address TEXT, ward_office_zip TEXT, ward_email TEXT, ward_office_phone TEXT, ward_office_fax TEXT, city_hall_office_room INTEGER, city_hall_office_phone TEXT, city_hall_office_fax TEXT, Population INTEGER ); CREATE TABLE Crime ( report_no INTEGER primary key, case_number TEXT, date TEXT, block TEXT, iucr_no TEXT, location_description TEXT, arrest TEXT, domestic TEXT, beat INTEGER, district_no INTEGER, ward_no INTEGER, community_area_no INTEGER, fbi_code_no TEXT, latitude TEXT, longitude TEXT, foreign key (ward_no) references Ward(ward_no), foreign key (iucr_no) references IUCR(iucr_no), foreign key (district_no) references District(district_no), foreign key (community_area_no) references Community_Area(community_area_no), foreign key (fbi_code_no) references FBI_Code(fbi_code_no) );
image_and_language
Please list the IDs of all the images with more than 2 pairs of object samples with the relation "parked on".
IDs of all the images refers to IMG_ID; relation "parked on" refers to PRED_CLASS = 'parked on'; more than 2 pairs refers to count(IMG_ID) where OBJ1_SAMPLE_ID ! = OBJ2_SAMPLE_ID
SELECT T2.IMG_ID FROM PRED_CLASSES AS T1 INNER JOIN IMG_REL AS T2 ON T1.PRED_CLASS_ID = T2.PRED_CLASS_ID WHERE T1.PRED_CLASS = 'parked on' AND T2.OBJ1_SAMPLE_ID != T2.OBJ2_SAMPLE_ID GROUP BY T2.IMG_ID HAVING COUNT(T2.IMG_ID) > 2
CREATE TABLE ATT_CLASSES ( ATT_CLASS_ID INTEGER default 0 not null primary key, ATT_CLASS TEXT not null ); CREATE TABLE OBJ_CLASSES ( OBJ_CLASS_ID INTEGER default 0 not null primary key, OBJ_CLASS TEXT not null ); CREATE TABLE IMG_OBJ ( IMG_ID INTEGER default 0 not null, OBJ_SAMPLE_ID INTEGER default 0 not null, OBJ_CLASS_ID INTEGER null, X INTEGER null, Y INTEGER null, W INTEGER null, H INTEGER null, primary key (IMG_ID, OBJ_SAMPLE_ID), foreign key (OBJ_CLASS_ID) references OBJ_CLASSES (OBJ_CLASS_ID) ); CREATE TABLE IMG_OBJ_ATT ( IMG_ID INTEGER default 0 not null, ATT_CLASS_ID INTEGER default 0 not null, OBJ_SAMPLE_ID INTEGER default 0 not null, primary key (IMG_ID, ATT_CLASS_ID, OBJ_SAMPLE_ID), foreign key (ATT_CLASS_ID) references ATT_CLASSES (ATT_CLASS_ID), foreign key (IMG_ID, OBJ_SAMPLE_ID) references IMG_OBJ (IMG_ID, OBJ_SAMPLE_ID) ); CREATE TABLE PRED_CLASSES ( PRED_CLASS_ID INTEGER default 0 not null primary key, PRED_CLASS TEXT not null ); CREATE TABLE IMG_REL ( IMG_ID INTEGER default 0 not null, PRED_CLASS_ID INTEGER default 0 not null, OBJ1_SAMPLE_ID INTEGER default 0 not null, OBJ2_SAMPLE_ID INTEGER default 0 not null, primary key (IMG_ID, PRED_CLASS_ID, OBJ1_SAMPLE_ID, OBJ2_SAMPLE_ID), foreign key (PRED_CLASS_ID) references PRED_CLASSES (PRED_CLASS_ID), foreign key (IMG_ID, OBJ1_SAMPLE_ID) references IMG_OBJ (IMG_ID, OBJ_SAMPLE_ID), foreign key (IMG_ID, OBJ2_SAMPLE_ID) references IMG_OBJ (IMG_ID, OBJ_SAMPLE_ID) );
donor
Which school requested the highest amount of resources from Amazon? State the school's ID.
highest amount of resources refers to max(count(schoolid)); Amazon refers to vendor_name = 'Amazon'
SELECT T2.schoolid FROM resources AS T1 INNER JOIN projects AS T2 ON T1.projectid = T2.projectid WHERE T1.vendor_name LIKE 'Amazon' GROUP BY T2.schoolid ORDER BY COUNT(T1.vendor_name) DESC LIMIT 1
CREATE TABLE sqlite_sequence(name,seq); CREATE TABLE IF NOT EXISTS "essays" ( projectid TEXT, teacher_acctid TEXT, title TEXT, short_description TEXT, need_statement TEXT, essay TEXT ); CREATE TABLE IF NOT EXISTS "projects" ( projectid TEXT not null primary key, teacher_acctid TEXT, schoolid TEXT, school_ncesid TEXT, school_latitude REAL, school_longitude REAL, school_city TEXT, school_state TEXT, school_zip INTEGER, school_metro TEXT, school_district TEXT, school_county TEXT, school_charter TEXT, school_magnet TEXT, school_year_round TEXT, school_nlns TEXT, school_kipp TEXT, school_charter_ready_promise TEXT, teacher_prefix TEXT, teacher_teach_for_america TEXT, teacher_ny_teaching_fellow TEXT, primary_focus_subject TEXT, primary_focus_area TEXT, secondary_focus_subject TEXT, secondary_focus_area TEXT, resource_type TEXT, poverty_level TEXT, grade_level TEXT, fulfillment_labor_materials REAL, total_price_excluding_optional_support REAL, total_price_including_optional_support REAL, students_reached INTEGER, eligible_double_your_impact_match TEXT, eligible_almost_home_match TEXT, date_posted DATE ); CREATE TABLE donations ( donationid TEXT not null primary key, projectid TEXT, donor_acctid TEXT, donor_city TEXT, donor_state TEXT, donor_zip TEXT, is_teacher_acct TEXT, donation_timestamp DATETIME, donation_to_project REAL, donation_optional_support REAL, donation_total REAL, dollar_amount TEXT, donation_included_optional_support TEXT, payment_method TEXT, payment_included_acct_credit TEXT, payment_included_campaign_gift_card TEXT, payment_included_web_purchased_gift_card TEXT, payment_was_promo_matched TEXT, via_giving_page TEXT, for_honoree TEXT, donation_message TEXT, foreign key (projectid) references projects(projectid) ); CREATE TABLE resources ( resourceid TEXT not null primary key, projectid TEXT, vendorid INTEGER, vendor_name TEXT, project_resource_type TEXT, item_name TEXT, item_number TEXT, item_unit_price REAL, item_quantity INTEGER, foreign key (projectid) references projects(projectid) );
public_review_platform
Give the number of "4" stars Yelp businesses in "Mesa" city.
"4" stars refers to stars = '4'; 'Mesa' is the name of city
SELECT COUNT(business_id) FROM Business WHERE stars = 4 AND city = 'Mesa'
CREATE TABLE Attributes ( attribute_id INTEGER constraint Attributes_pk primary key, attribute_name TEXT ); CREATE TABLE Categories ( category_id INTEGER constraint Categories_pk primary key, category_name TEXT ); CREATE TABLE Compliments ( compliment_id INTEGER constraint Compliments_pk primary key, compliment_type TEXT ); CREATE TABLE Days ( day_id INTEGER constraint Days_pk primary key, day_of_week TEXT ); CREATE TABLE Years ( year_id INTEGER constraint Years_pk primary key, actual_year INTEGER ); CREATE TABLE IF NOT EXISTS "Business_Attributes" ( attribute_id INTEGER constraint Business_Attributes_Attributes_attribute_id_fk references Attributes, business_id INTEGER constraint Business_Attributes_Business_business_id_fk references Business, attribute_value TEXT, constraint Business_Attributes_pk primary key (attribute_id, business_id) ); CREATE TABLE IF NOT EXISTS "Business_Categories" ( business_id INTEGER constraint Business_Categories_Business_business_id_fk references Business, category_id INTEGER constraint Business_Categories_Categories_category_id_fk references Categories, constraint Business_Categories_pk primary key (business_id, category_id) ); CREATE TABLE IF NOT EXISTS "Business_Hours" ( business_id INTEGER constraint Business_Hours_Business_business_id_fk references Business, day_id INTEGER constraint Business_Hours_Days_day_id_fk references Days, opening_time TEXT, closing_time TEXT, constraint Business_Hours_pk primary key (business_id, day_id) ); CREATE TABLE IF NOT EXISTS "Checkins" ( business_id INTEGER constraint Checkins_Business_business_id_fk references Business, day_id INTEGER constraint Checkins_Days_day_id_fk references Days, label_time_0 TEXT, label_time_1 TEXT, label_time_2 TEXT, label_time_3 TEXT, label_time_4 TEXT, label_time_5 TEXT, label_time_6 TEXT, label_time_7 TEXT, label_time_8 TEXT, label_time_9 TEXT, label_time_10 TEXT, label_time_11 TEXT, label_time_12 TEXT, label_time_13 TEXT, label_time_14 TEXT, label_time_15 TEXT, label_time_16 TEXT, label_time_17 TEXT, label_time_18 TEXT, label_time_19 TEXT, label_time_20 TEXT, label_time_21 TEXT, label_time_22 TEXT, label_time_23 TEXT, constraint Checkins_pk primary key (business_id, day_id) ); CREATE TABLE IF NOT EXISTS "Elite" ( user_id INTEGER constraint Elite_Users_user_id_fk references Users, year_id INTEGER constraint Elite_Years_year_id_fk references Years, constraint Elite_pk primary key (user_id, year_id) ); CREATE TABLE IF NOT EXISTS "Reviews" ( business_id INTEGER constraint Reviews_Business_business_id_fk references Business, user_id INTEGER constraint Reviews_Users_user_id_fk references Users, review_stars INTEGER, review_votes_funny TEXT, review_votes_useful TEXT, review_votes_cool TEXT, review_length TEXT, constraint Reviews_pk primary key (business_id, user_id) ); CREATE TABLE IF NOT EXISTS "Tips" ( business_id INTEGER constraint Tips_Business_business_id_fk references Business, user_id INTEGER constraint Tips_Users_user_id_fk references Users, likes INTEGER, tip_length TEXT, constraint Tips_pk primary key (business_id, user_id) ); CREATE TABLE IF NOT EXISTS "Users_Compliments" ( compliment_id INTEGER constraint Users_Compliments_Compliments_compliment_id_fk references Compliments, user_id INTEGER constraint Users_Compliments_Users_user_id_fk references Users, number_of_compliments TEXT, constraint Users_Compliments_pk primary key (compliment_id, user_id) ); CREATE TABLE IF NOT EXISTS "Business" ( business_id INTEGER constraint Business_pk primary key, active TEXT, city TEXT, state TEXT, stars REAL, review_count TEXT ); CREATE TABLE IF NOT EXISTS "Users" ( user_id INTEGER constraint Users_pk primary key, user_yelping_since_year INTEGER, user_average_stars TEXT, user_votes_funny TEXT, user_votes_useful TEXT, user_votes_cool TEXT, user_review_count TEXT, user_fans TEXT );
mental_health_survey
How many different answers did the question "Describe the conversation you had with your previous employer about your mental health, including their reactions and actions taken to address your mental health issue/questions." get?
SELECT COUNT(DISTINCT T1.AnswerText) FROM Answer AS T1 INNER JOIN Question AS T2 ON T1.QuestionID = T2.questionid WHERE T2.questiontext LIKE 'Describe the conversation you had with your previous employer about your mental health, including their reactions and actions taken to address your mental health issue/questions.'
CREATE TABLE Question ( questiontext TEXT, questionid INTEGER constraint Question_pk primary key ); CREATE TABLE Survey ( SurveyID INTEGER constraint Survey_pk primary key, Description TEXT ); CREATE TABLE IF NOT EXISTS "Answer" ( AnswerText TEXT, SurveyID INTEGER constraint Answer_Survey_SurveyID_fk references Survey, UserID INTEGER, QuestionID INTEGER constraint Answer_Question_questionid_fk references Question, constraint Answer_pk primary key (UserID, QuestionID) );
authors
Tell the number of papers that were presented at "International Symposium on Software Testing and Analysis" conference.
'International Symposium on Software Testing and Analysis' is the FullName of the conference; papers refers to Paper.Id
SELECT COUNT(T1.Id) FROM Paper AS T1 INNER JOIN Conference AS T2 ON T1.ConferenceId = T2.Id WHERE T2.FullName = 'International Symposium on Software Testing and Analysis'
CREATE TABLE IF NOT EXISTS "Author" ( Id INTEGER constraint Author_pk primary key, Name TEXT, Affiliation TEXT ); CREATE TABLE IF NOT EXISTS "Conference" ( Id INTEGER constraint Conference_pk primary key, ShortName TEXT, FullName TEXT, HomePage TEXT ); CREATE TABLE IF NOT EXISTS "Journal" ( Id INTEGER constraint Journal_pk primary key, ShortName TEXT, FullName TEXT, HomePage TEXT ); CREATE TABLE Paper ( Id INTEGER primary key, Title TEXT, Year INTEGER, ConferenceId INTEGER, JournalId INTEGER, Keyword TEXT, foreign key (ConferenceId) references Conference(Id), foreign key (JournalId) references Journal(Id) ); CREATE TABLE PaperAuthor ( PaperId INTEGER, AuthorId INTEGER, Name TEXT, Affiliation TEXT, foreign key (PaperId) references Paper(Id), foreign key (AuthorId) references Author(Id) );
shakespeare
Which chapter has the most paragraphs? Give the description of the chapter.
most paragraphs refers to max(count(chapter_id))
SELECT T1.Description FROM chapters AS T1 INNER JOIN paragraphs AS T2 ON T1.id = T2.chapter_id ORDER BY T2.ParagraphNum DESC LIMIT 1
CREATE TABLE IF NOT EXISTS "chapters" ( id INTEGER primary key autoincrement, Act INTEGER not null, Scene INTEGER not null, Description TEXT not null, work_id INTEGER not null references works ); CREATE TABLE sqlite_sequence(name,seq); CREATE TABLE IF NOT EXISTS "characters" ( id INTEGER primary key autoincrement, CharName TEXT not null, Abbrev TEXT not null, Description TEXT not null ); CREATE TABLE IF NOT EXISTS "paragraphs" ( id INTEGER primary key autoincrement, ParagraphNum INTEGER not null, PlainText TEXT not null, character_id INTEGER not null references characters, chapter_id INTEGER default 0 not null references chapters ); CREATE TABLE IF NOT EXISTS "works" ( id INTEGER primary key autoincrement, Title TEXT not null, LongTitle TEXT not null, Date INTEGER not null, GenreType TEXT not null );
donor
What is the project title of the school located at latitude 42003718 and longitude -87668289?
latitude 42003718 refers to school_latitude = 42003718; longitude -87668289 refers to school_longitude = -87668289
SELECT T1.title FROM essays AS T1 INNER JOIN projects AS T2 ON T1.projectid = T2.projectid WHERE T2.school_latitude = 42003718 AND T2.school_longitude = -87668289
CREATE TABLE sqlite_sequence(name,seq); CREATE TABLE IF NOT EXISTS "essays" ( projectid TEXT, teacher_acctid TEXT, title TEXT, short_description TEXT, need_statement TEXT, essay TEXT ); CREATE TABLE IF NOT EXISTS "projects" ( projectid TEXT not null primary key, teacher_acctid TEXT, schoolid TEXT, school_ncesid TEXT, school_latitude REAL, school_longitude REAL, school_city TEXT, school_state TEXT, school_zip INTEGER, school_metro TEXT, school_district TEXT, school_county TEXT, school_charter TEXT, school_magnet TEXT, school_year_round TEXT, school_nlns TEXT, school_kipp TEXT, school_charter_ready_promise TEXT, teacher_prefix TEXT, teacher_teach_for_america TEXT, teacher_ny_teaching_fellow TEXT, primary_focus_subject TEXT, primary_focus_area TEXT, secondary_focus_subject TEXT, secondary_focus_area TEXT, resource_type TEXT, poverty_level TEXT, grade_level TEXT, fulfillment_labor_materials REAL, total_price_excluding_optional_support REAL, total_price_including_optional_support REAL, students_reached INTEGER, eligible_double_your_impact_match TEXT, eligible_almost_home_match TEXT, date_posted DATE ); CREATE TABLE donations ( donationid TEXT not null primary key, projectid TEXT, donor_acctid TEXT, donor_city TEXT, donor_state TEXT, donor_zip TEXT, is_teacher_acct TEXT, donation_timestamp DATETIME, donation_to_project REAL, donation_optional_support REAL, donation_total REAL, dollar_amount TEXT, donation_included_optional_support TEXT, payment_method TEXT, payment_included_acct_credit TEXT, payment_included_campaign_gift_card TEXT, payment_included_web_purchased_gift_card TEXT, payment_was_promo_matched TEXT, via_giving_page TEXT, for_honoree TEXT, donation_message TEXT, foreign key (projectid) references projects(projectid) ); CREATE TABLE resources ( resourceid TEXT not null primary key, projectid TEXT, vendorid INTEGER, vendor_name TEXT, project_resource_type TEXT, item_name TEXT, item_number TEXT, item_unit_price REAL, item_quantity INTEGER, foreign key (projectid) references projects(projectid) );
synthea
Give the procedure description of Ms. Jacquelyn Shanahan on 2009/8/9.
on 2009/8/9 refers to DATE = '2009-08-09';
SELECT DISTINCT T2.description FROM patients AS T1 INNER JOIN procedures AS T2 ON T1.patient = T2.PATIENT WHERE T1.prefix = 'Ms.' AND T1.first = 'Jacquelyn' AND T1.last = 'Shanahan' AND T2.DATE = '2009-08-09'
CREATE TABLE all_prevalences ( ITEM TEXT primary key, "POPULATION TYPE" TEXT, OCCURRENCES INTEGER, "POPULATION COUNT" INTEGER, "PREVALENCE RATE" REAL, "PREVALENCE PERCENTAGE" REAL ); CREATE TABLE patients ( patient TEXT primary key, birthdate DATE, deathdate DATE, ssn TEXT, drivers TEXT, passport TEXT, prefix TEXT, first TEXT, last TEXT, suffix TEXT, maiden TEXT, marital TEXT, race TEXT, ethnicity TEXT, gender TEXT, birthplace TEXT, address TEXT ); CREATE TABLE encounters ( ID TEXT primary key, DATE DATE, PATIENT TEXT, CODE INTEGER, DESCRIPTION TEXT, REASONCODE INTEGER, REASONDESCRIPTION TEXT, foreign key (PATIENT) references patients(patient) ); CREATE TABLE allergies ( START TEXT, STOP TEXT, PATIENT TEXT, ENCOUNTER TEXT, CODE INTEGER, DESCRIPTION TEXT, primary key (PATIENT, ENCOUNTER, CODE), foreign key (ENCOUNTER) references encounters(ID), foreign key (PATIENT) references patients(patient) ); CREATE TABLE careplans ( ID TEXT, START DATE, STOP DATE, PATIENT TEXT, ENCOUNTER TEXT, CODE REAL, DESCRIPTION TEXT, REASONCODE INTEGER, REASONDESCRIPTION TEXT, foreign key (ENCOUNTER) references encounters(ID), foreign key (PATIENT) references patients(patient) ); CREATE TABLE conditions ( START DATE, STOP DATE, PATIENT TEXT, ENCOUNTER TEXT, CODE INTEGER, DESCRIPTION TEXT, foreign key (ENCOUNTER) references encounters(ID), foreign key (PATIENT) references patients(patient), foreign key (DESCRIPTION) references all_prevalences(ITEM) ); CREATE TABLE immunizations ( DATE DATE, PATIENT TEXT, ENCOUNTER TEXT, CODE INTEGER, DESCRIPTION TEXT, primary key (DATE, PATIENT, ENCOUNTER, CODE), foreign key (ENCOUNTER) references encounters(ID), foreign key (PATIENT) references patients(patient) ); CREATE TABLE medications ( START DATE, STOP DATE, PATIENT TEXT, ENCOUNTER TEXT, CODE INTEGER, DESCRIPTION TEXT, REASONCODE INTEGER, REASONDESCRIPTION TEXT, primary key (START, PATIENT, ENCOUNTER, CODE), foreign key (ENCOUNTER) references encounters(ID), foreign key (PATIENT) references patients(patient) ); CREATE TABLE observations ( DATE DATE, PATIENT TEXT, ENCOUNTER TEXT, CODE TEXT, DESCRIPTION TEXT, VALUE REAL, UNITS TEXT, foreign key (ENCOUNTER) references encounters(ID), foreign key (PATIENT) references patients(patient) ); CREATE TABLE procedures ( DATE DATE, PATIENT TEXT, ENCOUNTER TEXT, CODE INTEGER, DESCRIPTION TEXT, REASONCODE INTEGER, REASONDESCRIPTION TEXT, foreign key (ENCOUNTER) references encounters(ID), foreign key (PATIENT) references patients(patient) ); CREATE TABLE IF NOT EXISTS "claims" ( ID TEXT primary key, PATIENT TEXT references patients, BILLABLEPERIOD DATE, ORGANIZATION TEXT, ENCOUNTER TEXT references encounters, DIAGNOSIS TEXT, TOTAL INTEGER );
computer_student
How many advisors are in charge of advising all the students in 1st year?
advisors refers to p_id_dummy; students in 1st year refers to student = 1 and yearsInProgram = 'Year_1'
SELECT COUNT(T1.p_id_dummy) FROM advisedBy AS T1 INNER JOIN person AS T2 ON T1.p_id = T2.p_id WHERE T2.yearsInProgram = 'Year_1' AND T2.student = 1
CREATE TABLE course ( course_id INTEGER constraint course_pk primary key, courseLevel TEXT ); CREATE TABLE person ( p_id INTEGER constraint person_pk primary key, professor INTEGER, student INTEGER, hasPosition TEXT, inPhase TEXT, yearsInProgram TEXT ); CREATE TABLE IF NOT EXISTS "advisedBy" ( p_id INTEGER, p_id_dummy INTEGER, constraint advisedBy_pk primary key (p_id, p_id_dummy), constraint advisedBy_person_p_id_p_id_fk foreign key (p_id, p_id_dummy) references person (p_id, p_id) ); CREATE TABLE taughtBy ( course_id INTEGER, p_id INTEGER, primary key (course_id, p_id), foreign key (p_id) references person(p_id), foreign key (course_id) references course(course_id) );
student_loan
How many disabled students are male?
male students are mentioned in male.name;
SELECT COUNT(T1.name) FROM male AS T1 INNER JOIN disabled AS T2 ON T1.name = T2.name
CREATE TABLE bool ( "name" TEXT default '' not null primary key ); CREATE TABLE person ( "name" TEXT default '' not null primary key ); CREATE TABLE disabled ( "name" TEXT default '' not null primary key, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE enlist ( "name" TEXT not null, organ TEXT not null, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE filed_for_bankrupcy ( "name" TEXT default '' not null primary key, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE longest_absense_from_school ( "name" TEXT default '' not null primary key, "month" INTEGER default 0 null, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE male ( "name" TEXT default '' not null primary key, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE no_payment_due ( "name" TEXT default '' not null primary key, bool TEXT null, foreign key ("name") references person ("name") on update cascade on delete cascade, foreign key (bool) references bool ("name") on update cascade on delete cascade ); CREATE TABLE unemployed ( "name" TEXT default '' not null primary key, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE `enrolled` ( `name` TEXT NOT NULL, `school` TEXT NOT NULL, `month` INTEGER NOT NULL DEFAULT 0, PRIMARY KEY (`name`,`school`), FOREIGN KEY (`name`) REFERENCES `person` (`name`) ON DELETE CASCADE ON UPDATE CASCADE );
university
Give the name of the university with the most number of students in 2015.
most number of students refers to MAX(num_students); in 2015 refers to year = 2015; name of university refers to university_name;
SELECT T2.university_name FROM university_year AS T1 INNER JOIN university AS T2 ON T1.university_id = T2.id WHERE T1.year = 2015 ORDER BY T1.num_students DESC LIMIT 1
CREATE TABLE country ( id INTEGER not null primary key, country_name TEXT default NULL ); CREATE TABLE ranking_system ( id INTEGER not null primary key, system_name TEXT default NULL ); CREATE TABLE ranking_criteria ( id INTEGER not null primary key, ranking_system_id INTEGER default NULL, criteria_name TEXT default NULL, foreign key (ranking_system_id) references ranking_system(id) ); CREATE TABLE university ( id INTEGER not null primary key, country_id INTEGER default NULL, university_name TEXT default NULL, foreign key (country_id) references country(id) ); CREATE TABLE university_ranking_year ( university_id INTEGER default NULL, ranking_criteria_id INTEGER default NULL, year INTEGER default NULL, score INTEGER default NULL, foreign key (ranking_criteria_id) references ranking_criteria(id), foreign key (university_id) references university(id) ); CREATE TABLE university_year ( university_id INTEGER default NULL, year INTEGER default NULL, num_students INTEGER default NULL, student_staff_ratio REAL default NULL, pct_international_students INTEGER default NULL, pct_female_students INTEGER default NULL, foreign key (university_id) references university(id) );
books
What is the title of the book in the order ID 931?
SELECT T1.title FROM book AS T1 INNER JOIN order_line AS T2 ON T1.book_id = T2.book_id WHERE T2.order_id = 931
CREATE TABLE address_status ( status_id INTEGER primary key, address_status TEXT ); CREATE TABLE author ( author_id INTEGER primary key, author_name TEXT ); CREATE TABLE book_language ( language_id INTEGER primary key, language_code TEXT, language_name TEXT ); CREATE TABLE country ( country_id INTEGER primary key, country_name TEXT ); CREATE TABLE address ( address_id INTEGER primary key, street_number TEXT, street_name TEXT, city TEXT, country_id INTEGER, foreign key (country_id) references country(country_id) ); CREATE TABLE customer ( customer_id INTEGER primary key, first_name TEXT, last_name TEXT, email TEXT ); CREATE TABLE customer_address ( customer_id INTEGER, address_id INTEGER, status_id INTEGER, primary key (customer_id, address_id), foreign key (address_id) references address(address_id), foreign key (customer_id) references customer(customer_id) ); CREATE TABLE order_status ( status_id INTEGER primary key, status_value TEXT ); CREATE TABLE publisher ( publisher_id INTEGER primary key, publisher_name TEXT ); CREATE TABLE book ( book_id INTEGER primary key, title TEXT, isbn13 TEXT, language_id INTEGER, num_pages INTEGER, publication_date DATE, publisher_id INTEGER, foreign key (language_id) references book_language(language_id), foreign key (publisher_id) references publisher(publisher_id) ); CREATE TABLE book_author ( book_id INTEGER, author_id INTEGER, primary key (book_id, author_id), foreign key (author_id) references author(author_id), foreign key (book_id) references book(book_id) ); CREATE TABLE shipping_method ( method_id INTEGER primary key, method_name TEXT, cost REAL ); CREATE TABLE IF NOT EXISTS "cust_order" ( order_id INTEGER primary key autoincrement, order_date DATETIME, customer_id INTEGER references customer, shipping_method_id INTEGER references shipping_method, dest_address_id INTEGER references address ); CREATE TABLE sqlite_sequence(name,seq); CREATE TABLE IF NOT EXISTS "order_history" ( history_id INTEGER primary key autoincrement, order_id INTEGER references cust_order, status_id INTEGER references order_status, status_date DATETIME ); CREATE TABLE IF NOT EXISTS "order_line" ( line_id INTEGER primary key autoincrement, order_id INTEGER references cust_order, book_id INTEGER references book, price REAL );
bike_share_1
Which year experienced the most rain?
events = 'Rain'; year refers to YEAR(date);
SELECT SUBSTR(CAST(date AS TEXT), -4) FROM weather GROUP BY SUBSTR(CAST(date AS TEXT), -4) ORDER BY SUM(CASE WHEN events LIKE '%Rain%' OR events LIKE '%rain%' THEN 1 ELSE 0 END) DESC LIMIT 1
CREATE TABLE IF NOT EXISTS "station" ( id INTEGER not null primary key, name TEXT, lat REAL, long REAL, dock_count INTEGER, city TEXT, installation_date TEXT ); CREATE TABLE IF NOT EXISTS "status" ( station_id INTEGER, bikes_available INTEGER, docks_available INTEGER, time TEXT ); CREATE TABLE IF NOT EXISTS "trip" ( id INTEGER not null primary key, duration INTEGER, start_date TEXT, start_station_name TEXT, start_station_id INTEGER, end_date TEXT, end_station_name TEXT, end_station_id INTEGER, bike_id INTEGER, subscription_type TEXT, zip_code INTEGER ); CREATE TABLE IF NOT EXISTS "weather" ( date TEXT, max_temperature_f INTEGER, mean_temperature_f INTEGER, min_temperature_f INTEGER, max_dew_point_f INTEGER, mean_dew_point_f INTEGER, min_dew_point_f INTEGER, max_humidity INTEGER, mean_humidity INTEGER, min_humidity INTEGER, max_sea_level_pressure_inches REAL, mean_sea_level_pressure_inches REAL, min_sea_level_pressure_inches REAL, max_visibility_miles INTEGER, mean_visibility_miles INTEGER, min_visibility_miles INTEGER, max_wind_Speed_mph INTEGER, mean_wind_speed_mph INTEGER, max_gust_speed_mph INTEGER, precipitation_inches TEXT, cloud_cover INTEGER, events TEXT, wind_dir_degrees INTEGER, zip_code TEXT );
language_corpus
What is the occurrence of the word "nombre"?
This is not;
SELECT occurrences FROM words WHERE word = 'nombre'
CREATE TABLE langs(lid INTEGER PRIMARY KEY AUTOINCREMENT, lang TEXT UNIQUE, locale TEXT UNIQUE, pages INTEGER DEFAULT 0, -- total pages in this language words INTEGER DEFAULT 0); CREATE TABLE sqlite_sequence(name,seq); CREATE TABLE pages(pid INTEGER PRIMARY KEY AUTOINCREMENT, lid INTEGER REFERENCES langs(lid) ON UPDATE CASCADE ON DELETE CASCADE, page INTEGER DEFAULT NULL, -- wikipedia page id revision INTEGER DEFAULT NULL, -- wikipedia revision page id title TEXT, words INTEGER DEFAULT 0, -- number of different words in this page UNIQUE(lid,page,title)); CREATE TRIGGER ins_page AFTER INSERT ON pages FOR EACH ROW BEGIN UPDATE langs SET pages=pages+1 WHERE lid=NEW.lid; END; CREATE TRIGGER del_page AFTER DELETE ON pages FOR EACH ROW BEGIN UPDATE langs SET pages=pages-1 WHERE lid=OLD.lid; END; CREATE TABLE words(wid INTEGER PRIMARY KEY AUTOINCREMENT, word TEXT UNIQUE, occurrences INTEGER DEFAULT 0); CREATE TABLE langs_words(lid INTEGER REFERENCES langs(lid) ON UPDATE CASCADE ON DELETE CASCADE, wid INTEGER REFERENCES words(wid) ON UPDATE CASCADE ON DELETE CASCADE, occurrences INTEGER, -- repetitions of this word in this language PRIMARY KEY(lid,wid)) WITHOUT ROWID; CREATE TRIGGER ins_lang_word AFTER INSERT ON langs_words FOR EACH ROW BEGIN UPDATE langs SET words=words+1 WHERE lid=NEW.lid; END; CREATE TRIGGER del_lang_word AFTER DELETE ON langs_words FOR EACH ROW BEGIN UPDATE langs SET words=words-1 WHERE lid=OLD.lid; END; CREATE TABLE pages_words(pid INTEGER REFERENCES pages(pid) ON UPDATE CASCADE ON DELETE CASCADE, wid INTEGER REFERENCES words(wid) ON UPDATE CASCADE ON DELETE CASCADE, occurrences INTEGER DEFAULT 0, -- times this word appears into this page PRIMARY KEY(pid,wid)) WITHOUT ROWID; CREATE TRIGGER ins_page_word AFTER INSERT ON pages_words FOR EACH ROW BEGIN UPDATE pages SET words=words+1 WHERE pid=NEW.pid; END; CREATE TRIGGER del_page_word AFTER DELETE ON pages_words FOR EACH ROW BEGIN UPDATE pages SET words=words-1 WHERE pid=OLD.pid; END; CREATE TABLE biwords(lid INTEGER REFERENCES langs(lid) ON UPDATE CASCADE ON DELETE CASCADE, w1st INTEGER REFERENCES words(wid) ON UPDATE CASCADE ON DELETE CASCADE, w2nd INTEGER REFERENCES words(wid) ON UPDATE CASCADE ON DELETE CASCADE, occurrences INTEGER DEFAULT 0, -- times this pair appears in this language/page PRIMARY KEY(lid,w1st,w2nd)) WITHOUT ROWID;
legislator
Which legislators are woman?
woman refers to gender_bio = 'F';
SELECT first_name, last_name FROM historical WHERE gender_bio = 'F'
CREATE TABLE current ( ballotpedia_id TEXT, bioguide_id TEXT, birthday_bio DATE, cspan_id REAL, fec_id TEXT, first_name TEXT, gender_bio TEXT, google_entity_id_id TEXT, govtrack_id INTEGER, house_history_id REAL, icpsr_id REAL, last_name TEXT, lis_id TEXT, maplight_id REAL, middle_name TEXT, nickname_name TEXT, official_full_name TEXT, opensecrets_id TEXT, religion_bio TEXT, suffix_name TEXT, thomas_id INTEGER, votesmart_id REAL, wikidata_id TEXT, wikipedia_id TEXT, primary key (bioguide_id, cspan_id) ); CREATE TABLE IF NOT EXISTS "current-terms" ( address TEXT, bioguide TEXT, caucus TEXT, chamber TEXT, class REAL, contact_form TEXT, district REAL, end TEXT, fax TEXT, last TEXT, name TEXT, office TEXT, party TEXT, party_affiliations TEXT, phone TEXT, relation TEXT, rss_url TEXT, start TEXT, state TEXT, state_rank TEXT, title TEXT, type TEXT, url TEXT, primary key (bioguide, end), foreign key (bioguide) references current(bioguide_id) ); CREATE TABLE historical ( ballotpedia_id TEXT, bioguide_id TEXT primary key, bioguide_previous_id TEXT, birthday_bio TEXT, cspan_id TEXT, fec_id TEXT, first_name TEXT, gender_bio TEXT, google_entity_id_id TEXT, govtrack_id INTEGER, house_history_alternate_id TEXT, house_history_id REAL, icpsr_id REAL, last_name TEXT, lis_id TEXT, maplight_id TEXT, middle_name TEXT, nickname_name TEXT, official_full_name TEXT, opensecrets_id TEXT, religion_bio TEXT, suffix_name TEXT, thomas_id TEXT, votesmart_id TEXT, wikidata_id TEXT, wikipedia_id TEXT ); CREATE TABLE IF NOT EXISTS "historical-terms" ( address TEXT, bioguide TEXT primary key, chamber TEXT, class REAL, contact_form TEXT, district REAL, end TEXT, fax TEXT, last TEXT, middle TEXT, name TEXT, office TEXT, party TEXT, party_affiliations TEXT, phone TEXT, relation TEXT, rss_url TEXT, start TEXT, state TEXT, state_rank TEXT, title TEXT, type TEXT, url TEXT, foreign key (bioguide) references historical(bioguide_id) ); CREATE TABLE IF NOT EXISTS "social-media" ( bioguide TEXT primary key, facebook TEXT, facebook_id REAL, govtrack REAL, instagram TEXT, instagram_id REAL, thomas INTEGER, twitter TEXT, twitter_id REAL, youtube TEXT, youtube_id TEXT, foreign key (bioguide) references current(bioguide_id) );
video_games
What is the least common game genre?
the least common game genre refers to min(count(genre_id)); genre refers to genre_name
SELECT T.game_name FROM ( SELECT T2.game_name, COUNT(T2.id) FROM genre AS T1 INNER JOIN game AS T2 ON T1.id = T2.genre_id GROUP BY T2.game_name ORDER BY COUNT(T2.id) ASC LIMIT 1 ) t
CREATE TABLE genre ( id INTEGER not null primary key, genre_name TEXT default NULL ); CREATE TABLE game ( id INTEGER not null primary key, genre_id INTEGER default NULL, game_name TEXT default NULL, foreign key (genre_id) references genre(id) ); CREATE TABLE platform ( id INTEGER not null primary key, platform_name TEXT default NULL ); CREATE TABLE publisher ( id INTEGER not null primary key, publisher_name TEXT default NULL ); CREATE TABLE game_publisher ( id INTEGER not null primary key, game_id INTEGER default NULL, publisher_id INTEGER default NULL, foreign key (game_id) references game(id), foreign key (publisher_id) references publisher(id) ); CREATE TABLE game_platform ( id INTEGER not null primary key, game_publisher_id INTEGER default NULL, platform_id INTEGER default NULL, release_year INTEGER default NULL, foreign key (game_publisher_id) references game_publisher(id), foreign key (platform_id) references platform(id) ); CREATE TABLE region ( id INTEGER not null primary key, region_name TEXT default NULL ); CREATE TABLE region_sales ( region_id INTEGER default NULL, game_platform_id INTEGER default NULL, num_sales REAL default NULL, foreign key (game_platform_id) references game_platform(id), foreign key (region_id) references region(id) );
works_cycles
Lists all companies by BusinessEntityID that increased their current year sales by more than 60% over last year's sales and have a bonus greater than 3,000.
increased their current year sales by more than 60% refers to DIVIDE(SUBTRACT(SalesYTD, SalesLastYear),SalesLastYear)>0.6
SELECT BusinessEntityID FROM SalesPerson WHERE SalesYTD > SalesLastYear + SalesLastyear * 0.6 AND Bonus > 3000
CREATE TABLE sqlite_sequence(name,seq); CREATE TABLE CountryRegion ( CountryRegionCode TEXT not null primary key, Name TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE Culture ( CultureID TEXT not null primary key, Name TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE Currency ( CurrencyCode TEXT not null primary key, Name TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE CountryRegionCurrency ( CountryRegionCode TEXT not null, CurrencyCode TEXT not null, ModifiedDate DATETIME default current_timestamp not null, primary key (CountryRegionCode, CurrencyCode), foreign key (CountryRegionCode) references CountryRegion(CountryRegionCode), foreign key (CurrencyCode) references Currency(CurrencyCode) ); CREATE TABLE Person ( BusinessEntityID INTEGER not null primary key, PersonType TEXT not null, NameStyle INTEGER default 0 not null, Title TEXT, FirstName TEXT not null, MiddleName TEXT, LastName TEXT not null, Suffix TEXT, EmailPromotion INTEGER default 0 not null, AdditionalContactInfo TEXT, Demographics TEXT, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null, foreign key (BusinessEntityID) references BusinessEntity(BusinessEntityID) ); CREATE TABLE BusinessEntityContact ( BusinessEntityID INTEGER not null, PersonID INTEGER not null, ContactTypeID INTEGER not null, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null, primary key (BusinessEntityID, PersonID, ContactTypeID), foreign key (BusinessEntityID) references BusinessEntity(BusinessEntityID), foreign key (ContactTypeID) references ContactType(ContactTypeID), foreign key (PersonID) references Person(BusinessEntityID) ); CREATE TABLE EmailAddress ( BusinessEntityID INTEGER not null, EmailAddressID INTEGER, EmailAddress TEXT, rowguid TEXT not null, ModifiedDate DATETIME default current_timestamp not null, primary key (EmailAddressID, BusinessEntityID), foreign key (BusinessEntityID) references Person(BusinessEntityID) ); CREATE TABLE Employee ( BusinessEntityID INTEGER not null primary key, NationalIDNumber TEXT not null unique, LoginID TEXT not null unique, OrganizationNode TEXT, OrganizationLevel INTEGER, JobTitle TEXT not null, BirthDate DATE not null, MaritalStatus TEXT not null, Gender TEXT not null, HireDate DATE not null, SalariedFlag INTEGER default 1 not null, VacationHours INTEGER default 0 not null, SickLeaveHours INTEGER default 0 not null, CurrentFlag INTEGER default 1 not null, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null, foreign key (BusinessEntityID) references Person(BusinessEntityID) ); CREATE TABLE Password ( BusinessEntityID INTEGER not null primary key, PasswordHash TEXT not null, PasswordSalt TEXT not null, rowguid TEXT not null, ModifiedDate DATETIME default current_timestamp not null, foreign key (BusinessEntityID) references Person(BusinessEntityID) ); CREATE TABLE PersonCreditCard ( BusinessEntityID INTEGER not null, CreditCardID INTEGER not null, ModifiedDate DATETIME default current_timestamp not null, primary key (BusinessEntityID, CreditCardID), foreign key (CreditCardID) references CreditCard(CreditCardID), foreign key (BusinessEntityID) references Person(BusinessEntityID) ); CREATE TABLE ProductCategory ( ProductCategoryID INTEGER primary key autoincrement, Name TEXT not null unique, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE ProductDescription ( ProductDescriptionID INTEGER primary key autoincrement, Description TEXT not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE ProductModel ( ProductModelID INTEGER primary key autoincrement, Name TEXT not null unique, CatalogDescription TEXT, Instructions TEXT, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE ProductModelProductDescriptionCulture ( ProductModelID INTEGER not null, ProductDescriptionID INTEGER not null, CultureID TEXT not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (ProductModelID, ProductDescriptionID, CultureID), foreign key (ProductModelID) references ProductModel(ProductModelID), foreign key (ProductDescriptionID) references ProductDescription(ProductDescriptionID), foreign key (CultureID) references Culture(CultureID) ); CREATE TABLE ProductPhoto ( ProductPhotoID INTEGER primary key autoincrement, ThumbNailPhoto BLOB, ThumbnailPhotoFileName TEXT, LargePhoto BLOB, LargePhotoFileName TEXT, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE ProductSubcategory ( ProductSubcategoryID INTEGER primary key autoincrement, ProductCategoryID INTEGER not null, Name TEXT not null unique, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (ProductCategoryID) references ProductCategory(ProductCategoryID) ); CREATE TABLE SalesReason ( SalesReasonID INTEGER primary key autoincrement, Name TEXT not null, ReasonType TEXT not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE SalesTerritory ( TerritoryID INTEGER primary key autoincrement, Name TEXT not null unique, CountryRegionCode TEXT not null, "Group" TEXT not null, SalesYTD REAL default 0.0000 not null, SalesLastYear REAL default 0.0000 not null, CostYTD REAL default 0.0000 not null, CostLastYear REAL default 0.0000 not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (CountryRegionCode) references CountryRegion(CountryRegionCode) ); CREATE TABLE SalesPerson ( BusinessEntityID INTEGER not null primary key, TerritoryID INTEGER, SalesQuota REAL, Bonus REAL default 0.0000 not null, CommissionPct REAL default 0.0000 not null, SalesYTD REAL default 0.0000 not null, SalesLastYear REAL default 0.0000 not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (BusinessEntityID) references Employee(BusinessEntityID), foreign key (TerritoryID) references SalesTerritory(TerritoryID) ); CREATE TABLE SalesPersonQuotaHistory ( BusinessEntityID INTEGER not null, QuotaDate DATETIME not null, SalesQuota REAL not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (BusinessEntityID, QuotaDate), foreign key (BusinessEntityID) references SalesPerson(BusinessEntityID) ); CREATE TABLE SalesTerritoryHistory ( BusinessEntityID INTEGER not null, TerritoryID INTEGER not null, StartDate DATETIME not null, EndDate DATETIME, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (BusinessEntityID, StartDate, TerritoryID), foreign key (BusinessEntityID) references SalesPerson(BusinessEntityID), foreign key (TerritoryID) references SalesTerritory(TerritoryID) ); CREATE TABLE ScrapReason ( ScrapReasonID INTEGER primary key autoincrement, Name TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE Shift ( ShiftID INTEGER primary key autoincrement, Name TEXT not null unique, StartTime TEXT not null, EndTime TEXT not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, unique (StartTime, EndTime) ); CREATE TABLE ShipMethod ( ShipMethodID INTEGER primary key autoincrement, Name TEXT not null unique, ShipBase REAL default 0.0000 not null, ShipRate REAL default 0.0000 not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE SpecialOffer ( SpecialOfferID INTEGER primary key autoincrement, Description TEXT not null, DiscountPct REAL default 0.0000 not null, Type TEXT not null, Category TEXT not null, StartDate DATETIME not null, EndDate DATETIME not null, MinQty INTEGER default 0 not null, MaxQty INTEGER, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE BusinessEntityAddress ( BusinessEntityID INTEGER not null, AddressID INTEGER not null, AddressTypeID INTEGER not null, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null, primary key (BusinessEntityID, AddressID, AddressTypeID), foreign key (AddressID) references Address(AddressID), foreign key (AddressTypeID) references AddressType(AddressTypeID), foreign key (BusinessEntityID) references BusinessEntity(BusinessEntityID) ); CREATE TABLE SalesTaxRate ( SalesTaxRateID INTEGER primary key autoincrement, StateProvinceID INTEGER not null, TaxType INTEGER not null, TaxRate REAL default 0.0000 not null, Name TEXT not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, unique (StateProvinceID, TaxType), foreign key (StateProvinceID) references StateProvince(StateProvinceID) ); CREATE TABLE Store ( BusinessEntityID INTEGER not null primary key, Name TEXT not null, SalesPersonID INTEGER, Demographics TEXT, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (BusinessEntityID) references BusinessEntity(BusinessEntityID), foreign key (SalesPersonID) references SalesPerson(BusinessEntityID) ); CREATE TABLE SalesOrderHeaderSalesReason ( SalesOrderID INTEGER not null, SalesReasonID INTEGER not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (SalesOrderID, SalesReasonID), foreign key (SalesOrderID) references SalesOrderHeader(SalesOrderID), foreign key (SalesReasonID) references SalesReason(SalesReasonID) ); CREATE TABLE TransactionHistoryArchive ( TransactionID INTEGER not null primary key, ProductID INTEGER not null, ReferenceOrderID INTEGER not null, ReferenceOrderLineID INTEGER default 0 not null, TransactionDate DATETIME default CURRENT_TIMESTAMP not null, TransactionType TEXT not null, Quantity INTEGER not null, ActualCost REAL not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE UnitMeasure ( UnitMeasureCode TEXT not null primary key, Name TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null ); CREATE TABLE ProductCostHistory ( ProductID INTEGER not null, StartDate DATE not null, EndDate DATE, StandardCost REAL not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (ProductID, StartDate), foreign key (ProductID) references Product(ProductID) ); CREATE TABLE ProductDocument ( ProductID INTEGER not null, DocumentNode TEXT not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (ProductID, DocumentNode), foreign key (ProductID) references Product(ProductID), foreign key (DocumentNode) references Document(DocumentNode) ); CREATE TABLE ProductInventory ( ProductID INTEGER not null, LocationID INTEGER not null, Shelf TEXT not null, Bin INTEGER not null, Quantity INTEGER default 0 not null, rowguid TEXT not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (ProductID, LocationID), foreign key (ProductID) references Product(ProductID), foreign key (LocationID) references Location(LocationID) ); CREATE TABLE ProductProductPhoto ( ProductID INTEGER not null, ProductPhotoID INTEGER not null, "Primary" INTEGER default 0 not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (ProductID, ProductPhotoID), foreign key (ProductID) references Product(ProductID), foreign key (ProductPhotoID) references ProductPhoto(ProductPhotoID) ); CREATE TABLE ProductReview ( ProductReviewID INTEGER primary key autoincrement, ProductID INTEGER not null, ReviewerName TEXT not null, ReviewDate DATETIME default CURRENT_TIMESTAMP not null, EmailAddress TEXT not null, Rating INTEGER not null, Comments TEXT, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (ProductID) references Product(ProductID) ); CREATE TABLE ShoppingCartItem ( ShoppingCartItemID INTEGER primary key autoincrement, ShoppingCartID TEXT not null, Quantity INTEGER default 1 not null, ProductID INTEGER not null, DateCreated DATETIME default CURRENT_TIMESTAMP not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (ProductID) references Product(ProductID) ); CREATE TABLE SpecialOfferProduct ( SpecialOfferID INTEGER not null, ProductID INTEGER not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (SpecialOfferID, ProductID), foreign key (SpecialOfferID) references SpecialOffer(SpecialOfferID), foreign key (ProductID) references Product(ProductID) ); CREATE TABLE SalesOrderDetail ( SalesOrderID INTEGER not null, SalesOrderDetailID INTEGER primary key autoincrement, CarrierTrackingNumber TEXT, OrderQty INTEGER not null, ProductID INTEGER not null, SpecialOfferID INTEGER not null, UnitPrice REAL not null, UnitPriceDiscount REAL default 0.0000 not null, LineTotal REAL not null, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (SalesOrderID) references SalesOrderHeader(SalesOrderID), foreign key (SpecialOfferID, ProductID) references SpecialOfferProduct(SpecialOfferID, ProductID) ); CREATE TABLE TransactionHistory ( TransactionID INTEGER primary key autoincrement, ProductID INTEGER not null, ReferenceOrderID INTEGER not null, ReferenceOrderLineID INTEGER default 0 not null, TransactionDate DATETIME default CURRENT_TIMESTAMP not null, TransactionType TEXT not null, Quantity INTEGER not null, ActualCost REAL not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (ProductID) references Product(ProductID) ); CREATE TABLE Vendor ( BusinessEntityID INTEGER not null primary key, AccountNumber TEXT not null unique, Name TEXT not null, CreditRating INTEGER not null, PreferredVendorStatus INTEGER default 1 not null, ActiveFlag INTEGER default 1 not null, PurchasingWebServiceURL TEXT, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (BusinessEntityID) references BusinessEntity(BusinessEntityID) ); CREATE TABLE ProductVendor ( ProductID INTEGER not null, BusinessEntityID INTEGER not null, AverageLeadTime INTEGER not null, StandardPrice REAL not null, LastReceiptCost REAL, LastReceiptDate DATETIME, MinOrderQty INTEGER not null, MaxOrderQty INTEGER not null, OnOrderQty INTEGER, UnitMeasureCode TEXT not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (ProductID, BusinessEntityID), foreign key (ProductID) references Product(ProductID), foreign key (BusinessEntityID) references Vendor(BusinessEntityID), foreign key (UnitMeasureCode) references UnitMeasure(UnitMeasureCode) ); CREATE TABLE PurchaseOrderHeader ( PurchaseOrderID INTEGER primary key autoincrement, RevisionNumber INTEGER default 0 not null, Status INTEGER default 1 not null, EmployeeID INTEGER not null, VendorID INTEGER not null, ShipMethodID INTEGER not null, OrderDate DATETIME default CURRENT_TIMESTAMP not null, ShipDate DATETIME, SubTotal REAL default 0.0000 not null, TaxAmt REAL default 0.0000 not null, Freight REAL default 0.0000 not null, TotalDue REAL not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (EmployeeID) references Employee(BusinessEntityID), foreign key (VendorID) references Vendor(BusinessEntityID), foreign key (ShipMethodID) references ShipMethod(ShipMethodID) ); CREATE TABLE PurchaseOrderDetail ( PurchaseOrderID INTEGER not null, PurchaseOrderDetailID INTEGER primary key autoincrement, DueDate DATETIME not null, OrderQty INTEGER not null, ProductID INTEGER not null, UnitPrice REAL not null, LineTotal REAL not null, ReceivedQty REAL not null, RejectedQty REAL not null, StockedQty REAL not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (PurchaseOrderID) references PurchaseOrderHeader(PurchaseOrderID), foreign key (ProductID) references Product(ProductID) ); CREATE TABLE WorkOrder ( WorkOrderID INTEGER primary key autoincrement, ProductID INTEGER not null, OrderQty INTEGER not null, StockedQty INTEGER not null, ScrappedQty INTEGER not null, StartDate DATETIME not null, EndDate DATETIME, DueDate DATETIME not null, ScrapReasonID INTEGER, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, foreign key (ProductID) references Product(ProductID), foreign key (ScrapReasonID) references ScrapReason(ScrapReasonID) ); CREATE TABLE WorkOrderRouting ( WorkOrderID INTEGER not null, ProductID INTEGER not null, OperationSequence INTEGER not null, LocationID INTEGER not null, ScheduledStartDate DATETIME not null, ScheduledEndDate DATETIME not null, ActualStartDate DATETIME, ActualEndDate DATETIME, ActualResourceHrs REAL, PlannedCost REAL not null, ActualCost REAL, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (WorkOrderID, ProductID, OperationSequence), foreign key (WorkOrderID) references WorkOrder(WorkOrderID), foreign key (LocationID) references Location(LocationID) ); CREATE TABLE Customer ( CustomerID INTEGER primary key, PersonID INTEGER, StoreID INTEGER, TerritoryID INTEGER, AccountNumber TEXT not null unique, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null, foreign key (PersonID) references Person(BusinessEntityID), foreign key (TerritoryID) references SalesTerritory(TerritoryID), foreign key (StoreID) references Store(BusinessEntityID) ); CREATE TABLE ProductListPriceHistory ( ProductID INTEGER not null, StartDate DATE not null, EndDate DATE, ListPrice REAL not null, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, primary key (ProductID, StartDate), foreign key (ProductID) references Product(ProductID) ); CREATE TABLE IF NOT EXISTS "Address" ( AddressID INTEGER primary key autoincrement, AddressLine1 TEXT not null, AddressLine2 TEXT, City TEXT not null, StateProvinceID INTEGER not null references StateProvince, PostalCode TEXT not null, SpatialLocation TEXT, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null, unique (AddressLine1, AddressLine2, City, StateProvinceID, PostalCode) ); CREATE TABLE IF NOT EXISTS "AddressType" ( AddressTypeID INTEGER primary key autoincrement, Name TEXT not null unique, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "BillOfMaterials" ( BillOfMaterialsID INTEGER primary key autoincrement, ProductAssemblyID INTEGER references Product, ComponentID INTEGER not null references Product, StartDate DATETIME default current_timestamp not null, EndDate DATETIME, UnitMeasureCode TEXT not null references UnitMeasure, BOMLevel INTEGER not null, PerAssemblyQty REAL default 1.00 not null, ModifiedDate DATETIME default current_timestamp not null, unique (ProductAssemblyID, ComponentID, StartDate) ); CREATE TABLE IF NOT EXISTS "BusinessEntity" ( BusinessEntityID INTEGER primary key autoincrement, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "ContactType" ( ContactTypeID INTEGER primary key autoincrement, Name TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "CurrencyRate" ( CurrencyRateID INTEGER primary key autoincrement, CurrencyRateDate DATETIME not null, FromCurrencyCode TEXT not null references Currency, ToCurrencyCode TEXT not null references Currency, AverageRate REAL not null, EndOfDayRate REAL not null, ModifiedDate DATETIME default current_timestamp not null, unique (CurrencyRateDate, FromCurrencyCode, ToCurrencyCode) ); CREATE TABLE IF NOT EXISTS "Department" ( DepartmentID INTEGER primary key autoincrement, Name TEXT not null unique, GroupName TEXT not null, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "EmployeeDepartmentHistory" ( BusinessEntityID INTEGER not null references Employee, DepartmentID INTEGER not null references Department, ShiftID INTEGER not null references Shift, StartDate DATE not null, EndDate DATE, ModifiedDate DATETIME default current_timestamp not null, primary key (BusinessEntityID, StartDate, DepartmentID, ShiftID) ); CREATE TABLE IF NOT EXISTS "EmployeePayHistory" ( BusinessEntityID INTEGER not null references Employee, RateChangeDate DATETIME not null, Rate REAL not null, PayFrequency INTEGER not null, ModifiedDate DATETIME default current_timestamp not null, primary key (BusinessEntityID, RateChangeDate) ); CREATE TABLE IF NOT EXISTS "JobCandidate" ( JobCandidateID INTEGER primary key autoincrement, BusinessEntityID INTEGER references Employee, Resume TEXT, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "Location" ( LocationID INTEGER primary key autoincrement, Name TEXT not null unique, CostRate REAL default 0.0000 not null, Availability REAL default 0.00 not null, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "PhoneNumberType" ( PhoneNumberTypeID INTEGER primary key autoincrement, Name TEXT not null, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "Product" ( ProductID INTEGER primary key autoincrement, Name TEXT not null unique, ProductNumber TEXT not null unique, MakeFlag INTEGER default 1 not null, FinishedGoodsFlag INTEGER default 1 not null, Color TEXT, SafetyStockLevel INTEGER not null, ReorderPoint INTEGER not null, StandardCost REAL not null, ListPrice REAL not null, Size TEXT, SizeUnitMeasureCode TEXT references UnitMeasure, WeightUnitMeasureCode TEXT references UnitMeasure, Weight REAL, DaysToManufacture INTEGER not null, ProductLine TEXT, Class TEXT, Style TEXT, ProductSubcategoryID INTEGER references ProductSubcategory, ProductModelID INTEGER references ProductModel, SellStartDate DATETIME not null, SellEndDate DATETIME, DiscontinuedDate DATETIME, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "Document" ( DocumentNode TEXT not null primary key, DocumentLevel INTEGER, Title TEXT not null, Owner INTEGER not null references Employee, FolderFlag INTEGER default 0 not null, FileName TEXT not null, FileExtension TEXT not null, Revision TEXT not null, ChangeNumber INTEGER default 0 not null, Status INTEGER not null, DocumentSummary TEXT, Document BLOB, rowguid TEXT not null unique, ModifiedDate DATETIME default current_timestamp not null, unique (DocumentLevel, DocumentNode) ); CREATE TABLE IF NOT EXISTS "StateProvince" ( StateProvinceID INTEGER primary key autoincrement, StateProvinceCode TEXT not null, CountryRegionCode TEXT not null references CountryRegion, IsOnlyStateProvinceFlag INTEGER default 1 not null, Name TEXT not null unique, TerritoryID INTEGER not null references SalesTerritory, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null, unique (StateProvinceCode, CountryRegionCode) ); CREATE TABLE IF NOT EXISTS "CreditCard" ( CreditCardID INTEGER primary key autoincrement, CardType TEXT not null, CardNumber TEXT not null unique, ExpMonth INTEGER not null, ExpYear INTEGER not null, ModifiedDate DATETIME default current_timestamp not null ); CREATE TABLE IF NOT EXISTS "SalesOrderHeader" ( SalesOrderID INTEGER primary key autoincrement, RevisionNumber INTEGER default 0 not null, OrderDate DATETIME default CURRENT_TIMESTAMP not null, DueDate DATETIME not null, ShipDate DATETIME, Status INTEGER default 1 not null, OnlineOrderFlag INTEGER default 1 not null, SalesOrderNumber TEXT not null unique, PurchaseOrderNumber TEXT, AccountNumber TEXT, CustomerID INTEGER not null references Customer, SalesPersonID INTEGER references SalesPerson, TerritoryID INTEGER references SalesTerritory, BillToAddressID INTEGER not null references Address, ShipToAddressID INTEGER not null references Address, ShipMethodID INTEGER not null references Address, CreditCardID INTEGER references CreditCard, CreditCardApprovalCode TEXT, CurrencyRateID INTEGER references CurrencyRate, SubTotal REAL default 0.0000 not null, TaxAmt REAL default 0.0000 not null, Freight REAL default 0.0000 not null, TotalDue REAL not null, Comment TEXT, rowguid TEXT not null unique, ModifiedDate DATETIME default CURRENT_TIMESTAMP not null );
synthea
List out patient names with calcium deficiency.
patient names = first, last; calcium deficiency refers to observations.DESCRIPTION = 'Calcium' and observations.VALUE < 8.6;
SELECT DISTINCT T1.first, T1.last FROM patients AS T1 INNER JOIN observations AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'Calcium' AND T2.VALUE < 8.6
CREATE TABLE all_prevalences ( ITEM TEXT primary key, "POPULATION TYPE" TEXT, OCCURRENCES INTEGER, "POPULATION COUNT" INTEGER, "PREVALENCE RATE" REAL, "PREVALENCE PERCENTAGE" REAL ); CREATE TABLE patients ( patient TEXT primary key, birthdate DATE, deathdate DATE, ssn TEXT, drivers TEXT, passport TEXT, prefix TEXT, first TEXT, last TEXT, suffix TEXT, maiden TEXT, marital TEXT, race TEXT, ethnicity TEXT, gender TEXT, birthplace TEXT, address TEXT ); CREATE TABLE encounters ( ID TEXT primary key, DATE DATE, PATIENT TEXT, CODE INTEGER, DESCRIPTION TEXT, REASONCODE INTEGER, REASONDESCRIPTION TEXT, foreign key (PATIENT) references patients(patient) ); CREATE TABLE allergies ( START TEXT, STOP TEXT, PATIENT TEXT, ENCOUNTER TEXT, CODE INTEGER, DESCRIPTION TEXT, primary key (PATIENT, ENCOUNTER, CODE), foreign key (ENCOUNTER) references encounters(ID), foreign key (PATIENT) references patients(patient) ); CREATE TABLE careplans ( ID TEXT, START DATE, STOP DATE, PATIENT TEXT, ENCOUNTER TEXT, CODE REAL, DESCRIPTION TEXT, REASONCODE INTEGER, REASONDESCRIPTION TEXT, foreign key (ENCOUNTER) references encounters(ID), foreign key (PATIENT) references patients(patient) ); CREATE TABLE conditions ( START DATE, STOP DATE, PATIENT TEXT, ENCOUNTER TEXT, CODE INTEGER, DESCRIPTION TEXT, foreign key (ENCOUNTER) references encounters(ID), foreign key (PATIENT) references patients(patient), foreign key (DESCRIPTION) references all_prevalences(ITEM) ); CREATE TABLE immunizations ( DATE DATE, PATIENT TEXT, ENCOUNTER TEXT, CODE INTEGER, DESCRIPTION TEXT, primary key (DATE, PATIENT, ENCOUNTER, CODE), foreign key (ENCOUNTER) references encounters(ID), foreign key (PATIENT) references patients(patient) ); CREATE TABLE medications ( START DATE, STOP DATE, PATIENT TEXT, ENCOUNTER TEXT, CODE INTEGER, DESCRIPTION TEXT, REASONCODE INTEGER, REASONDESCRIPTION TEXT, primary key (START, PATIENT, ENCOUNTER, CODE), foreign key (ENCOUNTER) references encounters(ID), foreign key (PATIENT) references patients(patient) ); CREATE TABLE observations ( DATE DATE, PATIENT TEXT, ENCOUNTER TEXT, CODE TEXT, DESCRIPTION TEXT, VALUE REAL, UNITS TEXT, foreign key (ENCOUNTER) references encounters(ID), foreign key (PATIENT) references patients(patient) ); CREATE TABLE procedures ( DATE DATE, PATIENT TEXT, ENCOUNTER TEXT, CODE INTEGER, DESCRIPTION TEXT, REASONCODE INTEGER, REASONDESCRIPTION TEXT, foreign key (ENCOUNTER) references encounters(ID), foreign key (PATIENT) references patients(patient) ); CREATE TABLE IF NOT EXISTS "claims" ( ID TEXT primary key, PATIENT TEXT references patients, BILLABLEPERIOD DATE, ORGANIZATION TEXT, ENCOUNTER TEXT references encounters, DIAGNOSIS TEXT, TOTAL INTEGER );
retail_world
What is the name of the supplier company for Aniseed Syrup?
name of the supplier refers to CompanyName; Aniseed Syrup refers to ProductName = 'Aniseed Syrup';
SELECT T2.CompanyName FROM Products AS T1 INNER JOIN Suppliers AS T2 ON T1.SupplierID = T2.SupplierID WHERE T1.ProductName = 'Aniseed Syrup'
CREATE TABLE sqlite_sequence(name,seq); CREATE TABLE Categories ( CategoryID INTEGER PRIMARY KEY AUTOINCREMENT, CategoryName TEXT, Description TEXT ); CREATE TABLE Customers ( CustomerID INTEGER PRIMARY KEY AUTOINCREMENT, CustomerName TEXT, ContactName TEXT, Address TEXT, City TEXT, PostalCode TEXT, Country TEXT ); CREATE TABLE Employees ( EmployeeID INTEGER PRIMARY KEY AUTOINCREMENT, LastName TEXT, FirstName TEXT, BirthDate DATE, Photo TEXT, Notes TEXT ); CREATE TABLE Shippers( ShipperID INTEGER PRIMARY KEY AUTOINCREMENT, ShipperName TEXT, Phone TEXT ); CREATE TABLE Suppliers( SupplierID INTEGER PRIMARY KEY AUTOINCREMENT, SupplierName TEXT, ContactName TEXT, Address TEXT, City TEXT, PostalCode TEXT, Country TEXT, Phone TEXT ); CREATE TABLE Products( ProductID INTEGER PRIMARY KEY AUTOINCREMENT, ProductName TEXT, SupplierID INTEGER, CategoryID INTEGER, Unit TEXT, Price REAL DEFAULT 0, FOREIGN KEY (CategoryID) REFERENCES Categories (CategoryID), FOREIGN KEY (SupplierID) REFERENCES Suppliers (SupplierID) ); CREATE TABLE Orders( OrderID INTEGER PRIMARY KEY AUTOINCREMENT, CustomerID INTEGER, EmployeeID INTEGER, OrderDate DATETIME, ShipperID INTEGER, FOREIGN KEY (EmployeeID) REFERENCES Employees (EmployeeID), FOREIGN KEY (CustomerID) REFERENCES Customers (CustomerID), FOREIGN KEY (ShipperID) REFERENCES Shippers (ShipperID) ); CREATE TABLE OrderDetails( OrderDetailID INTEGER PRIMARY KEY AUTOINCREMENT, OrderID INTEGER, ProductID INTEGER, Quantity INTEGER, FOREIGN KEY (OrderID) REFERENCES Orders (OrderID), FOREIGN KEY (ProductID) REFERENCES Products (ProductID) );
movie_platform
How many followers does the list created by the user whose user_avatar_image_url is https://assets.mubicdn.net/images/avatars/74983/images-w150.jpg?1523895214 have?
followers refers to list_followers;
SELECT SUM(T2.list_followers) FROM lists_users AS T1 INNER JOIN lists AS T2 ON T1.list_id = T2.list_id WHERE T1.user_avatar_image_url = 'https://assets.mubicdn.net/images/avatars/74983/images-w150.jpg?1523895214'
CREATE TABLE IF NOT EXISTS "lists" ( user_id INTEGER references lists_users (user_id), list_id INTEGER not null primary key, list_title TEXT, list_movie_number INTEGER, list_update_timestamp_utc TEXT, list_creation_timestamp_utc TEXT, list_followers INTEGER, list_url TEXT, list_comments INTEGER, list_description TEXT, list_cover_image_url TEXT, list_first_image_url TEXT, list_second_image_url TEXT, list_third_image_url TEXT ); CREATE TABLE IF NOT EXISTS "movies" ( movie_id INTEGER not null primary key, movie_title TEXT, movie_release_year INTEGER, movie_url TEXT, movie_title_language TEXT, movie_popularity INTEGER, movie_image_url TEXT, director_id TEXT, director_name TEXT, director_url TEXT ); CREATE TABLE IF NOT EXISTS "ratings_users" ( user_id INTEGER references lists_users (user_id), rating_date_utc TEXT, user_trialist INTEGER, user_subscriber INTEGER, user_avatar_image_url TEXT, user_cover_image_url TEXT, user_eligible_for_trial INTEGER, user_has_payment_method INTEGER ); CREATE TABLE lists_users ( user_id INTEGER not null , list_id INTEGER not null , list_update_date_utc TEXT, list_creation_date_utc TEXT, user_trialist INTEGER, user_subscriber INTEGER, user_avatar_image_url TEXT, user_cover_image_url TEXT, user_eligible_for_trial TEXT, user_has_payment_method TEXT, primary key (user_id, list_id), foreign key (list_id) references lists(list_id), foreign key (user_id) references lists(user_id) ); CREATE TABLE ratings ( movie_id INTEGER, rating_id INTEGER, rating_url TEXT, rating_score INTEGER, rating_timestamp_utc TEXT, critic TEXT, critic_likes INTEGER, critic_comments INTEGER, user_id INTEGER, user_trialist INTEGER, user_subscriber INTEGER, user_eligible_for_trial INTEGER, user_has_payment_method INTEGER, foreign key (movie_id) references movies(movie_id), foreign key (user_id) references lists_users(user_id), foreign key (rating_id) references ratings(rating_id), foreign key (user_id) references ratings_users(user_id) );
public_review_platform
Please list the businesses name with a rating less than 5 whose category name is men's clothing.
businesses name refers to business_id; rating refers to stars; stars < 5;
SELECT T2.business_id FROM Categories AS T1 INNER JOIN Business_Categories AS T2 ON T1.category_id = T2.category_id INNER JOIN Business AS T3 ON T2.business_id = T3.business_id WHERE T1.category_name LIKE 'Men''s Clothing' AND T3.stars < 5
CREATE TABLE Attributes ( attribute_id INTEGER constraint Attributes_pk primary key, attribute_name TEXT ); CREATE TABLE Categories ( category_id INTEGER constraint Categories_pk primary key, category_name TEXT ); CREATE TABLE Compliments ( compliment_id INTEGER constraint Compliments_pk primary key, compliment_type TEXT ); CREATE TABLE Days ( day_id INTEGER constraint Days_pk primary key, day_of_week TEXT ); CREATE TABLE Years ( year_id INTEGER constraint Years_pk primary key, actual_year INTEGER ); CREATE TABLE IF NOT EXISTS "Business_Attributes" ( attribute_id INTEGER constraint Business_Attributes_Attributes_attribute_id_fk references Attributes, business_id INTEGER constraint Business_Attributes_Business_business_id_fk references Business, attribute_value TEXT, constraint Business_Attributes_pk primary key (attribute_id, business_id) ); CREATE TABLE IF NOT EXISTS "Business_Categories" ( business_id INTEGER constraint Business_Categories_Business_business_id_fk references Business, category_id INTEGER constraint Business_Categories_Categories_category_id_fk references Categories, constraint Business_Categories_pk primary key (business_id, category_id) ); CREATE TABLE IF NOT EXISTS "Business_Hours" ( business_id INTEGER constraint Business_Hours_Business_business_id_fk references Business, day_id INTEGER constraint Business_Hours_Days_day_id_fk references Days, opening_time TEXT, closing_time TEXT, constraint Business_Hours_pk primary key (business_id, day_id) ); CREATE TABLE IF NOT EXISTS "Checkins" ( business_id INTEGER constraint Checkins_Business_business_id_fk references Business, day_id INTEGER constraint Checkins_Days_day_id_fk references Days, label_time_0 TEXT, label_time_1 TEXT, label_time_2 TEXT, label_time_3 TEXT, label_time_4 TEXT, label_time_5 TEXT, label_time_6 TEXT, label_time_7 TEXT, label_time_8 TEXT, label_time_9 TEXT, label_time_10 TEXT, label_time_11 TEXT, label_time_12 TEXT, label_time_13 TEXT, label_time_14 TEXT, label_time_15 TEXT, label_time_16 TEXT, label_time_17 TEXT, label_time_18 TEXT, label_time_19 TEXT, label_time_20 TEXT, label_time_21 TEXT, label_time_22 TEXT, label_time_23 TEXT, constraint Checkins_pk primary key (business_id, day_id) ); CREATE TABLE IF NOT EXISTS "Elite" ( user_id INTEGER constraint Elite_Users_user_id_fk references Users, year_id INTEGER constraint Elite_Years_year_id_fk references Years, constraint Elite_pk primary key (user_id, year_id) ); CREATE TABLE IF NOT EXISTS "Reviews" ( business_id INTEGER constraint Reviews_Business_business_id_fk references Business, user_id INTEGER constraint Reviews_Users_user_id_fk references Users, review_stars INTEGER, review_votes_funny TEXT, review_votes_useful TEXT, review_votes_cool TEXT, review_length TEXT, constraint Reviews_pk primary key (business_id, user_id) ); CREATE TABLE IF NOT EXISTS "Tips" ( business_id INTEGER constraint Tips_Business_business_id_fk references Business, user_id INTEGER constraint Tips_Users_user_id_fk references Users, likes INTEGER, tip_length TEXT, constraint Tips_pk primary key (business_id, user_id) ); CREATE TABLE IF NOT EXISTS "Users_Compliments" ( compliment_id INTEGER constraint Users_Compliments_Compliments_compliment_id_fk references Compliments, user_id INTEGER constraint Users_Compliments_Users_user_id_fk references Users, number_of_compliments TEXT, constraint Users_Compliments_pk primary key (compliment_id, user_id) ); CREATE TABLE IF NOT EXISTS "Business" ( business_id INTEGER constraint Business_pk primary key, active TEXT, city TEXT, state TEXT, stars REAL, review_count TEXT ); CREATE TABLE IF NOT EXISTS "Users" ( user_id INTEGER constraint Users_pk primary key, user_yelping_since_year INTEGER, user_average_stars TEXT, user_votes_funny TEXT, user_votes_useful TEXT, user_votes_cool TEXT, user_review_count TEXT, user_fans TEXT );
cars
List the names and prices of the cars with model 82 and mileage per gallon of greater than 30.
car's name refers to car_name; model 82 refers to model = 82; mileage per gallon of greater than 30 refers to mpg > 30
SELECT T2.car_name, T1.price FROM price AS T1 INNER JOIN data AS T2 ON T1.ID = T2.ID WHERE T2.model = 82 AND T2.mpg > 30
CREATE TABLE country ( origin INTEGER primary key, country TEXT ); CREATE TABLE price ( ID INTEGER primary key, price REAL ); CREATE TABLE data ( ID INTEGER primary key, mpg REAL, cylinders INTEGER, displacement REAL, horsepower INTEGER, weight INTEGER, acceleration REAL, model INTEGER, car_name TEXT, foreign key (ID) references price(ID) ); CREATE TABLE production ( ID INTEGER, model_year INTEGER, country INTEGER, primary key (ID, model_year), foreign key (country) references country(origin), foreign key (ID) references data(ID), foreign key (ID) references price(ID) );
food_inspection
How many restaurants have met all requirements in the inspection?
met all requirements in the inspection refers to score = 100;
SELECT COUNT(score) FROM inspections WHERE score = 100
CREATE TABLE `businesses` ( `business_id` INTEGER NOT NULL, `name` TEXT NOT NULL, `address` TEXT DEFAULT NULL, `city` TEXT DEFAULT NULL, `postal_code` TEXT DEFAULT NULL, `latitude` REAL DEFAULT NULL, `longitude` REAL DEFAULT NULL, `phone_number` INTEGER DEFAULT NULL, `tax_code` TEXT DEFAULT NULL, `business_certificate` INTEGER NOT NULL, `application_date` DATE DEFAULT NULL, `owner_name` TEXT NOT NULL, `owner_address` TEXT DEFAULT NULL, `owner_city` TEXT DEFAULT NULL, `owner_state` TEXT DEFAULT NULL, `owner_zip` TEXT DEFAULT NULL, PRIMARY KEY (`business_id`) ); CREATE TABLE `inspections` ( `business_id` INTEGER NOT NULL, `score` INTEGER DEFAULT NULL, `date` DATE NOT NULL, `type` TEXT NOT NULL, FOREIGN KEY (`business_id`) REFERENCES `businesses` (`business_id`) ); CREATE TABLE `violations` ( `business_id` INTEGER NOT NULL, `date` DATE NOT NULL, `violation_type_id` TEXT NOT NULL, `risk_category` TEXT NOT NULL, `description` TEXT NOT NULL, FOREIGN KEY (`business_id`) REFERENCES `businesses` (`business_id`) );
university
Which country is the University of Oxford located?
University of Oxford refers to university_name = 'University of Oxford'; which country refers to country_name
SELECT T2.country_name FROM university AS T1 INNER JOIN country AS T2 ON T1.country_id = T2.id WHERE university_name = 'University of Oxford'
CREATE TABLE country ( id INTEGER not null primary key, country_name TEXT default NULL ); CREATE TABLE ranking_system ( id INTEGER not null primary key, system_name TEXT default NULL ); CREATE TABLE ranking_criteria ( id INTEGER not null primary key, ranking_system_id INTEGER default NULL, criteria_name TEXT default NULL, foreign key (ranking_system_id) references ranking_system(id) ); CREATE TABLE university ( id INTEGER not null primary key, country_id INTEGER default NULL, university_name TEXT default NULL, foreign key (country_id) references country(id) ); CREATE TABLE university_ranking_year ( university_id INTEGER default NULL, ranking_criteria_id INTEGER default NULL, year INTEGER default NULL, score INTEGER default NULL, foreign key (ranking_criteria_id) references ranking_criteria(id), foreign key (university_id) references university(id) ); CREATE TABLE university_year ( university_id INTEGER default NULL, year INTEGER default NULL, num_students INTEGER default NULL, student_staff_ratio REAL default NULL, pct_international_students INTEGER default NULL, pct_female_students INTEGER default NULL, foreign key (university_id) references university(id) );
books
How many customers ordered the oldest book?
oldest book refers to Min(publiation_date)
SELECT COUNT(*) FROM book AS T1 INNER JOIN order_line AS T2 ON T1.book_id = T2.book_id GROUP BY T1.publication_date ORDER BY T1.publication_date ASC LIMIT 1
CREATE TABLE address_status ( status_id INTEGER primary key, address_status TEXT ); CREATE TABLE author ( author_id INTEGER primary key, author_name TEXT ); CREATE TABLE book_language ( language_id INTEGER primary key, language_code TEXT, language_name TEXT ); CREATE TABLE country ( country_id INTEGER primary key, country_name TEXT ); CREATE TABLE address ( address_id INTEGER primary key, street_number TEXT, street_name TEXT, city TEXT, country_id INTEGER, foreign key (country_id) references country(country_id) ); CREATE TABLE customer ( customer_id INTEGER primary key, first_name TEXT, last_name TEXT, email TEXT ); CREATE TABLE customer_address ( customer_id INTEGER, address_id INTEGER, status_id INTEGER, primary key (customer_id, address_id), foreign key (address_id) references address(address_id), foreign key (customer_id) references customer(customer_id) ); CREATE TABLE order_status ( status_id INTEGER primary key, status_value TEXT ); CREATE TABLE publisher ( publisher_id INTEGER primary key, publisher_name TEXT ); CREATE TABLE book ( book_id INTEGER primary key, title TEXT, isbn13 TEXT, language_id INTEGER, num_pages INTEGER, publication_date DATE, publisher_id INTEGER, foreign key (language_id) references book_language(language_id), foreign key (publisher_id) references publisher(publisher_id) ); CREATE TABLE book_author ( book_id INTEGER, author_id INTEGER, primary key (book_id, author_id), foreign key (author_id) references author(author_id), foreign key (book_id) references book(book_id) ); CREATE TABLE shipping_method ( method_id INTEGER primary key, method_name TEXT, cost REAL ); CREATE TABLE IF NOT EXISTS "cust_order" ( order_id INTEGER primary key autoincrement, order_date DATETIME, customer_id INTEGER references customer, shipping_method_id INTEGER references shipping_method, dest_address_id INTEGER references address ); CREATE TABLE sqlite_sequence(name,seq); CREATE TABLE IF NOT EXISTS "order_history" ( history_id INTEGER primary key autoincrement, order_id INTEGER references cust_order, status_id INTEGER references order_status, status_date DATETIME ); CREATE TABLE IF NOT EXISTS "order_line" ( line_id INTEGER primary key autoincrement, order_id INTEGER references cust_order, book_id INTEGER references book, price REAL );
student_loan
Calculate the average duration of absense of female students.
average duration = DIVIDE(SUM(month), COUNT(longest_absence_from_school.name which are NOT in male.name)); female students refers to longest_absence_from_school.name who are NOT in male.name;
SELECT AVG(T2.month) FROM person AS T1 INNER JOIN longest_absense_from_school AS T2 ON T1.name = T2.name LEFT JOIN male AS T3 ON T1.name = T3.name WHERE T3.name IS NULL
CREATE TABLE bool ( "name" TEXT default '' not null primary key ); CREATE TABLE person ( "name" TEXT default '' not null primary key ); CREATE TABLE disabled ( "name" TEXT default '' not null primary key, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE enlist ( "name" TEXT not null, organ TEXT not null, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE filed_for_bankrupcy ( "name" TEXT default '' not null primary key, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE longest_absense_from_school ( "name" TEXT default '' not null primary key, "month" INTEGER default 0 null, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE male ( "name" TEXT default '' not null primary key, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE no_payment_due ( "name" TEXT default '' not null primary key, bool TEXT null, foreign key ("name") references person ("name") on update cascade on delete cascade, foreign key (bool) references bool ("name") on update cascade on delete cascade ); CREATE TABLE unemployed ( "name" TEXT default '' not null primary key, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE `enrolled` ( `name` TEXT NOT NULL, `school` TEXT NOT NULL, `month` INTEGER NOT NULL DEFAULT 0, PRIMARY KEY (`name`,`school`), FOREIGN KEY (`name`) REFERENCES `person` (`name`) ON DELETE CASCADE ON UPDATE CASCADE );
hockey
Which team got the most wins in the Stanley Cup finals?
team refers name; most wins = MAX(W);
SELECT T2.name FROM TeamsSC AS T1 INNER JOIN Teams AS T2 ON T1.tmID = T2.tmID AND T1.year = T2.year GROUP BY T2.name ORDER BY SUM(T1.W) DESC LIMIT 1
CREATE TABLE AwardsMisc ( name TEXT not null primary key, ID TEXT, award TEXT, year INTEGER, lgID TEXT, note TEXT ); CREATE TABLE HOF ( year INTEGER, hofID TEXT not null primary key, name TEXT, category TEXT ); CREATE TABLE Teams ( year INTEGER not null, lgID TEXT, tmID TEXT not null, franchID TEXT, confID TEXT, divID TEXT, rank INTEGER, playoff TEXT, G INTEGER, W INTEGER, L INTEGER, T INTEGER, OTL TEXT, Pts INTEGER, SoW TEXT, SoL TEXT, GF INTEGER, GA INTEGER, name TEXT, PIM TEXT, BenchMinor TEXT, PPG TEXT, PPC TEXT, SHA TEXT, PKG TEXT, PKC TEXT, SHF TEXT, primary key (year, tmID) ); CREATE TABLE Coaches ( coachID TEXT not null, year INTEGER not null, tmID TEXT not null, lgID TEXT, stint INTEGER not null, notes TEXT, g INTEGER, w INTEGER, l INTEGER, t INTEGER, postg TEXT, postw TEXT, postl TEXT, postt TEXT, primary key (coachID, year, tmID, stint), foreign key (year, tmID) references Teams (year, tmID) on update cascade on delete cascade ); CREATE TABLE AwardsCoaches ( coachID TEXT, award TEXT, year INTEGER, lgID TEXT, note TEXT, foreign key (coachID) references Coaches (coachID) ); CREATE TABLE Master ( playerID TEXT, coachID TEXT, hofID TEXT, firstName TEXT, lastName TEXT not null, nameNote TEXT, nameGiven TEXT, nameNick TEXT, height TEXT, weight TEXT, shootCatch TEXT, legendsID TEXT, ihdbID TEXT, hrefID TEXT, firstNHL TEXT, lastNHL TEXT, firstWHA TEXT, lastWHA TEXT, pos TEXT, birthYear TEXT, birthMon TEXT, birthDay TEXT, birthCountry TEXT, birthState TEXT, birthCity TEXT, deathYear TEXT, deathMon TEXT, deathDay TEXT, deathCountry TEXT, deathState TEXT, deathCity TEXT, foreign key (coachID) references Coaches (coachID) on update cascade on delete cascade ); CREATE TABLE AwardsPlayers ( playerID TEXT not null, award TEXT not null, year INTEGER not null, lgID TEXT, note TEXT, pos TEXT, primary key (playerID, award, year), foreign key (playerID) references Master (playerID) on update cascade on delete cascade ); CREATE TABLE CombinedShutouts ( year INTEGER, month INTEGER, date INTEGER, tmID TEXT, oppID TEXT, "R/P" TEXT, IDgoalie1 TEXT, IDgoalie2 TEXT, foreign key (IDgoalie1) references Master (playerID) on update cascade on delete cascade, foreign key (IDgoalie2) references Master (playerID) on update cascade on delete cascade ); CREATE TABLE Goalies ( playerID TEXT not null, year INTEGER not null, stint INTEGER not null, tmID TEXT, lgID TEXT, GP TEXT, Min TEXT, W TEXT, L TEXT, "T/OL" TEXT, ENG TEXT, SHO TEXT, GA TEXT, SA TEXT, PostGP TEXT, PostMin TEXT, PostW TEXT, PostL TEXT, PostT TEXT, PostENG TEXT, PostSHO TEXT, PostGA TEXT, PostSA TEXT, primary key (playerID, year, stint), foreign key (year, tmID) references Teams (year, tmID) on update cascade on delete cascade, foreign key (playerID) references Master (playerID) on update cascade on delete cascade ); CREATE TABLE GoaliesSC ( playerID TEXT not null, year INTEGER not null, tmID TEXT, lgID TEXT, GP INTEGER, Min INTEGER, W INTEGER, L INTEGER, T INTEGER, SHO INTEGER, GA INTEGER, primary key (playerID, year), foreign key (year, tmID) references Teams (year, tmID) on update cascade on delete cascade, foreign key (playerID) references Master (playerID) on update cascade on delete cascade ); CREATE TABLE GoaliesShootout ( playerID TEXT, year INTEGER, stint INTEGER, tmID TEXT, W INTEGER, L INTEGER, SA INTEGER, GA INTEGER, foreign key (year, tmID) references Teams (year, tmID) on update cascade on delete cascade, foreign key (playerID) references Master (playerID) on update cascade on delete cascade ); CREATE TABLE Scoring ( playerID TEXT, year INTEGER, stint INTEGER, tmID TEXT, lgID TEXT, pos TEXT, GP INTEGER, G INTEGER, A INTEGER, Pts INTEGER, PIM INTEGER, "+/-" TEXT, PPG TEXT, PPA TEXT, SHG TEXT, SHA TEXT, GWG TEXT, GTG TEXT, SOG TEXT, PostGP TEXT, PostG TEXT, PostA TEXT, PostPts TEXT, PostPIM TEXT, "Post+/-" TEXT, PostPPG TEXT, PostPPA TEXT, PostSHG TEXT, PostSHA TEXT, PostGWG TEXT, PostSOG TEXT, foreign key (year, tmID) references Teams (year, tmID) on update cascade on delete cascade, foreign key (playerID) references Master (playerID) on update cascade on delete cascade ); CREATE TABLE ScoringSC ( playerID TEXT, year INTEGER, tmID TEXT, lgID TEXT, pos TEXT, GP INTEGER, G INTEGER, A INTEGER, Pts INTEGER, PIM INTEGER, foreign key (year, tmID) references Teams (year, tmID) on update cascade on delete cascade, foreign key (playerID) references Master (playerID) on update cascade on delete cascade ); CREATE TABLE ScoringShootout ( playerID TEXT, year INTEGER, stint INTEGER, tmID TEXT, S INTEGER, G INTEGER, GDG INTEGER, foreign key (year, tmID) references Teams (year, tmID) on update cascade on delete cascade, foreign key (playerID) references Master (playerID) on update cascade on delete cascade ); CREATE TABLE ScoringSup ( playerID TEXT, year INTEGER, PPA TEXT, SHA TEXT, foreign key (playerID) references Master (playerID) on update cascade on delete cascade ); CREATE TABLE SeriesPost ( year INTEGER, round TEXT, series TEXT, tmIDWinner TEXT, lgIDWinner TEXT, tmIDLoser TEXT, lgIDLoser TEXT, W INTEGER, L INTEGER, T INTEGER, GoalsWinner INTEGER, GoalsLoser INTEGER, note TEXT, foreign key (year, tmIDWinner) references Teams (year, tmID) on update cascade on delete cascade, foreign key (year, tmIDLoser) references Teams (year, tmID) on update cascade on delete cascade ); CREATE TABLE TeamSplits ( year INTEGER not null, lgID TEXT, tmID TEXT not null, hW INTEGER, hL INTEGER, hT INTEGER, hOTL TEXT, rW INTEGER, rL INTEGER, rT INTEGER, rOTL TEXT, SepW TEXT, SepL TEXT, SepT TEXT, SepOL TEXT, OctW TEXT, OctL TEXT, OctT TEXT, OctOL TEXT, NovW TEXT, NovL TEXT, NovT TEXT, NovOL TEXT, DecW TEXT, DecL TEXT, DecT TEXT, DecOL TEXT, JanW INTEGER, JanL INTEGER, JanT INTEGER, JanOL TEXT, FebW INTEGER, FebL INTEGER, FebT INTEGER, FebOL TEXT, MarW TEXT, MarL TEXT, MarT TEXT, MarOL TEXT, AprW TEXT, AprL TEXT, AprT TEXT, AprOL TEXT, primary key (year, tmID), foreign key (year, tmID) references Teams (year, tmID) on update cascade on delete cascade ); CREATE TABLE TeamVsTeam ( year INTEGER not null, lgID TEXT, tmID TEXT not null, oppID TEXT not null, W INTEGER, L INTEGER, T INTEGER, OTL TEXT, primary key (year, tmID, oppID), foreign key (year, tmID) references Teams (year, tmID) on update cascade on delete cascade, foreign key (oppID, year) references Teams (tmID, year) on update cascade on delete cascade ); CREATE TABLE TeamsHalf ( year INTEGER not null, lgID TEXT, tmID TEXT not null, half INTEGER not null, rank INTEGER, G INTEGER, W INTEGER, L INTEGER, T INTEGER, GF INTEGER, GA INTEGER, primary key (year, tmID, half), foreign key (tmID, year) references Teams (tmID, year) on update cascade on delete cascade ); CREATE TABLE TeamsPost ( year INTEGER not null, lgID TEXT, tmID TEXT not null, G INTEGER, W INTEGER, L INTEGER, T INTEGER, GF INTEGER, GA INTEGER, PIM TEXT, BenchMinor TEXT, PPG TEXT, PPC TEXT, SHA TEXT, PKG TEXT, PKC TEXT, SHF TEXT, primary key (year, tmID), foreign key (year, tmID) references Teams (year, tmID) on update cascade on delete cascade ); CREATE TABLE TeamsSC ( year INTEGER not null, lgID TEXT, tmID TEXT not null, G INTEGER, W INTEGER, L INTEGER, T INTEGER, GF INTEGER, GA INTEGER, PIM TEXT, primary key (year, tmID), foreign key (year, tmID) references Teams (year, tmID) on update cascade on delete cascade ); CREATE TABLE abbrev ( Type TEXT not null, Code TEXT not null, Fullname TEXT, primary key (Type, Code) );
simpson_episodes
How many award winners are from the USA?
award winner refers to result = 'Winner'; 'USA' is the birth_country
SELECT COUNT(*) FROM Person AS T1 INNER JOIN Award AS T2 ON T1.name = T2.person WHERE T1.birth_country = 'USA' AND T2.result = 'Winner';
CREATE TABLE IF NOT EXISTS "Episode" ( episode_id TEXT constraint Episode_pk primary key, season INTEGER, episode INTEGER, number_in_series INTEGER, title TEXT, summary TEXT, air_date TEXT, episode_image TEXT, rating REAL, votes INTEGER ); CREATE TABLE Person ( name TEXT constraint Person_pk primary key, birthdate TEXT, birth_name TEXT, birth_place TEXT, birth_region TEXT, birth_country TEXT, height_meters REAL, nickname TEXT ); CREATE TABLE Award ( award_id INTEGER primary key, organization TEXT, year INTEGER, award_category TEXT, award TEXT, person TEXT, role TEXT, episode_id TEXT, season TEXT, song TEXT, result TEXT, foreign key (person) references Person(name), foreign key (episode_id) references Episode(episode_id) ); CREATE TABLE Character_Award ( award_id INTEGER, character TEXT, foreign key (award_id) references Award(award_id) ); CREATE TABLE Credit ( episode_id TEXT, category TEXT, person TEXT, role TEXT, credited TEXT, foreign key (episode_id) references Episode(episode_id), foreign key (person) references Person(name) ); CREATE TABLE Keyword ( episode_id TEXT, keyword TEXT, primary key (episode_id, keyword), foreign key (episode_id) references Episode(episode_id) ); CREATE TABLE Vote ( episode_id TEXT, stars INTEGER, votes INTEGER, percent REAL, foreign key (episode_id) references Episode(episode_id) );
language_corpus
How many times of repetition does the word "exemple" show in the Catalan language?
exemple refers to word = 'exemple'; repetition refers to langs_words.occurrences; lid = 1 menas it's Catalan language
SELECT T2.occurrences FROM words AS T1 INNER JOIN langs_words AS T2 ON T1.wid = T2.wid WHERE T1.word = 'exemple' AND T2.lid = 1
CREATE TABLE langs(lid INTEGER PRIMARY KEY AUTOINCREMENT, lang TEXT UNIQUE, locale TEXT UNIQUE, pages INTEGER DEFAULT 0, -- total pages in this language words INTEGER DEFAULT 0); CREATE TABLE sqlite_sequence(name,seq); CREATE TABLE pages(pid INTEGER PRIMARY KEY AUTOINCREMENT, lid INTEGER REFERENCES langs(lid) ON UPDATE CASCADE ON DELETE CASCADE, page INTEGER DEFAULT NULL, -- wikipedia page id revision INTEGER DEFAULT NULL, -- wikipedia revision page id title TEXT, words INTEGER DEFAULT 0, -- number of different words in this page UNIQUE(lid,page,title)); CREATE TRIGGER ins_page AFTER INSERT ON pages FOR EACH ROW BEGIN UPDATE langs SET pages=pages+1 WHERE lid=NEW.lid; END; CREATE TRIGGER del_page AFTER DELETE ON pages FOR EACH ROW BEGIN UPDATE langs SET pages=pages-1 WHERE lid=OLD.lid; END; CREATE TABLE words(wid INTEGER PRIMARY KEY AUTOINCREMENT, word TEXT UNIQUE, occurrences INTEGER DEFAULT 0); CREATE TABLE langs_words(lid INTEGER REFERENCES langs(lid) ON UPDATE CASCADE ON DELETE CASCADE, wid INTEGER REFERENCES words(wid) ON UPDATE CASCADE ON DELETE CASCADE, occurrences INTEGER, -- repetitions of this word in this language PRIMARY KEY(lid,wid)) WITHOUT ROWID; CREATE TRIGGER ins_lang_word AFTER INSERT ON langs_words FOR EACH ROW BEGIN UPDATE langs SET words=words+1 WHERE lid=NEW.lid; END; CREATE TRIGGER del_lang_word AFTER DELETE ON langs_words FOR EACH ROW BEGIN UPDATE langs SET words=words-1 WHERE lid=OLD.lid; END; CREATE TABLE pages_words(pid INTEGER REFERENCES pages(pid) ON UPDATE CASCADE ON DELETE CASCADE, wid INTEGER REFERENCES words(wid) ON UPDATE CASCADE ON DELETE CASCADE, occurrences INTEGER DEFAULT 0, -- times this word appears into this page PRIMARY KEY(pid,wid)) WITHOUT ROWID; CREATE TRIGGER ins_page_word AFTER INSERT ON pages_words FOR EACH ROW BEGIN UPDATE pages SET words=words+1 WHERE pid=NEW.pid; END; CREATE TRIGGER del_page_word AFTER DELETE ON pages_words FOR EACH ROW BEGIN UPDATE pages SET words=words-1 WHERE pid=OLD.pid; END; CREATE TABLE biwords(lid INTEGER REFERENCES langs(lid) ON UPDATE CASCADE ON DELETE CASCADE, w1st INTEGER REFERENCES words(wid) ON UPDATE CASCADE ON DELETE CASCADE, w2nd INTEGER REFERENCES words(wid) ON UPDATE CASCADE ON DELETE CASCADE, occurrences INTEGER DEFAULT 0, -- times this pair appears in this language/page PRIMARY KEY(lid,w1st,w2nd)) WITHOUT ROWID;
regional_sales
Please indicate total order quantity of product Candles and calculate the percentage of such product among all the orders.
total order quantity refers to Sum (Order Quantity); 'Candles' is the Products Name; percentage = Divide (Sum(Order Quantity where Product Name = 'Candles'), Sum(Order Quantity)) * 100
SELECT SUM(CASE WHEN T1.`Product Name` = 'Candles' THEN T2.`Order Quantity` ELSE 0 END), CAST(SUM(CASE WHEN T1.`Product Name` = 'Candles' THEN T2.`Order Quantity` ELSE 0 END) AS REAL) * 100 / SUM(T2.`Order Quantity`) FROM Products AS T1 INNER JOIN `Sales Orders` AS T2 ON T2._ProductID = T1.ProductID INNER JOIN `Store Locations` AS T3 ON T3.StoreID = T2._StoreID
CREATE TABLE Customers ( CustomerID INTEGER constraint Customers_pk primary key, "Customer Names" TEXT ); CREATE TABLE Products ( ProductID INTEGER constraint Products_pk primary key, "Product Name" TEXT ); CREATE TABLE Regions ( StateCode TEXT constraint Regions_pk primary key, State TEXT, Region TEXT ); CREATE TABLE IF NOT EXISTS "Sales Team" ( SalesTeamID INTEGER constraint "Sales Team_pk" primary key, "Sales Team" TEXT, Region TEXT ); CREATE TABLE IF NOT EXISTS "Store Locations" ( StoreID INTEGER constraint "Store Locations_pk" primary key, "City Name" TEXT, County TEXT, StateCode TEXT constraint "Store Locations_Regions_StateCode_fk" references Regions(StateCode), State TEXT, Type TEXT, Latitude REAL, Longitude REAL, AreaCode INTEGER, Population INTEGER, "Household Income" INTEGER, "Median Income" INTEGER, "Land Area" INTEGER, "Water Area" INTEGER, "Time Zone" TEXT ); CREATE TABLE IF NOT EXISTS "Sales Orders" ( OrderNumber TEXT constraint "Sales Orders_pk" primary key, "Sales Channel" TEXT, WarehouseCode TEXT, ProcuredDate TEXT, OrderDate TEXT, ShipDate TEXT, DeliveryDate TEXT, CurrencyCode TEXT, _SalesTeamID INTEGER constraint "Sales Orders_Sales Team_SalesTeamID_fk" references "Sales Team"(SalesTeamID), _CustomerID INTEGER constraint "Sales Orders_Customers_CustomerID_fk" references Customers(CustomerID), _StoreID INTEGER constraint "Sales Orders_Store Locations_StoreID_fk" references "Store Locations"(StoreID), _ProductID INTEGER constraint "Sales Orders_Products_ProductID_fk" references Products(ProductID), "Order Quantity" INTEGER, "Discount Applied" REAL, "Unit Price" TEXT, "Unit Cost" TEXT );
student_loan
Which organization did student285 enlist?
SELECT organ FROM enlist WHERE name = 'student285'
CREATE TABLE bool ( "name" TEXT default '' not null primary key ); CREATE TABLE person ( "name" TEXT default '' not null primary key ); CREATE TABLE disabled ( "name" TEXT default '' not null primary key, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE enlist ( "name" TEXT not null, organ TEXT not null, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE filed_for_bankrupcy ( "name" TEXT default '' not null primary key, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE longest_absense_from_school ( "name" TEXT default '' not null primary key, "month" INTEGER default 0 null, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE male ( "name" TEXT default '' not null primary key, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE no_payment_due ( "name" TEXT default '' not null primary key, bool TEXT null, foreign key ("name") references person ("name") on update cascade on delete cascade, foreign key (bool) references bool ("name") on update cascade on delete cascade ); CREATE TABLE unemployed ( "name" TEXT default '' not null primary key, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE `enrolled` ( `name` TEXT NOT NULL, `school` TEXT NOT NULL, `month` INTEGER NOT NULL DEFAULT 0, PRIMARY KEY (`name`,`school`), FOREIGN KEY (`name`) REFERENCES `person` (`name`) ON DELETE CASCADE ON UPDATE CASCADE );
donor
Who is the vendor of the resources needed by the project that had the highest cost of optional tip?
Highest cost of the optional tip refers to Max(total_price_including_optional_support - total_price_excluding_optional_support);
SELECT T1.vendor_name FROM resources AS T1 INNER JOIN projects AS T2 ON T1.projectid = T2.projectid ORDER BY T2.total_price_including_optional_support - T2.total_price_including_optional_support DESC LIMIT 1
CREATE TABLE sqlite_sequence(name,seq); CREATE TABLE IF NOT EXISTS "essays" ( projectid TEXT, teacher_acctid TEXT, title TEXT, short_description TEXT, need_statement TEXT, essay TEXT ); CREATE TABLE IF NOT EXISTS "projects" ( projectid TEXT not null primary key, teacher_acctid TEXT, schoolid TEXT, school_ncesid TEXT, school_latitude REAL, school_longitude REAL, school_city TEXT, school_state TEXT, school_zip INTEGER, school_metro TEXT, school_district TEXT, school_county TEXT, school_charter TEXT, school_magnet TEXT, school_year_round TEXT, school_nlns TEXT, school_kipp TEXT, school_charter_ready_promise TEXT, teacher_prefix TEXT, teacher_teach_for_america TEXT, teacher_ny_teaching_fellow TEXT, primary_focus_subject TEXT, primary_focus_area TEXT, secondary_focus_subject TEXT, secondary_focus_area TEXT, resource_type TEXT, poverty_level TEXT, grade_level TEXT, fulfillment_labor_materials REAL, total_price_excluding_optional_support REAL, total_price_including_optional_support REAL, students_reached INTEGER, eligible_double_your_impact_match TEXT, eligible_almost_home_match TEXT, date_posted DATE ); CREATE TABLE donations ( donationid TEXT not null primary key, projectid TEXT, donor_acctid TEXT, donor_city TEXT, donor_state TEXT, donor_zip TEXT, is_teacher_acct TEXT, donation_timestamp DATETIME, donation_to_project REAL, donation_optional_support REAL, donation_total REAL, dollar_amount TEXT, donation_included_optional_support TEXT, payment_method TEXT, payment_included_acct_credit TEXT, payment_included_campaign_gift_card TEXT, payment_included_web_purchased_gift_card TEXT, payment_was_promo_matched TEXT, via_giving_page TEXT, for_honoree TEXT, donation_message TEXT, foreign key (projectid) references projects(projectid) ); CREATE TABLE resources ( resourceid TEXT not null primary key, projectid TEXT, vendorid INTEGER, vendor_name TEXT, project_resource_type TEXT, item_name TEXT, item_number TEXT, item_unit_price REAL, item_quantity INTEGER, foreign key (projectid) references projects(projectid) );
car_retails
How many countries from the USA have an In Process order status?
country = 'USA'
SELECT COUNT(t2.orderNumber) FROM customers AS t1 INNER JOIN orders AS t2 ON t1.customerNumber = t2.customerNumber WHERE t2.status = 'On Hold' AND t1.country = 'USA'
CREATE TABLE offices ( officeCode TEXT not null primary key, city TEXT not null, phone TEXT not null, addressLine1 TEXT not null, addressLine2 TEXT, state TEXT, country TEXT not null, postalCode TEXT not null, territory TEXT not null ); CREATE TABLE employees ( employeeNumber INTEGER not null primary key, lastName TEXT not null, firstName TEXT not null, extension TEXT not null, email TEXT not null, officeCode TEXT not null, reportsTo INTEGER, jobTitle TEXT not null, foreign key (officeCode) references offices(officeCode), foreign key (reportsTo) references employees(employeeNumber) ); CREATE TABLE customers ( customerNumber INTEGER not null primary key, customerName TEXT not null, contactLastName TEXT not null, contactFirstName TEXT not null, phone TEXT not null, addressLine1 TEXT not null, addressLine2 TEXT, city TEXT not null, state TEXT, postalCode TEXT, country TEXT not null, salesRepEmployeeNumber INTEGER, creditLimit REAL, foreign key (salesRepEmployeeNumber) references employees(employeeNumber) ); CREATE TABLE orders ( orderNumber INTEGER not null primary key, orderDate DATE not null, requiredDate DATE not null, shippedDate DATE, status TEXT not null, comments TEXT, customerNumber INTEGER not null, foreign key (customerNumber) references customers(customerNumber) ); CREATE TABLE payments ( customerNumber INTEGER not null, checkNumber TEXT not null, paymentDate DATE not null, amount REAL not null, primary key (customerNumber, checkNumber), foreign key (customerNumber) references customers(customerNumber) ); CREATE TABLE productlines ( productLine TEXT not null primary key, textDescription TEXT, htmlDescription TEXT, image BLOB ); CREATE TABLE products ( productCode TEXT not null primary key, productName TEXT not null, productLine TEXT not null, productScale TEXT not null, productVendor TEXT not null, productDescription TEXT not null, quantityInStock INTEGER not null, buyPrice REAL not null, MSRP REAL not null, foreign key (productLine) references productlines(productLine) ); CREATE TABLE IF NOT EXISTS "orderdetails" ( orderNumber INTEGER not null references orders, productCode TEXT not null references products, quantityOrdered INTEGER not null, priceEach REAL not null, orderLineNumber INTEGER not null, primary key (orderNumber, productCode) );
retail_world
Who is in charge of the "Santa Monica" territory? Give the full name.
Santa Monica refers to TerritoryDescription = 'Santa Monica'; full name = FirstName, MiddleName, LastName;
SELECT T1.FirstName, T1.LastName FROM Employees AS T1 INNER JOIN EmployeeTerritories AS T2 ON T1.EmployeeID = T2.EmployeeID INNER JOIN Territories AS T3 ON T2.TerritoryID = T3.TerritoryID WHERE T3.TerritoryDescription = 'Santa Monica'
CREATE TABLE sqlite_sequence(name,seq); CREATE TABLE Categories ( CategoryID INTEGER PRIMARY KEY AUTOINCREMENT, CategoryName TEXT, Description TEXT ); CREATE TABLE Customers ( CustomerID INTEGER PRIMARY KEY AUTOINCREMENT, CustomerName TEXT, ContactName TEXT, Address TEXT, City TEXT, PostalCode TEXT, Country TEXT ); CREATE TABLE Employees ( EmployeeID INTEGER PRIMARY KEY AUTOINCREMENT, LastName TEXT, FirstName TEXT, BirthDate DATE, Photo TEXT, Notes TEXT ); CREATE TABLE Shippers( ShipperID INTEGER PRIMARY KEY AUTOINCREMENT, ShipperName TEXT, Phone TEXT ); CREATE TABLE Suppliers( SupplierID INTEGER PRIMARY KEY AUTOINCREMENT, SupplierName TEXT, ContactName TEXT, Address TEXT, City TEXT, PostalCode TEXT, Country TEXT, Phone TEXT ); CREATE TABLE Products( ProductID INTEGER PRIMARY KEY AUTOINCREMENT, ProductName TEXT, SupplierID INTEGER, CategoryID INTEGER, Unit TEXT, Price REAL DEFAULT 0, FOREIGN KEY (CategoryID) REFERENCES Categories (CategoryID), FOREIGN KEY (SupplierID) REFERENCES Suppliers (SupplierID) ); CREATE TABLE Orders( OrderID INTEGER PRIMARY KEY AUTOINCREMENT, CustomerID INTEGER, EmployeeID INTEGER, OrderDate DATETIME, ShipperID INTEGER, FOREIGN KEY (EmployeeID) REFERENCES Employees (EmployeeID), FOREIGN KEY (CustomerID) REFERENCES Customers (CustomerID), FOREIGN KEY (ShipperID) REFERENCES Shippers (ShipperID) ); CREATE TABLE OrderDetails( OrderDetailID INTEGER PRIMARY KEY AUTOINCREMENT, OrderID INTEGER, ProductID INTEGER, Quantity INTEGER, FOREIGN KEY (OrderID) REFERENCES Orders (OrderID), FOREIGN KEY (ProductID) REFERENCES Products (ProductID) );
movie_platform
What is the average popularity of each movie that was directed by Christopher Nolan? Indicate which movie directed by him has received the highest number of 5 rating scores.
5 rating scores refer to rating_score; Christopher Nolan refer to director_name; average popularity of each movie refer to AVG(movie_popularity where director_name = 'Christopher Nolan')
SELECT AVG(T2.movie_popularity) FROM ratings AS T1 INNER JOIN movies AS T2 ON T1.movie_id = T2.movie_id WHERE T2.director_name = 'Christopher Nolan'
CREATE TABLE IF NOT EXISTS "lists" ( user_id INTEGER references lists_users (user_id), list_id INTEGER not null primary key, list_title TEXT, list_movie_number INTEGER, list_update_timestamp_utc TEXT, list_creation_timestamp_utc TEXT, list_followers INTEGER, list_url TEXT, list_comments INTEGER, list_description TEXT, list_cover_image_url TEXT, list_first_image_url TEXT, list_second_image_url TEXT, list_third_image_url TEXT ); CREATE TABLE IF NOT EXISTS "movies" ( movie_id INTEGER not null primary key, movie_title TEXT, movie_release_year INTEGER, movie_url TEXT, movie_title_language TEXT, movie_popularity INTEGER, movie_image_url TEXT, director_id TEXT, director_name TEXT, director_url TEXT ); CREATE TABLE IF NOT EXISTS "ratings_users" ( user_id INTEGER references lists_users (user_id), rating_date_utc TEXT, user_trialist INTEGER, user_subscriber INTEGER, user_avatar_image_url TEXT, user_cover_image_url TEXT, user_eligible_for_trial INTEGER, user_has_payment_method INTEGER ); CREATE TABLE lists_users ( user_id INTEGER not null , list_id INTEGER not null , list_update_date_utc TEXT, list_creation_date_utc TEXT, user_trialist INTEGER, user_subscriber INTEGER, user_avatar_image_url TEXT, user_cover_image_url TEXT, user_eligible_for_trial TEXT, user_has_payment_method TEXT, primary key (user_id, list_id), foreign key (list_id) references lists(list_id), foreign key (user_id) references lists(user_id) ); CREATE TABLE ratings ( movie_id INTEGER, rating_id INTEGER, rating_url TEXT, rating_score INTEGER, rating_timestamp_utc TEXT, critic TEXT, critic_likes INTEGER, critic_comments INTEGER, user_id INTEGER, user_trialist INTEGER, user_subscriber INTEGER, user_eligible_for_trial INTEGER, user_has_payment_method INTEGER, foreign key (movie_id) references movies(movie_id), foreign key (user_id) references lists_users(user_id), foreign key (rating_id) references ratings(rating_id), foreign key (user_id) references ratings_users(user_id) );
disney
How many restricted horror movies were released between 1/1/1990 to 12/31/2015?
Restricted refers to MPAA_rating = 'R'; horror refers to genre = 'Horror'; released between 1/1/1990 to 12/31/2015 refers to (cast(SUBSTR(release_date, instr(release_date, ', ') + 1) as int) between 1990 and 2015);
SELECT COUNT(movie_title) FROM movies_total_gross WHERE MPAA_rating = 'R' AND genre = 'Horror' AND CAST(SUBSTR(release_date, INSTR(release_date, ', ') + 1) AS int) BETWEEN 1990 AND 2015
CREATE TABLE characters ( movie_title TEXT primary key, release_date TEXT, hero TEXT, villian TEXT, song TEXT, foreign key (hero) references "voice-actors"(character) ); CREATE TABLE director ( name TEXT primary key, director TEXT, foreign key (name) references characters(movie_title) ); CREATE TABLE movies_total_gross ( movie_title TEXT, release_date TEXT, genre TEXT, MPAA_rating TEXT, total_gross TEXT, inflation_adjusted_gross TEXT, primary key (movie_title, release_date), foreign key (movie_title) references characters(movie_title) ); CREATE TABLE revenue ( Year INTEGER primary key, "Studio Entertainment[NI 1]" REAL, "Disney Consumer Products[NI 2]" REAL, "Disney Interactive[NI 3][Rev 1]" INTEGER, "Walt Disney Parks and Resorts" REAL, "Disney Media Networks" TEXT, Total INTEGER ); CREATE TABLE IF NOT EXISTS "voice-actors" ( character TEXT primary key, "voice-actor" TEXT, movie TEXT, foreign key (movie) references characters(movie_title) );
hockey
Please list the positions of the players who were born in Canada and have won the All-Rookie award.
born in Canada refers to birthCountry = 'Canada'; pos = 'LW' refers to left winger; pos = 'RW' refers to right winger; pos = 'C' refers to center; pos = 'G' refers to goalie; pos = 'D' refers to defenceman; pos = 'W' refers to winger; pos = 'F' refers to forward
SELECT DISTINCT T1.pos FROM Master AS T1 INNER JOIN AwardsPlayers AS T2 ON T1.playerID = T2.playerID WHERE T1.birthCountry = 'Canada' AND T2.award = 'All-Rookie'
CREATE TABLE AwardsMisc ( name TEXT not null primary key, ID TEXT, award TEXT, year INTEGER, lgID TEXT, note TEXT ); CREATE TABLE HOF ( year INTEGER, hofID TEXT not null primary key, name TEXT, category TEXT ); CREATE TABLE Teams ( year INTEGER not null, lgID TEXT, tmID TEXT not null, franchID TEXT, confID TEXT, divID TEXT, rank INTEGER, playoff TEXT, G INTEGER, W INTEGER, L INTEGER, T INTEGER, OTL TEXT, Pts INTEGER, SoW TEXT, SoL TEXT, GF INTEGER, GA INTEGER, name TEXT, PIM TEXT, BenchMinor TEXT, PPG TEXT, PPC TEXT, SHA TEXT, PKG TEXT, PKC TEXT, SHF TEXT, primary key (year, tmID) ); CREATE TABLE Coaches ( coachID TEXT not null, year INTEGER not null, tmID TEXT not null, lgID TEXT, stint INTEGER not null, notes TEXT, g INTEGER, w INTEGER, l INTEGER, t INTEGER, postg TEXT, postw TEXT, postl TEXT, postt TEXT, primary key (coachID, year, tmID, stint), foreign key (year, tmID) references Teams (year, tmID) on update cascade on delete cascade ); CREATE TABLE AwardsCoaches ( coachID TEXT, award TEXT, year INTEGER, lgID TEXT, note TEXT, foreign key (coachID) references Coaches (coachID) ); CREATE TABLE Master ( playerID TEXT, coachID TEXT, hofID TEXT, firstName TEXT, lastName TEXT not null, nameNote TEXT, nameGiven TEXT, nameNick TEXT, height TEXT, weight TEXT, shootCatch TEXT, legendsID TEXT, ihdbID TEXT, hrefID TEXT, firstNHL TEXT, lastNHL TEXT, firstWHA TEXT, lastWHA TEXT, pos TEXT, birthYear TEXT, birthMon TEXT, birthDay TEXT, birthCountry TEXT, birthState TEXT, birthCity TEXT, deathYear TEXT, deathMon TEXT, deathDay TEXT, deathCountry TEXT, deathState TEXT, deathCity TEXT, foreign key (coachID) references Coaches (coachID) on update cascade on delete cascade ); CREATE TABLE AwardsPlayers ( playerID TEXT not null, award TEXT not null, year INTEGER not null, lgID TEXT, note TEXT, pos TEXT, primary key (playerID, award, year), foreign key (playerID) references Master (playerID) on update cascade on delete cascade ); CREATE TABLE CombinedShutouts ( year INTEGER, month INTEGER, date INTEGER, tmID TEXT, oppID TEXT, "R/P" TEXT, IDgoalie1 TEXT, IDgoalie2 TEXT, foreign key (IDgoalie1) references Master (playerID) on update cascade on delete cascade, foreign key (IDgoalie2) references Master (playerID) on update cascade on delete cascade ); CREATE TABLE Goalies ( playerID TEXT not null, year INTEGER not null, stint INTEGER not null, tmID TEXT, lgID TEXT, GP TEXT, Min TEXT, W TEXT, L TEXT, "T/OL" TEXT, ENG TEXT, SHO TEXT, GA TEXT, SA TEXT, PostGP TEXT, PostMin TEXT, PostW TEXT, PostL TEXT, PostT TEXT, PostENG TEXT, PostSHO TEXT, PostGA TEXT, PostSA TEXT, primary key (playerID, year, stint), foreign key (year, tmID) references Teams (year, tmID) on update cascade on delete cascade, foreign key (playerID) references Master (playerID) on update cascade on delete cascade ); CREATE TABLE GoaliesSC ( playerID TEXT not null, year INTEGER not null, tmID TEXT, lgID TEXT, GP INTEGER, Min INTEGER, W INTEGER, L INTEGER, T INTEGER, SHO INTEGER, GA INTEGER, primary key (playerID, year), foreign key (year, tmID) references Teams (year, tmID) on update cascade on delete cascade, foreign key (playerID) references Master (playerID) on update cascade on delete cascade ); CREATE TABLE GoaliesShootout ( playerID TEXT, year INTEGER, stint INTEGER, tmID TEXT, W INTEGER, L INTEGER, SA INTEGER, GA INTEGER, foreign key (year, tmID) references Teams (year, tmID) on update cascade on delete cascade, foreign key (playerID) references Master (playerID) on update cascade on delete cascade ); CREATE TABLE Scoring ( playerID TEXT, year INTEGER, stint INTEGER, tmID TEXT, lgID TEXT, pos TEXT, GP INTEGER, G INTEGER, A INTEGER, Pts INTEGER, PIM INTEGER, "+/-" TEXT, PPG TEXT, PPA TEXT, SHG TEXT, SHA TEXT, GWG TEXT, GTG TEXT, SOG TEXT, PostGP TEXT, PostG TEXT, PostA TEXT, PostPts TEXT, PostPIM TEXT, "Post+/-" TEXT, PostPPG TEXT, PostPPA TEXT, PostSHG TEXT, PostSHA TEXT, PostGWG TEXT, PostSOG TEXT, foreign key (year, tmID) references Teams (year, tmID) on update cascade on delete cascade, foreign key (playerID) references Master (playerID) on update cascade on delete cascade ); CREATE TABLE ScoringSC ( playerID TEXT, year INTEGER, tmID TEXT, lgID TEXT, pos TEXT, GP INTEGER, G INTEGER, A INTEGER, Pts INTEGER, PIM INTEGER, foreign key (year, tmID) references Teams (year, tmID) on update cascade on delete cascade, foreign key (playerID) references Master (playerID) on update cascade on delete cascade ); CREATE TABLE ScoringShootout ( playerID TEXT, year INTEGER, stint INTEGER, tmID TEXT, S INTEGER, G INTEGER, GDG INTEGER, foreign key (year, tmID) references Teams (year, tmID) on update cascade on delete cascade, foreign key (playerID) references Master (playerID) on update cascade on delete cascade ); CREATE TABLE ScoringSup ( playerID TEXT, year INTEGER, PPA TEXT, SHA TEXT, foreign key (playerID) references Master (playerID) on update cascade on delete cascade ); CREATE TABLE SeriesPost ( year INTEGER, round TEXT, series TEXT, tmIDWinner TEXT, lgIDWinner TEXT, tmIDLoser TEXT, lgIDLoser TEXT, W INTEGER, L INTEGER, T INTEGER, GoalsWinner INTEGER, GoalsLoser INTEGER, note TEXT, foreign key (year, tmIDWinner) references Teams (year, tmID) on update cascade on delete cascade, foreign key (year, tmIDLoser) references Teams (year, tmID) on update cascade on delete cascade ); CREATE TABLE TeamSplits ( year INTEGER not null, lgID TEXT, tmID TEXT not null, hW INTEGER, hL INTEGER, hT INTEGER, hOTL TEXT, rW INTEGER, rL INTEGER, rT INTEGER, rOTL TEXT, SepW TEXT, SepL TEXT, SepT TEXT, SepOL TEXT, OctW TEXT, OctL TEXT, OctT TEXT, OctOL TEXT, NovW TEXT, NovL TEXT, NovT TEXT, NovOL TEXT, DecW TEXT, DecL TEXT, DecT TEXT, DecOL TEXT, JanW INTEGER, JanL INTEGER, JanT INTEGER, JanOL TEXT, FebW INTEGER, FebL INTEGER, FebT INTEGER, FebOL TEXT, MarW TEXT, MarL TEXT, MarT TEXT, MarOL TEXT, AprW TEXT, AprL TEXT, AprT TEXT, AprOL TEXT, primary key (year, tmID), foreign key (year, tmID) references Teams (year, tmID) on update cascade on delete cascade ); CREATE TABLE TeamVsTeam ( year INTEGER not null, lgID TEXT, tmID TEXT not null, oppID TEXT not null, W INTEGER, L INTEGER, T INTEGER, OTL TEXT, primary key (year, tmID, oppID), foreign key (year, tmID) references Teams (year, tmID) on update cascade on delete cascade, foreign key (oppID, year) references Teams (tmID, year) on update cascade on delete cascade ); CREATE TABLE TeamsHalf ( year INTEGER not null, lgID TEXT, tmID TEXT not null, half INTEGER not null, rank INTEGER, G INTEGER, W INTEGER, L INTEGER, T INTEGER, GF INTEGER, GA INTEGER, primary key (year, tmID, half), foreign key (tmID, year) references Teams (tmID, year) on update cascade on delete cascade ); CREATE TABLE TeamsPost ( year INTEGER not null, lgID TEXT, tmID TEXT not null, G INTEGER, W INTEGER, L INTEGER, T INTEGER, GF INTEGER, GA INTEGER, PIM TEXT, BenchMinor TEXT, PPG TEXT, PPC TEXT, SHA TEXT, PKG TEXT, PKC TEXT, SHF TEXT, primary key (year, tmID), foreign key (year, tmID) references Teams (year, tmID) on update cascade on delete cascade ); CREATE TABLE TeamsSC ( year INTEGER not null, lgID TEXT, tmID TEXT not null, G INTEGER, W INTEGER, L INTEGER, T INTEGER, GF INTEGER, GA INTEGER, PIM TEXT, primary key (year, tmID), foreign key (year, tmID) references Teams (year, tmID) on update cascade on delete cascade ); CREATE TABLE abbrev ( Type TEXT not null, Code TEXT not null, Fullname TEXT, primary key (Type, Code) );
authors
What percentage of papers were preprinted after the year 2000?
after the year 2000 refers to Year > 2000; preprinted refers to ConferenceId = 0 AND JournalId = 0; percentage refers to DIVIDE(COUNT(ConferenceId = 0 AND JournalId = 0 AND Year > 2000), COUNT(Id))
SELECT CAST(SUM(CASE WHEN Year > 2000 THEN 1 ELSE 0 END) AS REAL) * 100 / COUNT(Id) FROM Paper
CREATE TABLE IF NOT EXISTS "Author" ( Id INTEGER constraint Author_pk primary key, Name TEXT, Affiliation TEXT ); CREATE TABLE IF NOT EXISTS "Conference" ( Id INTEGER constraint Conference_pk primary key, ShortName TEXT, FullName TEXT, HomePage TEXT ); CREATE TABLE IF NOT EXISTS "Journal" ( Id INTEGER constraint Journal_pk primary key, ShortName TEXT, FullName TEXT, HomePage TEXT ); CREATE TABLE Paper ( Id INTEGER primary key, Title TEXT, Year INTEGER, ConferenceId INTEGER, JournalId INTEGER, Keyword TEXT, foreign key (ConferenceId) references Conference(Id), foreign key (JournalId) references Journal(Id) ); CREATE TABLE PaperAuthor ( PaperId INTEGER, AuthorId INTEGER, Name TEXT, Affiliation TEXT, foreign key (PaperId) references Paper(Id), foreign key (AuthorId) references Author(Id) );
soccer_2016
What is the name of the player who won the "man of the match" award in the match on 2008/4/18?
name of player refers to Player_Name; on 2008/4/18 refers to Match_Date = '2008-04-18'
SELECT T2.Player_Name FROM Match AS T1 INNER JOIN Player AS T2 ON T2.Player_Id = T1.Man_of_the_Match WHERE T1.Match_Date = '2008-04-18'
CREATE TABLE Batting_Style ( Batting_Id INTEGER primary key, Batting_hand TEXT ); CREATE TABLE Bowling_Style ( Bowling_Id INTEGER primary key, Bowling_skill TEXT ); CREATE TABLE City ( City_Id INTEGER primary key, City_Name TEXT, Country_id INTEGER ); CREATE TABLE Country ( Country_Id INTEGER primary key, Country_Name TEXT, foreign key (Country_Id) references Country(Country_Id) ); CREATE TABLE Extra_Type ( Extra_Id INTEGER primary key, Extra_Name TEXT ); CREATE TABLE Extra_Runs ( Match_Id INTEGER, Over_Id INTEGER, Ball_Id INTEGER, Extra_Type_Id INTEGER, Extra_Runs INTEGER, Innings_No INTEGER, primary key (Match_Id, Over_Id, Ball_Id, Innings_No), foreign key (Extra_Type_Id) references Extra_Type(Extra_Id) ); CREATE TABLE Out_Type ( Out_Id INTEGER primary key, Out_Name TEXT ); CREATE TABLE Outcome ( Outcome_Id INTEGER primary key, Outcome_Type TEXT ); CREATE TABLE Player ( Player_Id INTEGER primary key, Player_Name TEXT, DOB DATE, Batting_hand INTEGER, Bowling_skill INTEGER, Country_Name INTEGER, foreign key (Batting_hand) references Batting_Style(Batting_Id), foreign key (Bowling_skill) references Bowling_Style(Bowling_Id), foreign key (Country_Name) references Country(Country_Id) ); CREATE TABLE Rolee ( Role_Id INTEGER primary key, Role_Desc TEXT ); CREATE TABLE Season ( Season_Id INTEGER primary key, Man_of_the_Series INTEGER, Orange_Cap INTEGER, Purple_Cap INTEGER, Season_Year INTEGER ); CREATE TABLE Team ( Team_Id INTEGER primary key, Team_Name TEXT ); CREATE TABLE Toss_Decision ( Toss_Id INTEGER primary key, Toss_Name TEXT ); CREATE TABLE Umpire ( Umpire_Id INTEGER primary key, Umpire_Name TEXT, Umpire_Country INTEGER, foreign key (Umpire_Country) references Country(Country_Id) ); CREATE TABLE Venue ( Venue_Id INTEGER primary key, Venue_Name TEXT, City_Id INTEGER, foreign key (City_Id) references City(City_Id) ); CREATE TABLE Win_By ( Win_Id INTEGER primary key, Win_Type TEXT ); CREATE TABLE Match ( Match_Id INTEGER primary key, Team_1 INTEGER, Team_2 INTEGER, Match_Date DATE, Season_Id INTEGER, Venue_Id INTEGER, Toss_Winner INTEGER, Toss_Decide INTEGER, Win_Type INTEGER, Win_Margin INTEGER, Outcome_type INTEGER, Match_Winner INTEGER, Man_of_the_Match INTEGER, foreign key (Team_1) references Team(Team_Id), foreign key (Team_2) references Team(Team_Id), foreign key (Season_Id) references Season(Season_Id), foreign key (Venue_Id) references Venue(Venue_Id), foreign key (Toss_Winner) references Team(Team_Id), foreign key (Toss_Decide) references Toss_Decision(Toss_Id), foreign key (Win_Type) references Win_By(Win_Id), foreign key (Outcome_type) references Out_Type(Out_Id), foreign key (Match_Winner) references Team(Team_Id), foreign key (Man_of_the_Match) references Player(Player_Id) ); CREATE TABLE Ball_by_Ball ( Match_Id INTEGER, Over_Id INTEGER, Ball_Id INTEGER, Innings_No INTEGER, Team_Batting INTEGER, Team_Bowling INTEGER, Striker_Batting_Position INTEGER, Striker INTEGER, Non_Striker INTEGER, Bowler INTEGER, primary key (Match_Id, Over_Id, Ball_Id, Innings_No), foreign key (Match_Id) references Match(Match_Id) ); CREATE TABLE Batsman_Scored ( Match_Id INTEGER, Over_Id INTEGER, Ball_Id INTEGER, Runs_Scored INTEGER, Innings_No INTEGER, primary key (Match_Id, Over_Id, Ball_Id, Innings_No), foreign key (Match_Id) references Match(Match_Id) ); CREATE TABLE Player_Match ( Match_Id INTEGER, Player_Id INTEGER, Role_Id INTEGER, Team_Id INTEGER, primary key (Match_Id, Player_Id, Role_Id), foreign key (Match_Id) references Match(Match_Id), foreign key (Player_Id) references Player(Player_Id), foreign key (Team_Id) references Team(Team_Id), foreign key (Role_Id) references Rolee(Role_Id) ); CREATE TABLE Wicket_Taken ( Match_Id INTEGER, Over_Id INTEGER, Ball_Id INTEGER, Player_Out INTEGER, Kind_Out INTEGER, Fielders INTEGER, Innings_No INTEGER, primary key (Match_Id, Over_Id, Ball_Id, Innings_No), foreign key (Match_Id) references Match(Match_Id), foreign key (Player_Out) references Player(Player_Id), foreign key (Kind_Out) references Out_Type(Out_Id), foreign key (Fielders) references Player(Player_Id) );
student_loan
How many students have been absent less than 4 months?
absent less than 4 months refers to month < 4;
SELECT COUNT(name) FROM longest_absense_from_school WHERE month < 4
CREATE TABLE bool ( "name" TEXT default '' not null primary key ); CREATE TABLE person ( "name" TEXT default '' not null primary key ); CREATE TABLE disabled ( "name" TEXT default '' not null primary key, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE enlist ( "name" TEXT not null, organ TEXT not null, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE filed_for_bankrupcy ( "name" TEXT default '' not null primary key, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE longest_absense_from_school ( "name" TEXT default '' not null primary key, "month" INTEGER default 0 null, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE male ( "name" TEXT default '' not null primary key, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE no_payment_due ( "name" TEXT default '' not null primary key, bool TEXT null, foreign key ("name") references person ("name") on update cascade on delete cascade, foreign key (bool) references bool ("name") on update cascade on delete cascade ); CREATE TABLE unemployed ( "name" TEXT default '' not null primary key, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE `enrolled` ( `name` TEXT NOT NULL, `school` TEXT NOT NULL, `month` INTEGER NOT NULL DEFAULT 0, PRIMARY KEY (`name`,`school`), FOREIGN KEY (`name`) REFERENCES `person` (`name`) ON DELETE CASCADE ON UPDATE CASCADE );
mondial_geo
Provide the country with republic government which has the highest population growth?
SELECT T2.Country FROM population AS T1 INNER JOIN politics AS T2 ON T1.Country = T2.Country WHERE T2.Government = 'republic' ORDER BY T1.Population_Growth DESC LIMIT 1
CREATE TABLE IF NOT EXISTS "borders" ( Country1 TEXT default '' not null constraint borders_ibfk_1 references country, Country2 TEXT default '' not null constraint borders_ibfk_2 references country, Length REAL, primary key (Country1, Country2) ); CREATE TABLE IF NOT EXISTS "city" ( Name TEXT default '' not null, Country TEXT default '' not null constraint city_ibfk_1 references country on update cascade on delete cascade, Province TEXT default '' not null, Population INTEGER, Longitude REAL, Latitude REAL, primary key (Name, Province), constraint city_ibfk_2 foreign key (Province, Country) references province on update cascade on delete cascade ); CREATE TABLE IF NOT EXISTS "continent" ( Name TEXT default '' not null primary key, Area REAL ); CREATE TABLE IF NOT EXISTS "country" ( Name TEXT not null constraint ix_county_Name unique, Code TEXT default '' not null primary key, Capital TEXT, Province TEXT, Area REAL, Population INTEGER ); CREATE TABLE IF NOT EXISTS "desert" ( Name TEXT default '' not null primary key, Area REAL, Longitude REAL, Latitude REAL ); CREATE TABLE IF NOT EXISTS "economy" ( Country TEXT default '' not null primary key constraint economy_ibfk_1 references country on update cascade on delete cascade, GDP REAL, Agriculture REAL, Service REAL, Industry REAL, Inflation REAL ); CREATE TABLE IF NOT EXISTS "encompasses" ( Country TEXT not null constraint encompasses_ibfk_1 references country on update cascade on delete cascade, Continent TEXT not null constraint encompasses_ibfk_2 references continent on update cascade on delete cascade, Percentage REAL, primary key (Country, Continent) ); CREATE TABLE IF NOT EXISTS "ethnicGroup" ( Country TEXT default '' not null constraint ethnicGroup_ibfk_1 references country on update cascade on delete cascade, Name TEXT default '' not null, Percentage REAL, primary key (Name, Country) ); CREATE TABLE IF NOT EXISTS "geo_desert" ( Desert TEXT default '' not null constraint geo_desert_ibfk_3 references desert on update cascade on delete cascade, Country TEXT default '' not null constraint geo_desert_ibfk_1 references country on update cascade on delete cascade, Province TEXT default '' not null, primary key (Province, Country, Desert), constraint geo_desert_ibfk_2 foreign key (Province, Country) references province on update cascade on delete cascade ); CREATE TABLE IF NOT EXISTS "geo_estuary" ( River TEXT default '' not null constraint geo_estuary_ibfk_3 references river on update cascade on delete cascade, Country TEXT default '' not null constraint geo_estuary_ibfk_1 references country on update cascade on delete cascade, Province TEXT default '' not null, primary key (Province, Country, River), constraint geo_estuary_ibfk_2 foreign key (Province, Country) references province on update cascade on delete cascade ); CREATE TABLE IF NOT EXISTS "geo_island" ( Island TEXT default '' not null constraint geo_island_ibfk_3 references island on update cascade on delete cascade, Country TEXT default '' not null constraint geo_island_ibfk_1 references country on update cascade on delete cascade, Province TEXT default '' not null, primary key (Province, Country, Island), constraint geo_island_ibfk_2 foreign key (Province, Country) references province on update cascade on delete cascade ); CREATE TABLE IF NOT EXISTS "geo_lake" ( Lake TEXT default '' not null constraint geo_lake_ibfk_3 references lake on update cascade on delete cascade, Country TEXT default '' not null constraint geo_lake_ibfk_1 references country on update cascade on delete cascade, Province TEXT default '' not null, primary key (Province, Country, Lake), constraint geo_lake_ibfk_2 foreign key (Province, Country) references province on update cascade on delete cascade ); CREATE TABLE IF NOT EXISTS "geo_mountain" ( Mountain TEXT default '' not null constraint geo_mountain_ibfk_3 references mountain on update cascade on delete cascade, Country TEXT default '' not null constraint geo_mountain_ibfk_1 references country on update cascade on delete cascade, Province TEXT default '' not null, primary key (Province, Country, Mountain), constraint geo_mountain_ibfk_2 foreign key (Province, Country) references province on update cascade on delete cascade ); CREATE TABLE IF NOT EXISTS "geo_river" ( River TEXT default '' not null constraint geo_river_ibfk_3 references river on update cascade on delete cascade, Country TEXT default '' not null constraint geo_river_ibfk_1 references country on update cascade on delete cascade, Province TEXT default '' not null, primary key (Province, Country, River), constraint geo_river_ibfk_2 foreign key (Province, Country) references province on update cascade on delete cascade ); CREATE TABLE IF NOT EXISTS "geo_sea" ( Sea TEXT default '' not null constraint geo_sea_ibfk_3 references sea on update cascade on delete cascade, Country TEXT default '' not null constraint geo_sea_ibfk_1 references country on update cascade on delete cascade, Province TEXT default '' not null, primary key (Province, Country, Sea), constraint geo_sea_ibfk_2 foreign key (Province, Country) references province on update cascade on delete cascade ); CREATE TABLE IF NOT EXISTS "geo_source" ( River TEXT default '' not null constraint geo_source_ibfk_3 references river on update cascade on delete cascade, Country TEXT default '' not null constraint geo_source_ibfk_1 references country on update cascade on delete cascade, Province TEXT default '' not null, primary key (Province, Country, River), constraint geo_source_ibfk_2 foreign key (Province, Country) references province on update cascade on delete cascade ); CREATE TABLE IF NOT EXISTS "island" ( Name TEXT default '' not null primary key, Islands TEXT, Area REAL, Height REAL, Type TEXT, Longitude REAL, Latitude REAL ); CREATE TABLE IF NOT EXISTS "islandIn" ( Island TEXT constraint islandIn_ibfk_4 references island on update cascade on delete cascade, Sea TEXT constraint islandIn_ibfk_3 references sea on update cascade on delete cascade, Lake TEXT constraint islandIn_ibfk_1 references lake on update cascade on delete cascade, River TEXT constraint islandIn_ibfk_2 references river on update cascade on delete cascade ); CREATE TABLE IF NOT EXISTS "isMember" ( Country TEXT default '' not null constraint isMember_ibfk_1 references country on update cascade on delete cascade, Organization TEXT default '' not null constraint isMember_ibfk_2 references organization on update cascade on delete cascade, Type TEXT default 'member', primary key (Country, Organization) ); CREATE TABLE IF NOT EXISTS "lake" ( Name TEXT default '' not null primary key, Area REAL, Depth REAL, Altitude REAL, Type TEXT, River TEXT, Longitude REAL, Latitude REAL ); CREATE TABLE IF NOT EXISTS "language" ( Country TEXT default '' not null constraint language_ibfk_1 references country on update cascade on delete cascade, Name TEXT default '' not null, Percentage REAL, primary key (Name, Country) ); CREATE TABLE IF NOT EXISTS "located" ( City TEXT, Province TEXT, Country TEXT constraint located_ibfk_1 references country on update cascade on delete cascade, River TEXT constraint located_ibfk_3 references river on update cascade on delete cascade, Lake TEXT constraint located_ibfk_4 references lake on update cascade on delete cascade, Sea TEXT constraint located_ibfk_5 references sea on update cascade on delete cascade, constraint located_ibfk_2 foreign key (City, Province) references city on update cascade on delete cascade, constraint located_ibfk_6 foreign key (Province, Country) references province on update cascade on delete cascade ); CREATE TABLE IF NOT EXISTS "locatedOn" ( City TEXT default '' not null, Province TEXT default '' not null, Country TEXT default '' not null constraint locatedOn_ibfk_1 references country on update cascade on delete cascade, Island TEXT default '' not null constraint locatedOn_ibfk_2 references island on update cascade on delete cascade, primary key (City, Province, Country, Island), constraint locatedOn_ibfk_3 foreign key (City, Province) references city on update cascade on delete cascade, constraint locatedOn_ibfk_4 foreign key (Province, Country) references province on update cascade on delete cascade ); CREATE TABLE IF NOT EXISTS "mergesWith" ( Sea1 TEXT default '' not null constraint mergesWith_ibfk_1 references sea on update cascade on delete cascade, Sea2 TEXT default '' not null constraint mergesWith_ibfk_2 references sea on update cascade on delete cascade, primary key (Sea1, Sea2) ); CREATE TABLE IF NOT EXISTS "mountain" ( Name TEXT default '' not null primary key, Mountains TEXT, Height REAL, Type TEXT, Longitude REAL, Latitude REAL ); CREATE TABLE IF NOT EXISTS "mountainOnIsland" ( Mountain TEXT default '' not null constraint mountainOnIsland_ibfk_2 references mountain on update cascade on delete cascade, Island TEXT default '' not null constraint mountainOnIsland_ibfk_1 references island on update cascade on delete cascade, primary key (Mountain, Island) ); CREATE TABLE IF NOT EXISTS "organization" ( Abbreviation TEXT not null primary key, Name TEXT not null constraint ix_organization_OrgNameUnique unique, City TEXT, Country TEXT constraint organization_ibfk_1 references country on update cascade on delete cascade, Province TEXT, Established DATE, constraint organization_ibfk_2 foreign key (City, Province) references city on update cascade on delete cascade, constraint organization_ibfk_3 foreign key (Province, Country) references province on update cascade on delete cascade ); CREATE TABLE IF NOT EXISTS "politics" ( Country TEXT default '' not null primary key constraint politics_ibfk_1 references country on update cascade on delete cascade, Independence DATE, Dependent TEXT constraint politics_ibfk_2 references country on update cascade on delete cascade, Government TEXT ); CREATE TABLE IF NOT EXISTS "population" ( Country TEXT default '' not null primary key constraint population_ibfk_1 references country on update cascade on delete cascade, Population_Growth REAL, Infant_Mortality REAL ); CREATE TABLE IF NOT EXISTS "province" ( Name TEXT not null, Country TEXT not null constraint province_ibfk_1 references country on update cascade on delete cascade, Population INTEGER, Area REAL, Capital TEXT, CapProv TEXT, primary key (Name, Country) ); CREATE TABLE IF NOT EXISTS "religion" ( Country TEXT default '' not null constraint religion_ibfk_1 references country on update cascade on delete cascade, Name TEXT default '' not null, Percentage REAL, primary key (Name, Country) ); CREATE TABLE IF NOT EXISTS "river" ( Name TEXT default '' not null primary key, River TEXT, Lake TEXT constraint river_ibfk_1 references lake on update cascade on delete cascade, Sea TEXT, Length REAL, SourceLongitude REAL, SourceLatitude REAL, Mountains TEXT, SourceAltitude REAL, EstuaryLongitude REAL, EstuaryLatitude REAL ); CREATE TABLE IF NOT EXISTS "sea" ( Name TEXT default '' not null primary key, Depth REAL ); CREATE TABLE IF NOT EXISTS "target" ( Country TEXT not null primary key constraint target_Country_fkey references country on update cascade on delete cascade, Target TEXT );
music_platform_2
What is the name of the podcast in which a commentor left a comment with the title 'Long time listener, calling it quits?' Include the URL of the podcast as well.
comment refers to review; 'Long time listener, calling it quits' is the title of review;  name of the podcast refers to title of podcast; URL refers to itunes_url
SELECT podcast_id, itunes_url FROM podcasts WHERE podcast_id = ( SELECT podcast_id FROM reviews WHERE title = 'Long time listener, calling it quits' )
CREATE TABLE runs ( run_at text not null, max_rowid integer not null, reviews_added integer not null ); CREATE TABLE podcasts ( podcast_id text primary key, itunes_id integer not null, slug text not null, itunes_url text not null, title text not null ); CREATE TABLE IF NOT EXISTS "reviews" ( podcast_id TEXT not null constraint reviews_podcasts_podcast_id_fk references podcasts, title TEXT not null, content TEXT not null, rating INTEGER not null, author_id TEXT not null, created_at TEXT not null ); CREATE TABLE IF NOT EXISTS "categories" ( podcast_id TEXT not null constraint categories_podcasts_podcast_id_fk references podcasts, category TEXT not null, constraint "PRIMARY" primary key (podcast_id, category) ); CREATE INDEX category_podcast_id_idx on categories (podcast_id);
language_corpus
Indicate if there is any pair formed by the words fukunaga and d'egees.
Pair is a relationship of two words: w1st and w2nd, where w1st is word id of the first word and w2nd is a word id of the second word;  w1st = word = 'fukunaga' or w2nd = word = 'fukunaga'; w1st = word = 'd'egees'or w2nd = word = 'd'egees';
SELECT CASE WHEN COUNT(T1.wid) > 0 THEN 'yes' ELSE 'no' END FROM words AS T1 INNER JOIN biwords AS T2 ON T1.wid = T2.w1st OR T1.wid = T2.w2nd WHERE T2.w1st = ( SELECT wid FROM words WHERE T1.word = 'fukunaga' ) AND T2.w2nd = ( SELECT wid FROM words WHERE word LIKE 'd%egees' )
CREATE TABLE langs(lid INTEGER PRIMARY KEY AUTOINCREMENT, lang TEXT UNIQUE, locale TEXT UNIQUE, pages INTEGER DEFAULT 0, -- total pages in this language words INTEGER DEFAULT 0); CREATE TABLE sqlite_sequence(name,seq); CREATE TABLE pages(pid INTEGER PRIMARY KEY AUTOINCREMENT, lid INTEGER REFERENCES langs(lid) ON UPDATE CASCADE ON DELETE CASCADE, page INTEGER DEFAULT NULL, -- wikipedia page id revision INTEGER DEFAULT NULL, -- wikipedia revision page id title TEXT, words INTEGER DEFAULT 0, -- number of different words in this page UNIQUE(lid,page,title)); CREATE TRIGGER ins_page AFTER INSERT ON pages FOR EACH ROW BEGIN UPDATE langs SET pages=pages+1 WHERE lid=NEW.lid; END; CREATE TRIGGER del_page AFTER DELETE ON pages FOR EACH ROW BEGIN UPDATE langs SET pages=pages-1 WHERE lid=OLD.lid; END; CREATE TABLE words(wid INTEGER PRIMARY KEY AUTOINCREMENT, word TEXT UNIQUE, occurrences INTEGER DEFAULT 0); CREATE TABLE langs_words(lid INTEGER REFERENCES langs(lid) ON UPDATE CASCADE ON DELETE CASCADE, wid INTEGER REFERENCES words(wid) ON UPDATE CASCADE ON DELETE CASCADE, occurrences INTEGER, -- repetitions of this word in this language PRIMARY KEY(lid,wid)) WITHOUT ROWID; CREATE TRIGGER ins_lang_word AFTER INSERT ON langs_words FOR EACH ROW BEGIN UPDATE langs SET words=words+1 WHERE lid=NEW.lid; END; CREATE TRIGGER del_lang_word AFTER DELETE ON langs_words FOR EACH ROW BEGIN UPDATE langs SET words=words-1 WHERE lid=OLD.lid; END; CREATE TABLE pages_words(pid INTEGER REFERENCES pages(pid) ON UPDATE CASCADE ON DELETE CASCADE, wid INTEGER REFERENCES words(wid) ON UPDATE CASCADE ON DELETE CASCADE, occurrences INTEGER DEFAULT 0, -- times this word appears into this page PRIMARY KEY(pid,wid)) WITHOUT ROWID; CREATE TRIGGER ins_page_word AFTER INSERT ON pages_words FOR EACH ROW BEGIN UPDATE pages SET words=words+1 WHERE pid=NEW.pid; END; CREATE TRIGGER del_page_word AFTER DELETE ON pages_words FOR EACH ROW BEGIN UPDATE pages SET words=words-1 WHERE pid=OLD.pid; END; CREATE TABLE biwords(lid INTEGER REFERENCES langs(lid) ON UPDATE CASCADE ON DELETE CASCADE, w1st INTEGER REFERENCES words(wid) ON UPDATE CASCADE ON DELETE CASCADE, w2nd INTEGER REFERENCES words(wid) ON UPDATE CASCADE ON DELETE CASCADE, occurrences INTEGER DEFAULT 0, -- times this pair appears in this language/page PRIMARY KEY(lid,w1st,w2nd)) WITHOUT ROWID;
shipping
What is the model year of the truck used in shipment id 1003?
shipment id 1003 refers to ship_id = 1003
SELECT T1.model_year FROM truck AS T1 INNER JOIN shipment AS T2 ON T1.truck_id = T2.truck_id WHERE T2.ship_id = '1003'
CREATE TABLE city ( city_id INTEGER primary key, city_name TEXT, state TEXT, population INTEGER, area REAL ); CREATE TABLE customer ( cust_id INTEGER primary key, cust_name TEXT, annual_revenue INTEGER, cust_type TEXT, address TEXT, city TEXT, state TEXT, zip REAL, phone TEXT ); CREATE TABLE driver ( driver_id INTEGER primary key, first_name TEXT, last_name TEXT, address TEXT, city TEXT, state TEXT, zip_code INTEGER, phone TEXT ); CREATE TABLE truck ( truck_id INTEGER primary key, make TEXT, model_year INTEGER ); CREATE TABLE shipment ( ship_id INTEGER primary key, cust_id INTEGER, weight REAL, truck_id INTEGER, driver_id INTEGER, city_id INTEGER, ship_date TEXT, foreign key (cust_id) references customer(cust_id), foreign key (city_id) references city(city_id), foreign key (driver_id) references driver(driver_id), foreign key (truck_id) references truck(truck_id) );
shipping
How many pounds did Sue Newell transport during her first shipment?
first shipment refers to Min(ship_date); pounds refers to weight
SELECT T1.weight FROM shipment AS T1 INNER JOIN driver AS T2 ON T1.driver_id = T2.driver_id WHERE T2.first_name = 'Sue' AND T2.last_name = 'Newell' ORDER BY T1.ship_date ASC LIMIT 1
CREATE TABLE city ( city_id INTEGER primary key, city_name TEXT, state TEXT, population INTEGER, area REAL ); CREATE TABLE customer ( cust_id INTEGER primary key, cust_name TEXT, annual_revenue INTEGER, cust_type TEXT, address TEXT, city TEXT, state TEXT, zip REAL, phone TEXT ); CREATE TABLE driver ( driver_id INTEGER primary key, first_name TEXT, last_name TEXT, address TEXT, city TEXT, state TEXT, zip_code INTEGER, phone TEXT ); CREATE TABLE truck ( truck_id INTEGER primary key, make TEXT, model_year INTEGER ); CREATE TABLE shipment ( ship_id INTEGER primary key, cust_id INTEGER, weight REAL, truck_id INTEGER, driver_id INTEGER, city_id INTEGER, ship_date TEXT, foreign key (cust_id) references customer(cust_id), foreign key (city_id) references city(city_id), foreign key (driver_id) references driver(driver_id), foreign key (truck_id) references truck(truck_id) );
cs_semester
List the professors' IDs and students' IDs with the lowest research ability.
the lowest research ability refers to MIN(capability); professor’s ID refers to prof_id;
SELECT prof_id, student_id FROM RA WHERE capability = ( SELECT MIN(capability) FROM RA )
CREATE TABLE IF NOT EXISTS "course" ( course_id INTEGER constraint course_pk primary key, name TEXT, credit INTEGER, diff INTEGER ); CREATE TABLE prof ( prof_id INTEGER constraint prof_pk primary key, gender TEXT, first_name TEXT, last_name TEXT, email TEXT, popularity INTEGER, teachingability INTEGER, graduate_from TEXT ); CREATE TABLE RA ( student_id INTEGER, capability INTEGER, prof_id INTEGER, salary TEXT, primary key (student_id, prof_id), foreign key (prof_id) references prof(prof_id), foreign key (student_id) references student(student_id) ); CREATE TABLE registration ( course_id INTEGER, student_id INTEGER, grade TEXT, sat INTEGER, primary key (course_id, student_id), foreign key (course_id) references course(course_id), foreign key (student_id) references student(student_id) ); CREATE TABLE student ( student_id INTEGER primary key, f_name TEXT, l_name TEXT, phone_number TEXT, email TEXT, intelligence INTEGER, gpa REAL, type TEXT );
beer_factory
Which root beer got the most five stars in 2012? Give the brand name of this beer.
most five stars refers to MAX(COUNT(StarRating = 5)); in 2012 refers to FirstBrewedYear = 2012;
SELECT T3.BrandName FROM rootbeer AS T1 INNER JOIN rootbeerreview AS T2 ON T1.BrandID = T2.BrandID INNER JOIN rootbeerbrand AS T3 ON T1.BrandID = T3.BrandID WHERE T2.StarRating = 5 AND strftime('%Y', T2.ReviewDate) = '2012' GROUP BY T1.BrandID ORDER BY COUNT(T2.BrandID) DESC LIMIT 1
CREATE TABLE customers ( CustomerID INTEGER primary key, First TEXT, Last TEXT, StreetAddress TEXT, City TEXT, State TEXT, ZipCode INTEGER, Email TEXT, PhoneNumber TEXT, FirstPurchaseDate DATE, SubscribedToEmailList TEXT, Gender TEXT ); CREATE TABLE geolocation ( LocationID INTEGER primary key, Latitude REAL, Longitude REAL, foreign key (LocationID) references location(LocationID) ); CREATE TABLE location ( LocationID INTEGER primary key, LocationName TEXT, StreetAddress TEXT, City TEXT, State TEXT, ZipCode INTEGER, foreign key (LocationID) references geolocation(LocationID) ); CREATE TABLE rootbeerbrand ( BrandID INTEGER primary key, BrandName TEXT, FirstBrewedYear INTEGER, BreweryName TEXT, City TEXT, State TEXT, Country TEXT, Description TEXT, CaneSugar TEXT, CornSyrup TEXT, Honey TEXT, ArtificialSweetener TEXT, Caffeinated TEXT, Alcoholic TEXT, AvailableInCans TEXT, AvailableInBottles TEXT, AvailableInKegs TEXT, Website TEXT, FacebookPage TEXT, Twitter TEXT, WholesaleCost REAL, CurrentRetailPrice REAL ); CREATE TABLE rootbeer ( RootBeerID INTEGER primary key, BrandID INTEGER, ContainerType TEXT, LocationID INTEGER, PurchaseDate DATE, foreign key (LocationID) references geolocation(LocationID), foreign key (LocationID) references location(LocationID), foreign key (BrandID) references rootbeerbrand(BrandID) ); CREATE TABLE rootbeerreview ( CustomerID INTEGER, BrandID INTEGER, StarRating INTEGER, ReviewDate DATE, Review TEXT, primary key (CustomerID, BrandID), foreign key (CustomerID) references customers(CustomerID), foreign key (BrandID) references rootbeerbrand(BrandID) ); CREATE TABLE IF NOT EXISTS "transaction" ( TransactionID INTEGER primary key, CreditCardNumber INTEGER, CustomerID INTEGER, TransactionDate DATE, CreditCardType TEXT, LocationID INTEGER, RootBeerID INTEGER, PurchasePrice REAL, foreign key (CustomerID) references customers(CustomerID), foreign key (LocationID) references location(LocationID), foreign key (RootBeerID) references rootbeer(RootBeerID) );
books
How many books were published in 2017?
published in 2017 refers to Substr(publication_date,1, 4) = '2017'
SELECT COUNT(*) FROM book WHERE STRFTIME('%Y', publication_date) = '2017'
CREATE TABLE address_status ( status_id INTEGER primary key, address_status TEXT ); CREATE TABLE author ( author_id INTEGER primary key, author_name TEXT ); CREATE TABLE book_language ( language_id INTEGER primary key, language_code TEXT, language_name TEXT ); CREATE TABLE country ( country_id INTEGER primary key, country_name TEXT ); CREATE TABLE address ( address_id INTEGER primary key, street_number TEXT, street_name TEXT, city TEXT, country_id INTEGER, foreign key (country_id) references country(country_id) ); CREATE TABLE customer ( customer_id INTEGER primary key, first_name TEXT, last_name TEXT, email TEXT ); CREATE TABLE customer_address ( customer_id INTEGER, address_id INTEGER, status_id INTEGER, primary key (customer_id, address_id), foreign key (address_id) references address(address_id), foreign key (customer_id) references customer(customer_id) ); CREATE TABLE order_status ( status_id INTEGER primary key, status_value TEXT ); CREATE TABLE publisher ( publisher_id INTEGER primary key, publisher_name TEXT ); CREATE TABLE book ( book_id INTEGER primary key, title TEXT, isbn13 TEXT, language_id INTEGER, num_pages INTEGER, publication_date DATE, publisher_id INTEGER, foreign key (language_id) references book_language(language_id), foreign key (publisher_id) references publisher(publisher_id) ); CREATE TABLE book_author ( book_id INTEGER, author_id INTEGER, primary key (book_id, author_id), foreign key (author_id) references author(author_id), foreign key (book_id) references book(book_id) ); CREATE TABLE shipping_method ( method_id INTEGER primary key, method_name TEXT, cost REAL ); CREATE TABLE IF NOT EXISTS "cust_order" ( order_id INTEGER primary key autoincrement, order_date DATETIME, customer_id INTEGER references customer, shipping_method_id INTEGER references shipping_method, dest_address_id INTEGER references address ); CREATE TABLE sqlite_sequence(name,seq); CREATE TABLE IF NOT EXISTS "order_history" ( history_id INTEGER primary key autoincrement, order_id INTEGER references cust_order, status_id INTEGER references order_status, status_date DATETIME ); CREATE TABLE IF NOT EXISTS "order_line" ( line_id INTEGER primary key autoincrement, order_id INTEGER references cust_order, book_id INTEGER references book, price REAL );
mondial_geo
How many cities in France have a population of more than 100,000?
SELECT COUNT(T2.Name) FROM country AS T1 INNER JOIN city AS T2 ON T2.Country = T1.Code WHERE T1.Name = 'France' AND T2.Population > 100000
CREATE TABLE IF NOT EXISTS "borders" ( Country1 TEXT default '' not null constraint borders_ibfk_1 references country, Country2 TEXT default '' not null constraint borders_ibfk_2 references country, Length REAL, primary key (Country1, Country2) ); CREATE TABLE IF NOT EXISTS "city" ( Name TEXT default '' not null, Country TEXT default '' not null constraint city_ibfk_1 references country on update cascade on delete cascade, Province TEXT default '' not null, Population INTEGER, Longitude REAL, Latitude REAL, primary key (Name, Province), constraint city_ibfk_2 foreign key (Province, Country) references province on update cascade on delete cascade ); CREATE TABLE IF NOT EXISTS "continent" ( Name TEXT default '' not null primary key, Area REAL ); CREATE TABLE IF NOT EXISTS "country" ( Name TEXT not null constraint ix_county_Name unique, Code TEXT default '' not null primary key, Capital TEXT, Province TEXT, Area REAL, Population INTEGER ); CREATE TABLE IF NOT EXISTS "desert" ( Name TEXT default '' not null primary key, Area REAL, Longitude REAL, Latitude REAL ); CREATE TABLE IF NOT EXISTS "economy" ( Country TEXT default '' not null primary key constraint economy_ibfk_1 references country on update cascade on delete cascade, GDP REAL, Agriculture REAL, Service REAL, Industry REAL, Inflation REAL ); CREATE TABLE IF NOT EXISTS "encompasses" ( Country TEXT not null constraint encompasses_ibfk_1 references country on update cascade on delete cascade, Continent TEXT not null constraint encompasses_ibfk_2 references continent on update cascade on delete cascade, Percentage REAL, primary key (Country, Continent) ); CREATE TABLE IF NOT EXISTS "ethnicGroup" ( Country TEXT default '' not null constraint ethnicGroup_ibfk_1 references country on update cascade on delete cascade, Name TEXT default '' not null, Percentage REAL, primary key (Name, Country) ); CREATE TABLE IF NOT EXISTS "geo_desert" ( Desert TEXT default '' not null constraint geo_desert_ibfk_3 references desert on update cascade on delete cascade, Country TEXT default '' not null constraint geo_desert_ibfk_1 references country on update cascade on delete cascade, Province TEXT default '' not null, primary key (Province, Country, Desert), constraint geo_desert_ibfk_2 foreign key (Province, Country) references province on update cascade on delete cascade ); CREATE TABLE IF NOT EXISTS "geo_estuary" ( River TEXT default '' not null constraint geo_estuary_ibfk_3 references river on update cascade on delete cascade, Country TEXT default '' not null constraint geo_estuary_ibfk_1 references country on update cascade on delete cascade, Province TEXT default '' not null, primary key (Province, Country, River), constraint geo_estuary_ibfk_2 foreign key (Province, Country) references province on update cascade on delete cascade ); CREATE TABLE IF NOT EXISTS "geo_island" ( Island TEXT default '' not null constraint geo_island_ibfk_3 references island on update cascade on delete cascade, Country TEXT default '' not null constraint geo_island_ibfk_1 references country on update cascade on delete cascade, Province TEXT default '' not null, primary key (Province, Country, Island), constraint geo_island_ibfk_2 foreign key (Province, Country) references province on update cascade on delete cascade ); CREATE TABLE IF NOT EXISTS "geo_lake" ( Lake TEXT default '' not null constraint geo_lake_ibfk_3 references lake on update cascade on delete cascade, Country TEXT default '' not null constraint geo_lake_ibfk_1 references country on update cascade on delete cascade, Province TEXT default '' not null, primary key (Province, Country, Lake), constraint geo_lake_ibfk_2 foreign key (Province, Country) references province on update cascade on delete cascade ); CREATE TABLE IF NOT EXISTS "geo_mountain" ( Mountain TEXT default '' not null constraint geo_mountain_ibfk_3 references mountain on update cascade on delete cascade, Country TEXT default '' not null constraint geo_mountain_ibfk_1 references country on update cascade on delete cascade, Province TEXT default '' not null, primary key (Province, Country, Mountain), constraint geo_mountain_ibfk_2 foreign key (Province, Country) references province on update cascade on delete cascade ); CREATE TABLE IF NOT EXISTS "geo_river" ( River TEXT default '' not null constraint geo_river_ibfk_3 references river on update cascade on delete cascade, Country TEXT default '' not null constraint geo_river_ibfk_1 references country on update cascade on delete cascade, Province TEXT default '' not null, primary key (Province, Country, River), constraint geo_river_ibfk_2 foreign key (Province, Country) references province on update cascade on delete cascade ); CREATE TABLE IF NOT EXISTS "geo_sea" ( Sea TEXT default '' not null constraint geo_sea_ibfk_3 references sea on update cascade on delete cascade, Country TEXT default '' not null constraint geo_sea_ibfk_1 references country on update cascade on delete cascade, Province TEXT default '' not null, primary key (Province, Country, Sea), constraint geo_sea_ibfk_2 foreign key (Province, Country) references province on update cascade on delete cascade ); CREATE TABLE IF NOT EXISTS "geo_source" ( River TEXT default '' not null constraint geo_source_ibfk_3 references river on update cascade on delete cascade, Country TEXT default '' not null constraint geo_source_ibfk_1 references country on update cascade on delete cascade, Province TEXT default '' not null, primary key (Province, Country, River), constraint geo_source_ibfk_2 foreign key (Province, Country) references province on update cascade on delete cascade ); CREATE TABLE IF NOT EXISTS "island" ( Name TEXT default '' not null primary key, Islands TEXT, Area REAL, Height REAL, Type TEXT, Longitude REAL, Latitude REAL ); CREATE TABLE IF NOT EXISTS "islandIn" ( Island TEXT constraint islandIn_ibfk_4 references island on update cascade on delete cascade, Sea TEXT constraint islandIn_ibfk_3 references sea on update cascade on delete cascade, Lake TEXT constraint islandIn_ibfk_1 references lake on update cascade on delete cascade, River TEXT constraint islandIn_ibfk_2 references river on update cascade on delete cascade ); CREATE TABLE IF NOT EXISTS "isMember" ( Country TEXT default '' not null constraint isMember_ibfk_1 references country on update cascade on delete cascade, Organization TEXT default '' not null constraint isMember_ibfk_2 references organization on update cascade on delete cascade, Type TEXT default 'member', primary key (Country, Organization) ); CREATE TABLE IF NOT EXISTS "lake" ( Name TEXT default '' not null primary key, Area REAL, Depth REAL, Altitude REAL, Type TEXT, River TEXT, Longitude REAL, Latitude REAL ); CREATE TABLE IF NOT EXISTS "language" ( Country TEXT default '' not null constraint language_ibfk_1 references country on update cascade on delete cascade, Name TEXT default '' not null, Percentage REAL, primary key (Name, Country) ); CREATE TABLE IF NOT EXISTS "located" ( City TEXT, Province TEXT, Country TEXT constraint located_ibfk_1 references country on update cascade on delete cascade, River TEXT constraint located_ibfk_3 references river on update cascade on delete cascade, Lake TEXT constraint located_ibfk_4 references lake on update cascade on delete cascade, Sea TEXT constraint located_ibfk_5 references sea on update cascade on delete cascade, constraint located_ibfk_2 foreign key (City, Province) references city on update cascade on delete cascade, constraint located_ibfk_6 foreign key (Province, Country) references province on update cascade on delete cascade ); CREATE TABLE IF NOT EXISTS "locatedOn" ( City TEXT default '' not null, Province TEXT default '' not null, Country TEXT default '' not null constraint locatedOn_ibfk_1 references country on update cascade on delete cascade, Island TEXT default '' not null constraint locatedOn_ibfk_2 references island on update cascade on delete cascade, primary key (City, Province, Country, Island), constraint locatedOn_ibfk_3 foreign key (City, Province) references city on update cascade on delete cascade, constraint locatedOn_ibfk_4 foreign key (Province, Country) references province on update cascade on delete cascade ); CREATE TABLE IF NOT EXISTS "mergesWith" ( Sea1 TEXT default '' not null constraint mergesWith_ibfk_1 references sea on update cascade on delete cascade, Sea2 TEXT default '' not null constraint mergesWith_ibfk_2 references sea on update cascade on delete cascade, primary key (Sea1, Sea2) ); CREATE TABLE IF NOT EXISTS "mountain" ( Name TEXT default '' not null primary key, Mountains TEXT, Height REAL, Type TEXT, Longitude REAL, Latitude REAL ); CREATE TABLE IF NOT EXISTS "mountainOnIsland" ( Mountain TEXT default '' not null constraint mountainOnIsland_ibfk_2 references mountain on update cascade on delete cascade, Island TEXT default '' not null constraint mountainOnIsland_ibfk_1 references island on update cascade on delete cascade, primary key (Mountain, Island) ); CREATE TABLE IF NOT EXISTS "organization" ( Abbreviation TEXT not null primary key, Name TEXT not null constraint ix_organization_OrgNameUnique unique, City TEXT, Country TEXT constraint organization_ibfk_1 references country on update cascade on delete cascade, Province TEXT, Established DATE, constraint organization_ibfk_2 foreign key (City, Province) references city on update cascade on delete cascade, constraint organization_ibfk_3 foreign key (Province, Country) references province on update cascade on delete cascade ); CREATE TABLE IF NOT EXISTS "politics" ( Country TEXT default '' not null primary key constraint politics_ibfk_1 references country on update cascade on delete cascade, Independence DATE, Dependent TEXT constraint politics_ibfk_2 references country on update cascade on delete cascade, Government TEXT ); CREATE TABLE IF NOT EXISTS "population" ( Country TEXT default '' not null primary key constraint population_ibfk_1 references country on update cascade on delete cascade, Population_Growth REAL, Infant_Mortality REAL ); CREATE TABLE IF NOT EXISTS "province" ( Name TEXT not null, Country TEXT not null constraint province_ibfk_1 references country on update cascade on delete cascade, Population INTEGER, Area REAL, Capital TEXT, CapProv TEXT, primary key (Name, Country) ); CREATE TABLE IF NOT EXISTS "religion" ( Country TEXT default '' not null constraint religion_ibfk_1 references country on update cascade on delete cascade, Name TEXT default '' not null, Percentage REAL, primary key (Name, Country) ); CREATE TABLE IF NOT EXISTS "river" ( Name TEXT default '' not null primary key, River TEXT, Lake TEXT constraint river_ibfk_1 references lake on update cascade on delete cascade, Sea TEXT, Length REAL, SourceLongitude REAL, SourceLatitude REAL, Mountains TEXT, SourceAltitude REAL, EstuaryLongitude REAL, EstuaryLatitude REAL ); CREATE TABLE IF NOT EXISTS "sea" ( Name TEXT default '' not null primary key, Depth REAL ); CREATE TABLE IF NOT EXISTS "target" ( Country TEXT not null primary key constraint target_Country_fkey references country on update cascade on delete cascade, Target TEXT );
language_corpus
What is the average occurrence of the word "grec" on each Wikipedia page that has this word?
grec refers to word = 'grec'; AVG(occurrences where word = 'grec')
SELECT CAST(SUM(T2.occurrences) AS REAL) / COUNT(T1.wid) FROM words AS T1 INNER JOIN pages_words AS T2 ON T1.wid = T2.wid WHERE T1.word = 'grec'
CREATE TABLE langs(lid INTEGER PRIMARY KEY AUTOINCREMENT, lang TEXT UNIQUE, locale TEXT UNIQUE, pages INTEGER DEFAULT 0, -- total pages in this language words INTEGER DEFAULT 0); CREATE TABLE sqlite_sequence(name,seq); CREATE TABLE pages(pid INTEGER PRIMARY KEY AUTOINCREMENT, lid INTEGER REFERENCES langs(lid) ON UPDATE CASCADE ON DELETE CASCADE, page INTEGER DEFAULT NULL, -- wikipedia page id revision INTEGER DEFAULT NULL, -- wikipedia revision page id title TEXT, words INTEGER DEFAULT 0, -- number of different words in this page UNIQUE(lid,page,title)); CREATE TRIGGER ins_page AFTER INSERT ON pages FOR EACH ROW BEGIN UPDATE langs SET pages=pages+1 WHERE lid=NEW.lid; END; CREATE TRIGGER del_page AFTER DELETE ON pages FOR EACH ROW BEGIN UPDATE langs SET pages=pages-1 WHERE lid=OLD.lid; END; CREATE TABLE words(wid INTEGER PRIMARY KEY AUTOINCREMENT, word TEXT UNIQUE, occurrences INTEGER DEFAULT 0); CREATE TABLE langs_words(lid INTEGER REFERENCES langs(lid) ON UPDATE CASCADE ON DELETE CASCADE, wid INTEGER REFERENCES words(wid) ON UPDATE CASCADE ON DELETE CASCADE, occurrences INTEGER, -- repetitions of this word in this language PRIMARY KEY(lid,wid)) WITHOUT ROWID; CREATE TRIGGER ins_lang_word AFTER INSERT ON langs_words FOR EACH ROW BEGIN UPDATE langs SET words=words+1 WHERE lid=NEW.lid; END; CREATE TRIGGER del_lang_word AFTER DELETE ON langs_words FOR EACH ROW BEGIN UPDATE langs SET words=words-1 WHERE lid=OLD.lid; END; CREATE TABLE pages_words(pid INTEGER REFERENCES pages(pid) ON UPDATE CASCADE ON DELETE CASCADE, wid INTEGER REFERENCES words(wid) ON UPDATE CASCADE ON DELETE CASCADE, occurrences INTEGER DEFAULT 0, -- times this word appears into this page PRIMARY KEY(pid,wid)) WITHOUT ROWID; CREATE TRIGGER ins_page_word AFTER INSERT ON pages_words FOR EACH ROW BEGIN UPDATE pages SET words=words+1 WHERE pid=NEW.pid; END; CREATE TRIGGER del_page_word AFTER DELETE ON pages_words FOR EACH ROW BEGIN UPDATE pages SET words=words-1 WHERE pid=OLD.pid; END; CREATE TABLE biwords(lid INTEGER REFERENCES langs(lid) ON UPDATE CASCADE ON DELETE CASCADE, w1st INTEGER REFERENCES words(wid) ON UPDATE CASCADE ON DELETE CASCADE, w2nd INTEGER REFERENCES words(wid) ON UPDATE CASCADE ON DELETE CASCADE, occurrences INTEGER DEFAULT 0, -- times this pair appears in this language/page PRIMARY KEY(lid,w1st,w2nd)) WITHOUT ROWID;
retail_complains
Among the teenager clients who use Google account and Microsoft account, which group of client is more than the other?
teenager refers to 13 < age < = 19; Google account refers to email like '%@gmail.com'; Microsoft account refers to email like '%@outlook.com'
SELECT CASE WHEN SUM(CASE WHEN email LIKE '%@gmail.com' THEN 1 ELSE 0 END) > SUM(CASE WHEN email LIKE '%@outlook.com' THEN 1 ELSE 0 END) THEN 'Google account' ELSE 'Microsoft account' END FROM client WHERE age BETWEEN 13 AND 19
CREATE TABLE state ( StateCode TEXT constraint state_pk primary key, State TEXT, Region TEXT ); CREATE TABLE callcenterlogs ( "Date received" DATE, "Complaint ID" TEXT, "rand client" TEXT, phonefinal TEXT, "vru+line" TEXT, call_id INTEGER, priority INTEGER, type TEXT, outcome TEXT, server TEXT, ser_start TEXT, ser_exit TEXT, ser_time TEXT, primary key ("Complaint ID"), foreign key ("rand client") references client(client_id) ); CREATE TABLE client ( client_id TEXT primary key, sex TEXT, day INTEGER, month INTEGER, year INTEGER, age INTEGER, social TEXT, first TEXT, middle TEXT, last TEXT, phone TEXT, email TEXT, address_1 TEXT, address_2 TEXT, city TEXT, state TEXT, zipcode INTEGER, district_id INTEGER, foreign key (district_id) references district(district_id) ); CREATE TABLE district ( district_id INTEGER primary key, city TEXT, state_abbrev TEXT, division TEXT, foreign key (state_abbrev) references state(StateCode) ); CREATE TABLE events ( "Date received" DATE, Product TEXT, "Sub-product" TEXT, Issue TEXT, "Sub-issue" TEXT, "Consumer complaint narrative" TEXT, Tags TEXT, "Consumer consent provided?" TEXT, "Submitted via" TEXT, "Date sent to company" TEXT, "Company response to consumer" TEXT, "Timely response?" TEXT, "Consumer disputed?" TEXT, "Complaint ID" TEXT, Client_ID TEXT, primary key ("Complaint ID", Client_ID), foreign key ("Complaint ID") references callcenterlogs("Complaint ID"), foreign key (Client_ID) references client(client_id) ); CREATE TABLE reviews ( "Date" DATE primary key, Stars INTEGER, Reviews TEXT, Product TEXT, district_id INTEGER, foreign key (district_id) references district(district_id) );
authors
What is the title of the paper that was written by Cheng Huang and affiliated with Microsoft?
paper that was written by Cheng Huang refers to Name = 'Cheng Huang'; affiliated with Microsoft refers to Affiliation LIKE 'Microsoft %'
SELECT T1.Title FROM Paper AS T1 INNER JOIN PaperAuthor AS T2 ON T1.Id = T2.PaperId WHERE T2.Name = 'Cheng Huang' AND T2.Affiliation = 'Microsoft'
CREATE TABLE IF NOT EXISTS "Author" ( Id INTEGER constraint Author_pk primary key, Name TEXT, Affiliation TEXT ); CREATE TABLE IF NOT EXISTS "Conference" ( Id INTEGER constraint Conference_pk primary key, ShortName TEXT, FullName TEXT, HomePage TEXT ); CREATE TABLE IF NOT EXISTS "Journal" ( Id INTEGER constraint Journal_pk primary key, ShortName TEXT, FullName TEXT, HomePage TEXT ); CREATE TABLE Paper ( Id INTEGER primary key, Title TEXT, Year INTEGER, ConferenceId INTEGER, JournalId INTEGER, Keyword TEXT, foreign key (ConferenceId) references Conference(Id), foreign key (JournalId) references Journal(Id) ); CREATE TABLE PaperAuthor ( PaperId INTEGER, AuthorId INTEGER, Name TEXT, Affiliation TEXT, foreign key (PaperId) references Paper(Id), foreign key (AuthorId) references Author(Id) );
car_retails
How many Sales Rep who are working in Tokyo? List out email and full name of those employees.
Sales Rep is a job title; Tokyo is a city; full name = firstName+lastName;
SELECT T1.firstName, T1.lastName, T1.email FROM employees AS T1 INNER JOIN offices AS T2 ON T1.officeCode = T2.officeCode WHERE T2.city = 'Tokyo' AND T1.jobTitle = 'Sales Rep'
CREATE TABLE offices ( officeCode TEXT not null primary key, city TEXT not null, phone TEXT not null, addressLine1 TEXT not null, addressLine2 TEXT, state TEXT, country TEXT not null, postalCode TEXT not null, territory TEXT not null ); CREATE TABLE employees ( employeeNumber INTEGER not null primary key, lastName TEXT not null, firstName TEXT not null, extension TEXT not null, email TEXT not null, officeCode TEXT not null, reportsTo INTEGER, jobTitle TEXT not null, foreign key (officeCode) references offices(officeCode), foreign key (reportsTo) references employees(employeeNumber) ); CREATE TABLE customers ( customerNumber INTEGER not null primary key, customerName TEXT not null, contactLastName TEXT not null, contactFirstName TEXT not null, phone TEXT not null, addressLine1 TEXT not null, addressLine2 TEXT, city TEXT not null, state TEXT, postalCode TEXT, country TEXT not null, salesRepEmployeeNumber INTEGER, creditLimit REAL, foreign key (salesRepEmployeeNumber) references employees(employeeNumber) ); CREATE TABLE orders ( orderNumber INTEGER not null primary key, orderDate DATE not null, requiredDate DATE not null, shippedDate DATE, status TEXT not null, comments TEXT, customerNumber INTEGER not null, foreign key (customerNumber) references customers(customerNumber) ); CREATE TABLE payments ( customerNumber INTEGER not null, checkNumber TEXT not null, paymentDate DATE not null, amount REAL not null, primary key (customerNumber, checkNumber), foreign key (customerNumber) references customers(customerNumber) ); CREATE TABLE productlines ( productLine TEXT not null primary key, textDescription TEXT, htmlDescription TEXT, image BLOB ); CREATE TABLE products ( productCode TEXT not null primary key, productName TEXT not null, productLine TEXT not null, productScale TEXT not null, productVendor TEXT not null, productDescription TEXT not null, quantityInStock INTEGER not null, buyPrice REAL not null, MSRP REAL not null, foreign key (productLine) references productlines(productLine) ); CREATE TABLE IF NOT EXISTS "orderdetails" ( orderNumber INTEGER not null references orders, productCode TEXT not null references products, quantityOrdered INTEGER not null, priceEach REAL not null, orderLineNumber INTEGER not null, primary key (orderNumber, productCode) );
computer_student
Among the faculty affiliated professor, how many professors teaches professional or master/undergraduate courses?
faculty affiliated professor refers to professor = 1 and hasPosition = 'Faculty_aff'; professional or master/undergraduate courses refers to courseLevel = 'Level_500'
SELECT COUNT(*) FROM person AS T1 INNER JOIN taughtBy AS T2 ON T1.p_id = T2.p_id INNER JOIN course AS T3 ON T3.course_id = T2.course_id WHERE T1.hasPosition = 'Faculty_aff' AND T1.professor = 1 AND T3.courseLevel = 'Level_500'
CREATE TABLE course ( course_id INTEGER constraint course_pk primary key, courseLevel TEXT ); CREATE TABLE person ( p_id INTEGER constraint person_pk primary key, professor INTEGER, student INTEGER, hasPosition TEXT, inPhase TEXT, yearsInProgram TEXT ); CREATE TABLE IF NOT EXISTS "advisedBy" ( p_id INTEGER, p_id_dummy INTEGER, constraint advisedBy_pk primary key (p_id, p_id_dummy), constraint advisedBy_person_p_id_p_id_fk foreign key (p_id, p_id_dummy) references person (p_id, p_id) ); CREATE TABLE taughtBy ( course_id INTEGER, p_id INTEGER, primary key (course_id, p_id), foreign key (p_id) references person(p_id), foreign key (course_id) references course(course_id) );
regional_sales
What are the names of the sales teams that have served to customer Apotheca, Ltd?
name of sales team refers to Sales Team; 'Apotheca, Ltd' is the Customer Names
SELECT DISTINCT T3.`Sales Team` FROM Customers AS T1 INNER JOIN `Sales Orders` AS T2 ON T2._CustomerID = T1.CustomerID INNER JOIN `Sales Team` AS T3 ON T3.SalesTeamID = T2._SalesTeamID WHERE T1.`Customer Names` = 'Apotheca, Ltd'
CREATE TABLE Customers ( CustomerID INTEGER constraint Customers_pk primary key, "Customer Names" TEXT ); CREATE TABLE Products ( ProductID INTEGER constraint Products_pk primary key, "Product Name" TEXT ); CREATE TABLE Regions ( StateCode TEXT constraint Regions_pk primary key, State TEXT, Region TEXT ); CREATE TABLE IF NOT EXISTS "Sales Team" ( SalesTeamID INTEGER constraint "Sales Team_pk" primary key, "Sales Team" TEXT, Region TEXT ); CREATE TABLE IF NOT EXISTS "Store Locations" ( StoreID INTEGER constraint "Store Locations_pk" primary key, "City Name" TEXT, County TEXT, StateCode TEXT constraint "Store Locations_Regions_StateCode_fk" references Regions(StateCode), State TEXT, Type TEXT, Latitude REAL, Longitude REAL, AreaCode INTEGER, Population INTEGER, "Household Income" INTEGER, "Median Income" INTEGER, "Land Area" INTEGER, "Water Area" INTEGER, "Time Zone" TEXT ); CREATE TABLE IF NOT EXISTS "Sales Orders" ( OrderNumber TEXT constraint "Sales Orders_pk" primary key, "Sales Channel" TEXT, WarehouseCode TEXT, ProcuredDate TEXT, OrderDate TEXT, ShipDate TEXT, DeliveryDate TEXT, CurrencyCode TEXT, _SalesTeamID INTEGER constraint "Sales Orders_Sales Team_SalesTeamID_fk" references "Sales Team"(SalesTeamID), _CustomerID INTEGER constraint "Sales Orders_Customers_CustomerID_fk" references Customers(CustomerID), _StoreID INTEGER constraint "Sales Orders_Store Locations_StoreID_fk" references "Store Locations"(StoreID), _ProductID INTEGER constraint "Sales Orders_Products_ProductID_fk" references Products(ProductID), "Order Quantity" INTEGER, "Discount Applied" REAL, "Unit Price" TEXT, "Unit Cost" TEXT );
soccer_2016
List down the DOB of players who received the "man of the match" award.
SELECT T2.DOB FROM Match AS T1 INNER JOIN Player AS T2 ON T2.Player_Id = T1.Man_of_the_Match
CREATE TABLE Batting_Style ( Batting_Id INTEGER primary key, Batting_hand TEXT ); CREATE TABLE Bowling_Style ( Bowling_Id INTEGER primary key, Bowling_skill TEXT ); CREATE TABLE City ( City_Id INTEGER primary key, City_Name TEXT, Country_id INTEGER ); CREATE TABLE Country ( Country_Id INTEGER primary key, Country_Name TEXT, foreign key (Country_Id) references Country(Country_Id) ); CREATE TABLE Extra_Type ( Extra_Id INTEGER primary key, Extra_Name TEXT ); CREATE TABLE Extra_Runs ( Match_Id INTEGER, Over_Id INTEGER, Ball_Id INTEGER, Extra_Type_Id INTEGER, Extra_Runs INTEGER, Innings_No INTEGER, primary key (Match_Id, Over_Id, Ball_Id, Innings_No), foreign key (Extra_Type_Id) references Extra_Type(Extra_Id) ); CREATE TABLE Out_Type ( Out_Id INTEGER primary key, Out_Name TEXT ); CREATE TABLE Outcome ( Outcome_Id INTEGER primary key, Outcome_Type TEXT ); CREATE TABLE Player ( Player_Id INTEGER primary key, Player_Name TEXT, DOB DATE, Batting_hand INTEGER, Bowling_skill INTEGER, Country_Name INTEGER, foreign key (Batting_hand) references Batting_Style(Batting_Id), foreign key (Bowling_skill) references Bowling_Style(Bowling_Id), foreign key (Country_Name) references Country(Country_Id) ); CREATE TABLE Rolee ( Role_Id INTEGER primary key, Role_Desc TEXT ); CREATE TABLE Season ( Season_Id INTEGER primary key, Man_of_the_Series INTEGER, Orange_Cap INTEGER, Purple_Cap INTEGER, Season_Year INTEGER ); CREATE TABLE Team ( Team_Id INTEGER primary key, Team_Name TEXT ); CREATE TABLE Toss_Decision ( Toss_Id INTEGER primary key, Toss_Name TEXT ); CREATE TABLE Umpire ( Umpire_Id INTEGER primary key, Umpire_Name TEXT, Umpire_Country INTEGER, foreign key (Umpire_Country) references Country(Country_Id) ); CREATE TABLE Venue ( Venue_Id INTEGER primary key, Venue_Name TEXT, City_Id INTEGER, foreign key (City_Id) references City(City_Id) ); CREATE TABLE Win_By ( Win_Id INTEGER primary key, Win_Type TEXT ); CREATE TABLE Match ( Match_Id INTEGER primary key, Team_1 INTEGER, Team_2 INTEGER, Match_Date DATE, Season_Id INTEGER, Venue_Id INTEGER, Toss_Winner INTEGER, Toss_Decide INTEGER, Win_Type INTEGER, Win_Margin INTEGER, Outcome_type INTEGER, Match_Winner INTEGER, Man_of_the_Match INTEGER, foreign key (Team_1) references Team(Team_Id), foreign key (Team_2) references Team(Team_Id), foreign key (Season_Id) references Season(Season_Id), foreign key (Venue_Id) references Venue(Venue_Id), foreign key (Toss_Winner) references Team(Team_Id), foreign key (Toss_Decide) references Toss_Decision(Toss_Id), foreign key (Win_Type) references Win_By(Win_Id), foreign key (Outcome_type) references Out_Type(Out_Id), foreign key (Match_Winner) references Team(Team_Id), foreign key (Man_of_the_Match) references Player(Player_Id) ); CREATE TABLE Ball_by_Ball ( Match_Id INTEGER, Over_Id INTEGER, Ball_Id INTEGER, Innings_No INTEGER, Team_Batting INTEGER, Team_Bowling INTEGER, Striker_Batting_Position INTEGER, Striker INTEGER, Non_Striker INTEGER, Bowler INTEGER, primary key (Match_Id, Over_Id, Ball_Id, Innings_No), foreign key (Match_Id) references Match(Match_Id) ); CREATE TABLE Batsman_Scored ( Match_Id INTEGER, Over_Id INTEGER, Ball_Id INTEGER, Runs_Scored INTEGER, Innings_No INTEGER, primary key (Match_Id, Over_Id, Ball_Id, Innings_No), foreign key (Match_Id) references Match(Match_Id) ); CREATE TABLE Player_Match ( Match_Id INTEGER, Player_Id INTEGER, Role_Id INTEGER, Team_Id INTEGER, primary key (Match_Id, Player_Id, Role_Id), foreign key (Match_Id) references Match(Match_Id), foreign key (Player_Id) references Player(Player_Id), foreign key (Team_Id) references Team(Team_Id), foreign key (Role_Id) references Rolee(Role_Id) ); CREATE TABLE Wicket_Taken ( Match_Id INTEGER, Over_Id INTEGER, Ball_Id INTEGER, Player_Out INTEGER, Kind_Out INTEGER, Fielders INTEGER, Innings_No INTEGER, primary key (Match_Id, Over_Id, Ball_Id, Innings_No), foreign key (Match_Id) references Match(Match_Id), foreign key (Player_Out) references Player(Player_Id), foreign key (Kind_Out) references Out_Type(Out_Id), foreign key (Fielders) references Player(Player_Id) );
regional_sales
Describe the ID, city and region of the stores which are in Allen country.
ID refers to StoreID;
SELECT DISTINCT T2.StoreID, T2.`City Name`, T1.Region FROM Regions AS T1 INNER JOIN `Store Locations` AS T2 ON T2.StateCode = T1.StateCode WHERE T2.County = 'Allen County'
CREATE TABLE Customers ( CustomerID INTEGER constraint Customers_pk primary key, "Customer Names" TEXT ); CREATE TABLE Products ( ProductID INTEGER constraint Products_pk primary key, "Product Name" TEXT ); CREATE TABLE Regions ( StateCode TEXT constraint Regions_pk primary key, State TEXT, Region TEXT ); CREATE TABLE IF NOT EXISTS "Sales Team" ( SalesTeamID INTEGER constraint "Sales Team_pk" primary key, "Sales Team" TEXT, Region TEXT ); CREATE TABLE IF NOT EXISTS "Store Locations" ( StoreID INTEGER constraint "Store Locations_pk" primary key, "City Name" TEXT, County TEXT, StateCode TEXT constraint "Store Locations_Regions_StateCode_fk" references Regions(StateCode), State TEXT, Type TEXT, Latitude REAL, Longitude REAL, AreaCode INTEGER, Population INTEGER, "Household Income" INTEGER, "Median Income" INTEGER, "Land Area" INTEGER, "Water Area" INTEGER, "Time Zone" TEXT ); CREATE TABLE IF NOT EXISTS "Sales Orders" ( OrderNumber TEXT constraint "Sales Orders_pk" primary key, "Sales Channel" TEXT, WarehouseCode TEXT, ProcuredDate TEXT, OrderDate TEXT, ShipDate TEXT, DeliveryDate TEXT, CurrencyCode TEXT, _SalesTeamID INTEGER constraint "Sales Orders_Sales Team_SalesTeamID_fk" references "Sales Team"(SalesTeamID), _CustomerID INTEGER constraint "Sales Orders_Customers_CustomerID_fk" references Customers(CustomerID), _StoreID INTEGER constraint "Sales Orders_Store Locations_StoreID_fk" references "Store Locations"(StoreID), _ProductID INTEGER constraint "Sales Orders_Products_ProductID_fk" references Products(ProductID), "Order Quantity" INTEGER, "Discount Applied" REAL, "Unit Price" TEXT, "Unit Cost" TEXT );
sales_in_weather
Which items from store 1 have the highest units sold during rainy day?
store 1 refers to store_nbr = 1; highest unit sold refers to Max(units); during rainy day refers to codesum like '%'||'RA'||'%'; item refers to item_nbr
SELECT T2.item_nbr FROM weather AS T1 INNER JOIN sales_in_weather AS T2 ON T1.`date` = T2.`date` INNER JOIN relation AS T3 ON T2.store_nbr = T3.store_nbr AND T1.station_nbr = T3.station_nbr WHERE T2.store_nbr = 1 AND T1.codesum LIKE '%' OR 'RA' OR '%' GROUP BY T2.item_nbr ORDER BY T2.units DESC LIMIT 1
CREATE TABLE sales_in_weather ( date DATE, store_nbr INTEGER, item_nbr INTEGER, units INTEGER, primary key (store_nbr, date, item_nbr) ); CREATE TABLE weather ( station_nbr INTEGER, date DATE, tmax INTEGER, tmin INTEGER, tavg INTEGER, depart INTEGER, dewpoint INTEGER, wetbulb INTEGER, heat INTEGER, cool INTEGER, sunrise TEXT, sunset TEXT, codesum TEXT, snowfall REAL, preciptotal REAL, stnpressure REAL, sealevel REAL, resultspeed REAL, resultdir INTEGER, avgspeed REAL, primary key (station_nbr, date) ); CREATE TABLE relation ( store_nbr INTEGER primary key, station_nbr INTEGER, foreign key (store_nbr) references sales_in_weather(store_nbr), foreign key (station_nbr) references weather(station_nbr) );
bike_share_1
How many bike stations were installed in San Jose in 2014? Indicate the names of the stations.
San Jose is the name of the city; 2014 refers to installation_date between '1/1/2014' and '12/31/2014';
SELECT SUM(CASE WHEN city = 'San Jose' AND SUBSTR(installation_date, -4) = '2014' THEN 1 ELSE 0 END) FROM station UNION SELECT name FROM station WHERE city = 'San Jose' AND SUBSTR(installation_date, -4) = '2014'
CREATE TABLE IF NOT EXISTS "station" ( id INTEGER not null primary key, name TEXT, lat REAL, long REAL, dock_count INTEGER, city TEXT, installation_date TEXT ); CREATE TABLE IF NOT EXISTS "status" ( station_id INTEGER, bikes_available INTEGER, docks_available INTEGER, time TEXT ); CREATE TABLE IF NOT EXISTS "trip" ( id INTEGER not null primary key, duration INTEGER, start_date TEXT, start_station_name TEXT, start_station_id INTEGER, end_date TEXT, end_station_name TEXT, end_station_id INTEGER, bike_id INTEGER, subscription_type TEXT, zip_code INTEGER ); CREATE TABLE IF NOT EXISTS "weather" ( date TEXT, max_temperature_f INTEGER, mean_temperature_f INTEGER, min_temperature_f INTEGER, max_dew_point_f INTEGER, mean_dew_point_f INTEGER, min_dew_point_f INTEGER, max_humidity INTEGER, mean_humidity INTEGER, min_humidity INTEGER, max_sea_level_pressure_inches REAL, mean_sea_level_pressure_inches REAL, min_sea_level_pressure_inches REAL, max_visibility_miles INTEGER, mean_visibility_miles INTEGER, min_visibility_miles INTEGER, max_wind_Speed_mph INTEGER, mean_wind_speed_mph INTEGER, max_gust_speed_mph INTEGER, precipitation_inches TEXT, cloud_cover INTEGER, events TEXT, wind_dir_degrees INTEGER, zip_code TEXT );
music_tracker
Among id from 10 to 50. Which artist tagged as "new.york" has the most downloads?
Among id from 10 to 50 refers to id between 10 and 50; tag = 'new.york'; the most downloads refer to MAX(totalSnatched);
SELECT T1.artist FROM torrents AS T1 INNER JOIN tags AS T2 ON T1.id = T2.id WHERE T1.id BETWEEN 10 AND 50 AND T2.tag LIKE 'new.york' ORDER BY T1.totalSnatched DESC LIMIT 1
CREATE TABLE IF NOT EXISTS "torrents" ( groupName TEXT, totalSnatched INTEGER, artist TEXT, groupYear INTEGER, releaseType TEXT, groupId INTEGER, id INTEGER constraint torrents_pk primary key ); CREATE TABLE IF NOT EXISTS "tags" ( "index" INTEGER constraint tags_pk primary key, id INTEGER constraint tags_torrents_id_fk references torrents, tag TEXT ); CREATE INDEX ix_tags_index on tags ("index");
university
In 2016, what is the name of the university in Australia with the highest score in Citations criteria?
In 2016 refers to year = 2016; name of the university refers to university_name; in Australia refers to country_name = 'Australia'; in Citations criteria refers to criteria_name = 'Citations'; highest score refers to MAX(score)
SELECT T3.university_name FROM ranking_criteria AS T1 INNER JOIN university_ranking_year AS T2 ON T1.id = T2.ranking_criteria_id INNER JOIN university AS T3 ON T3.id = T2.university_id INNER JOIN country AS T4 ON T4.id = T3.country_id WHERE T1.criteria_name = 'Citations' AND T2.year = 2016 AND T1.id = 4 AND T4.country_name = 'Australia' ORDER BY T2.score DESC LIMIT 1
CREATE TABLE country ( id INTEGER not null primary key, country_name TEXT default NULL ); CREATE TABLE ranking_system ( id INTEGER not null primary key, system_name TEXT default NULL ); CREATE TABLE ranking_criteria ( id INTEGER not null primary key, ranking_system_id INTEGER default NULL, criteria_name TEXT default NULL, foreign key (ranking_system_id) references ranking_system(id) ); CREATE TABLE university ( id INTEGER not null primary key, country_id INTEGER default NULL, university_name TEXT default NULL, foreign key (country_id) references country(id) ); CREATE TABLE university_ranking_year ( university_id INTEGER default NULL, ranking_criteria_id INTEGER default NULL, year INTEGER default NULL, score INTEGER default NULL, foreign key (ranking_criteria_id) references ranking_criteria(id), foreign key (university_id) references university(id) ); CREATE TABLE university_year ( university_id INTEGER default NULL, year INTEGER default NULL, num_students INTEGER default NULL, student_staff_ratio REAL default NULL, pct_international_students INTEGER default NULL, pct_female_students INTEGER default NULL, foreign key (university_id) references university(id) );
disney
Who is the hero character of the Disney movie directed by Will Finn?
Will Finn refers to director = 'Will Finn';
SELECT T1.hero FROM characters AS T1 INNER JOIN director AS T2 ON T2.name = T1.movie_title WHERE T2.director = 'Will Finn'
CREATE TABLE characters ( movie_title TEXT primary key, release_date TEXT, hero TEXT, villian TEXT, song TEXT, foreign key (hero) references "voice-actors"(character) ); CREATE TABLE director ( name TEXT primary key, director TEXT, foreign key (name) references characters(movie_title) ); CREATE TABLE movies_total_gross ( movie_title TEXT, release_date TEXT, genre TEXT, MPAA_rating TEXT, total_gross TEXT, inflation_adjusted_gross TEXT, primary key (movie_title, release_date), foreign key (movie_title) references characters(movie_title) ); CREATE TABLE revenue ( Year INTEGER primary key, "Studio Entertainment[NI 1]" REAL, "Disney Consumer Products[NI 2]" REAL, "Disney Interactive[NI 3][Rev 1]" INTEGER, "Walt Disney Parks and Resorts" REAL, "Disney Media Networks" TEXT, Total INTEGER ); CREATE TABLE IF NOT EXISTS "voice-actors" ( character TEXT primary key, "voice-actor" TEXT, movie TEXT, foreign key (movie) references characters(movie_title) );
image_and_language
How many object classes are there in the database?
object classes refers to OBJ_CLASS
SELECT COUNT(OBJ_CLASS_ID) FROM OBJ_CLASSES
CREATE TABLE ATT_CLASSES ( ATT_CLASS_ID INTEGER default 0 not null primary key, ATT_CLASS TEXT not null ); CREATE TABLE OBJ_CLASSES ( OBJ_CLASS_ID INTEGER default 0 not null primary key, OBJ_CLASS TEXT not null ); CREATE TABLE IMG_OBJ ( IMG_ID INTEGER default 0 not null, OBJ_SAMPLE_ID INTEGER default 0 not null, OBJ_CLASS_ID INTEGER null, X INTEGER null, Y INTEGER null, W INTEGER null, H INTEGER null, primary key (IMG_ID, OBJ_SAMPLE_ID), foreign key (OBJ_CLASS_ID) references OBJ_CLASSES (OBJ_CLASS_ID) ); CREATE TABLE IMG_OBJ_ATT ( IMG_ID INTEGER default 0 not null, ATT_CLASS_ID INTEGER default 0 not null, OBJ_SAMPLE_ID INTEGER default 0 not null, primary key (IMG_ID, ATT_CLASS_ID, OBJ_SAMPLE_ID), foreign key (ATT_CLASS_ID) references ATT_CLASSES (ATT_CLASS_ID), foreign key (IMG_ID, OBJ_SAMPLE_ID) references IMG_OBJ (IMG_ID, OBJ_SAMPLE_ID) ); CREATE TABLE PRED_CLASSES ( PRED_CLASS_ID INTEGER default 0 not null primary key, PRED_CLASS TEXT not null ); CREATE TABLE IMG_REL ( IMG_ID INTEGER default 0 not null, PRED_CLASS_ID INTEGER default 0 not null, OBJ1_SAMPLE_ID INTEGER default 0 not null, OBJ2_SAMPLE_ID INTEGER default 0 not null, primary key (IMG_ID, PRED_CLASS_ID, OBJ1_SAMPLE_ID, OBJ2_SAMPLE_ID), foreign key (PRED_CLASS_ID) references PRED_CLASSES (PRED_CLASS_ID), foreign key (IMG_ID, OBJ1_SAMPLE_ID) references IMG_OBJ (IMG_ID, OBJ_SAMPLE_ID), foreign key (IMG_ID, OBJ2_SAMPLE_ID) references IMG_OBJ (IMG_ID, OBJ_SAMPLE_ID) );
talkingdata
Among the devices on which an event happened on 2016/5/1, how many of them are used by a male user?
on 2016/5/1 refers to timestamp = '2016-05-01'; male refers to gender = 'M';
SELECT COUNT(T1.device_id) FROM events AS T1 INNER JOIN gender_age AS T2 ON T1.device_id = T2.device_id WHERE T1.timestamp = '2016-05-01' AND T2.gender = 'M'
CREATE TABLE `app_all` ( `app_id` INTEGER NOT NULL, PRIMARY KEY (`app_id`) ); CREATE TABLE `app_events` ( `event_id` INTEGER NOT NULL, `app_id` INTEGER NOT NULL, `is_installed` INTEGER NOT NULL, `is_active` INTEGER NOT NULL, PRIMARY KEY (`event_id`,`app_id`), FOREIGN KEY (`event_id`) REFERENCES `events` (`event_id`) ON DELETE CASCADE ON UPDATE CASCADE ); CREATE TABLE `app_events_relevant` ( `event_id` INTEGER NOT NULL, `app_id` INTEGER NOT NULL, `is_installed` INTEGER DEFAULT NULL, `is_active` INTEGER DEFAULT NULL, PRIMARY KEY (`event_id`,`app_id`), FOREIGN KEY (`event_id`) REFERENCES `events_relevant` (`event_id`) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (`app_id`) REFERENCES `app_all` (`app_id`) ON DELETE CASCADE ON UPDATE CASCADE ); CREATE TABLE `app_labels` ( `app_id` INTEGER NOT NULL, `label_id` INTEGER NOT NULL, FOREIGN KEY (`label_id`) REFERENCES `label_categories` (`label_id`) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (`app_id`) REFERENCES `app_all` (`app_id`) ON DELETE CASCADE ON UPDATE CASCADE ); CREATE TABLE `events` ( `event_id` INTEGER NOT NULL, `device_id` INTEGER DEFAULT NULL, `timestamp` DATETIME DEFAULT NULL, `longitude` REAL DEFAULT NULL, `latitude` REAL DEFAULT NULL, PRIMARY KEY (`event_id`) ); CREATE TABLE `events_relevant` ( `event_id` INTEGER NOT NULL, `device_id` INTEGER DEFAULT NULL, `timestamp` DATETIME NOT NULL, `longitude` REAL NOT NULL, `latitude` REAL NOT NULL, PRIMARY KEY (`event_id`), FOREIGN KEY (`device_id`) REFERENCES `gender_age` (`device_id`) ON DELETE CASCADE ON UPDATE CASCADE ); CREATE TABLE `gender_age` ( `device_id` INTEGER NOT NULL, `gender` TEXT DEFAULT NULL, `age` INTEGER DEFAULT NULL, `group` TEXT DEFAULT NULL, PRIMARY KEY (`device_id`), FOREIGN KEY (`device_id`) REFERENCES `phone_brand_device_model2` (`device_id`) ON DELETE CASCADE ON UPDATE CASCADE ); CREATE TABLE `gender_age_test` ( `device_id` INTEGER NOT NULL, PRIMARY KEY (`device_id`) ); CREATE TABLE `gender_age_train` ( `device_id` INTEGER NOT NULL, `gender` TEXT DEFAULT NULL, `age` INTEGER DEFAULT NULL, `group` TEXT DEFAULT NULL, PRIMARY KEY (`device_id`) ); CREATE TABLE `label_categories` ( `label_id` INTEGER NOT NULL, `category` TEXT DEFAULT NULL, PRIMARY KEY (`label_id`) ); CREATE TABLE `phone_brand_device_model2` ( `device_id` INTEGER NOT NULL, `phone_brand` TEXT NOT NULL, `device_model` TEXT NOT NULL, PRIMARY KEY (`device_id`,`phone_brand`,`device_model`) ); CREATE TABLE `sample_submission` ( `device_id` INTEGER NOT NULL, `F23-` REAL DEFAULT NULL, `F24-26` REAL DEFAULT NULL, `F27-28` REAL DEFAULT NULL, `F29-32` REAL DEFAULT NULL, `F33-42` REAL DEFAULT NULL, `F43+` REAL DEFAULT NULL, `M22-` REAL DEFAULT NULL, `M23-26` REAL DEFAULT NULL, `M27-28` REAL DEFAULT NULL, `M29-31` REAL DEFAULT NULL, `M32-38` REAL DEFAULT NULL, `M39+` REAL DEFAULT NULL, PRIMARY KEY (`device_id`) );
law_episode
Give me the years and episode IDs in which Constantine Makris was the winner of the Television Silver Gavel Award at the American Bar Association Silver Gavel Awards for Media and the Arts for two consecutive years.
the winner refers to result = 'Winner'; the Television refers to award = 'Television'; Silver Gavel Award refers to award_category = 'Silver Gavel Award'; the American Bar Association Silver Gavel Awards for Media and the Arts refers to organization = 'American Bar Association Silver Gavel Awards for Media and the Arts'
SELECT t3.years, t3.episode_id FROM ( SELECT DISTINCT T2.year AS years, T2.episode_id, row_number() OVER (PARTITION BY T2.episode_id ORDER BY T2.year) AS rm FROM Person AS T1 INNER JOIN Award AS T2 ON T1.person_id = T2.person_id WHERE T2.award = 'Television' AND T2.award_category = 'Silver Gavel Award' AND T1.name = 'Constantine Makris' AND T2.result = 'Winner' AND T2.organization = 'American Bar Association Silver Gavel Awards for Media and the Arts' ) AS T3 GROUP BY t3.episode_id HAVING COUNT(t3.years - t3.rm) >= 2
CREATE TABLE Episode ( episode_id TEXT primary key, series TEXT, season INTEGER, episode INTEGER, number_in_series INTEGER, title TEXT, summary TEXT, air_date DATE, episode_image TEXT, rating REAL, votes INTEGER ); CREATE TABLE Keyword ( episode_id TEXT, keyword TEXT, primary key (episode_id, keyword), foreign key (episode_id) references Episode(episode_id) ); CREATE TABLE Person ( person_id TEXT primary key, name TEXT, birthdate DATE, birth_name TEXT, birth_place TEXT, birth_region TEXT, birth_country TEXT, height_meters REAL, nickname TEXT ); CREATE TABLE Award ( award_id INTEGER primary key, organization TEXT, year INTEGER, award_category TEXT, award TEXT, series TEXT, episode_id TEXT, person_id TEXT, role TEXT, result TEXT, foreign key (episode_id) references Episode(episode_id), foreign key (person_id) references Person(person_id) ); CREATE TABLE Credit ( episode_id TEXT, person_id TEXT, category TEXT, role TEXT, credited TEXT, primary key (episode_id, person_id), foreign key (episode_id) references Episode(episode_id), foreign key (person_id) references Person(person_id) ); CREATE TABLE Vote ( episode_id TEXT, stars INTEGER, votes INTEGER, percent REAL, foreign key (episode_id) references Episode(episode_id) );
beer_factory
For the customer who leaves the review content of "Tastes like Australia.", when was his/her first purchase date?
review content of "Tastes like Australia." refers to Review = 'Tastes like Australia.';
SELECT T1.FirstPurchaseDate FROM customers AS T1 INNER JOIN rootbeerreview AS T2 ON T1.CustomerID = T2.CustomerID WHERE T2.Review = 'Tastes like Australia.'
CREATE TABLE customers ( CustomerID INTEGER primary key, First TEXT, Last TEXT, StreetAddress TEXT, City TEXT, State TEXT, ZipCode INTEGER, Email TEXT, PhoneNumber TEXT, FirstPurchaseDate DATE, SubscribedToEmailList TEXT, Gender TEXT ); CREATE TABLE geolocation ( LocationID INTEGER primary key, Latitude REAL, Longitude REAL, foreign key (LocationID) references location(LocationID) ); CREATE TABLE location ( LocationID INTEGER primary key, LocationName TEXT, StreetAddress TEXT, City TEXT, State TEXT, ZipCode INTEGER, foreign key (LocationID) references geolocation(LocationID) ); CREATE TABLE rootbeerbrand ( BrandID INTEGER primary key, BrandName TEXT, FirstBrewedYear INTEGER, BreweryName TEXT, City TEXT, State TEXT, Country TEXT, Description TEXT, CaneSugar TEXT, CornSyrup TEXT, Honey TEXT, ArtificialSweetener TEXT, Caffeinated TEXT, Alcoholic TEXT, AvailableInCans TEXT, AvailableInBottles TEXT, AvailableInKegs TEXT, Website TEXT, FacebookPage TEXT, Twitter TEXT, WholesaleCost REAL, CurrentRetailPrice REAL ); CREATE TABLE rootbeer ( RootBeerID INTEGER primary key, BrandID INTEGER, ContainerType TEXT, LocationID INTEGER, PurchaseDate DATE, foreign key (LocationID) references geolocation(LocationID), foreign key (LocationID) references location(LocationID), foreign key (BrandID) references rootbeerbrand(BrandID) ); CREATE TABLE rootbeerreview ( CustomerID INTEGER, BrandID INTEGER, StarRating INTEGER, ReviewDate DATE, Review TEXT, primary key (CustomerID, BrandID), foreign key (CustomerID) references customers(CustomerID), foreign key (BrandID) references rootbeerbrand(BrandID) ); CREATE TABLE IF NOT EXISTS "transaction" ( TransactionID INTEGER primary key, CreditCardNumber INTEGER, CustomerID INTEGER, TransactionDate DATE, CreditCardType TEXT, LocationID INTEGER, RootBeerID INTEGER, PurchasePrice REAL, foreign key (CustomerID) references customers(CustomerID), foreign key (LocationID) references location(LocationID), foreign key (RootBeerID) references rootbeer(RootBeerID) );
student_loan
List the longest duration of absense for a student enlisted in the fire department.
longest duration of absence refers to MAX(month); department refers to organ; organ = 'fire_department';
SELECT T1.month FROM longest_absense_from_school AS T1 INNER JOIN enlist AS T2 ON T1.name = T2.name WHERE T2.organ = 'fire_department' ORDER BY T1.month DESC LIMIT 1
CREATE TABLE bool ( "name" TEXT default '' not null primary key ); CREATE TABLE person ( "name" TEXT default '' not null primary key ); CREATE TABLE disabled ( "name" TEXT default '' not null primary key, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE enlist ( "name" TEXT not null, organ TEXT not null, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE filed_for_bankrupcy ( "name" TEXT default '' not null primary key, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE longest_absense_from_school ( "name" TEXT default '' not null primary key, "month" INTEGER default 0 null, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE male ( "name" TEXT default '' not null primary key, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE no_payment_due ( "name" TEXT default '' not null primary key, bool TEXT null, foreign key ("name") references person ("name") on update cascade on delete cascade, foreign key (bool) references bool ("name") on update cascade on delete cascade ); CREATE TABLE unemployed ( "name" TEXT default '' not null primary key, foreign key ("name") references person ("name") on update cascade on delete cascade ); CREATE TABLE `enrolled` ( `name` TEXT NOT NULL, `school` TEXT NOT NULL, `month` INTEGER NOT NULL DEFAULT 0, PRIMARY KEY (`name`,`school`), FOREIGN KEY (`name`) REFERENCES `person` (`name`) ON DELETE CASCADE ON UPDATE CASCADE );