question
stringlengths
24
325
sql
stringlengths
30
804
db_id
stringclasses
63 values
prompt
stringlengths
308
18.9k
question_id
int64
167
9.43k
difficulty
stringclasses
1 value
Which date has the most ordered quantity? What is the total order quantity on that day?
SELECT ord_date, SUM(qty) FROM sales GROUP BY ord_date ORDER BY SUM(qty) DESC LIMIT 1
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Which date has the most ordered quantity? What is the total order quantity on that day?
167
What is the title with the most ordered quantity in year 1992?
SELECT T2.title FROM sales AS T1 INNER JOIN titles AS T2 ON T1.title_id = T2.title_id WHERE STRFTIME('%Y', T1.ord_date) = '1992' ORDER BY T1.qty DESC LIMIT 1
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # What is the title with the most ordered quantity in year 1992?
168
List the title, price and publication date for all sales with 'ON invoice' payment terms.
SELECT T2.title, T2.price, T2.pubdate FROM sales AS T1 INNER JOIN titles AS T2 ON T1.title_id = T2.title_id WHERE T1.payterms = 'ON invoice'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # List the title, price and publication date for all sales with 'ON invoice' payment terms.
169
What is the title that have at least 10% royalty without minimum range amount.
SELECT T1.title FROM titles AS T1 INNER JOIN roysched AS T2 ON T1.title_id = T2.title_id WHERE T2.lorange = 0 AND T2.royalty >= 10
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # What is the title that have at least 10% royalty without minimum range amount.
170
State the title and royalty percentage for title ID BU2075 between 10000 to 50000 range.
SELECT T1.title, T2.royalty FROM titles AS T1 INNER JOIN roysched AS T2 ON T1.title_id = T2.title_id WHERE T2.lorange > 10000 AND T2.hirange < 50000 AND T1.title_ID = 'BU2075'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # State the title and royalty percentage for title ID BU2075 between 10000 to 50000 range.
171
Among the titles with royalty percentage, which title has the greatest royalty percentage. State it's minimum range to enjoy this royalty percentage.
SELECT T1.title, T2.lorange FROM titles AS T1 INNER JOIN roysched AS T2 ON T1.title_id = T2.title_id ORDER BY T2.royalty DESC LIMIT 1
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Among the titles with royalty percentage, which title has the greatest royalty percentage. State it's minimum range to enjoy this royalty percentage.
172
Provide a list of titles together with its publisher name for all publishers located in the USA.
SELECT T1.title, T2.pub_name FROM titles AS T1 INNER JOIN publishers AS T2 ON T1.pub_id = T2.pub_id WHERE T2.country = 'USA'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Provide a list of titles together with its publisher name for all publishers located in the USA.
173
State the royalty percentage for the most year to date sale title within the 20000 range.
SELECT MAX(T1.ytd_sales) FROM titles AS T1 INNER JOIN roysched AS T2 ON T1.title_id = T2.title_id WHERE T2.lorange > 20000 AND T2.hirange < 20000
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # State the royalty percentage for the most year to date sale title within the 20000 range.
174
List all titles published in year 1991. Also provide notes details of the title and the publisher's name.
SELECT T1.title, T1.notes, T2.pub_name FROM titles AS T1 INNER JOIN publishers AS T2 ON T1.pub_id = T2.pub_id WHERE STRFTIME('%Y', T1.pubdate) = '1991'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # List all titles published in year 1991. Also provide notes details of the title and the publisher's name.
175
List all titles with sales of quantity more than 20 and store located in the CA state.
SELECT T1.title, T2.qty FROM titles AS T1 INNER JOIN sales AS T2 ON T1.title_id = T2.title_id INNER JOIN stores AS T3 ON T2.stor_id = T3.stor_id WHERE T2.qty > 20 AND T3.state = 'CA'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # List all titles with sales of quantity more than 20 and store located in the CA state.
176
Name the store with the highest quantity in sales? What is the least quantity title from the store's sale?
SELECT T3.stor_id, T2.title FROM sales AS T1 INNER JOIN titles AS T2 ON T1.title_id = T2.title_id INNER JOIN stores AS T3 ON T3.stor_id = T1.stor_id WHERE T3.stor_id = ( SELECT stor_id FROM sales GROUP BY stor_id ORDER BY SUM(qty) DESC LIMIT 1 ) GROUP BY T3.stor_id, T2.title ORDER BY SUM(T1.qty) ASC LIMIT 1
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Name the store with the highest quantity in sales? What is the least quantity title from the store's sale?
177
Name the title and publisher for title ID BU 2075. Provide all the royalty percentage for all ranges.
SELECT T1.title, T3.pub_name, T2.lorange, T2.hirange, T2.royalty FROM titles AS T1 INNER JOIN roysched AS T2 ON T1.title_id = T2.title_id INNER JOIN publishers AS T3 ON T1.pub_id = T3.pub_id WHERE T1.title_id = 'BU2075'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Name the title and publisher for title ID BU 2075. Provide all the royalty percentage for all ranges.
178
Name the store with ID 7066 and calculate the percentage of the the quantity ordered that were on 'Net 30' payment terms.
SELECT T2.stor_name , CAST(SUM(CASE WHEN payterms = 'Net 30' THEN qty ELSE 0 END) AS REAL) * 100 / SUM(qty) FROM sales AS T1 INNER JOIN stores AS T2 ON T1.stor_id = T2.stor_id WHERE T1.stor_id = '7066' GROUP BY T2.stor_name
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Name the store with ID 7066 and calculate the percentage of the the quantity ordered that were on 'Net 30' payment terms.
179
State the publisher name for publisher ID 877? Calculate its average year to date sales.
SELECT T2.pub_name, AVG(T1.ytd_sales) FROM titles AS T1 INNER JOIN publishers AS T2 ON T1.pub_id = T2.pub_id WHERE T1.pub_id = '0877' GROUP BY T2.pub_name
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # State the publisher name for publisher ID 877? Calculate its average year to date sales.
180
Name all employees who were hired before year 1990.
SELECT fname, lname FROM employee WHERE STRFTIME('%Y', hire_date) < '1990'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Name all employees who were hired before year 1990.
181
Which employee has the lowest job level. State the first name, last name and when he /she was hired.
SELECT fname, lname, hire_date FROM employee ORDER BY job_lvl LIMIT 1
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Which employee has the lowest job level. State the first name, last name and when he /she was hired.
182
In which year has the most hired employees?
SELECT STRFTIME('%Y', hire_date) FROM employee GROUP BY STRFTIME('%Y', hire_date) ORDER BY COUNT(emp_id) DESC LIMIT 1
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # In which year has the most hired employees?
183
List all employees who are at the maximum level in their job designation.
SELECT T1.fname, T1.lname FROM employee AS T1 INNER JOIN jobs AS T2 ON T1.job_id = T2.job_id WHERE T1.job_lvl = T2.max_lvl
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # List all employees who are at the maximum level in their job designation.
184
Name the Chief Executive Officer and when he/she was hired.
SELECT T1.fname, T1.lname, T1.hire_date FROM employee AS T1 INNER JOIN jobs AS T2 ON T1.job_id = T2.job_id WHERE T2.job_desc = 'Chief Financial Officier'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Name the Chief Executive Officer and when he/she was hired.
185
Who are the employees working for publisher not located in USA? State the employee's name and publisher name.
SELECT T1.fname, T1.lname, T2.pub_name FROM employee AS T1 INNER JOIN publishers AS T2 ON T1.pub_id = T2.pub_id WHERE T2.country != 'USA'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Who are the employees working for publisher not located in USA? State the employee's name and publisher name.
186
List all employees working for publisher 'GGG&G'. State their name and job description.
SELECT T1.fname, T1.lname, T3.job_desc FROM employee AS T1 INNER JOIN publishers AS T2 ON T1.pub_id = T2.pub_id INNER JOIN jobs AS T3 ON T1.job_id = T3.job_id WHERE T2.pub_name = 'GGG&G'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # List all employees working for publisher 'GGG&G'. State their name and job description.
187
For each publisher, state the type of titles they published order by the publisher name.
SELECT DISTINCT T2.pub_name, T1.type FROM titles AS T1 INNER JOIN publishers AS T2 ON T1.pub_id = T2.pub_id ORDER BY T2.pub_name
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # For each publisher, state the type of titles they published order by the publisher name.
188
Name the publisher which has the most titles published in 1991.
SELECT T2.pub_name FROM titles AS T1 INNER JOIN publishers AS T2 ON T1.pub_id = T2.pub_id WHERE STRFTIME('%Y', T1.pubdate) = '1991' GROUP BY T1.pub_id, T2.pub_name ORDER BY COUNT(T1.title_id) DESC LIMIT 1
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Name the publisher which has the most titles published in 1991.
189
Name the title with the highest price published by 'Binnet & Hardley'.
SELECT T1.title FROM titles AS T1 INNER JOIN publishers AS T2 ON T1.pub_id = T2.pub_id WHERE T2.pub_name = 'Binnet & Hardley' ORDER BY T1.price DESC LIMIT 1
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Name the title with the highest price published by 'Binnet & Hardley'.
190
Among all employees, who have job level greater than 200. State the employee name and job description.
SELECT T1.fname, T1.lname, T2.job_desc FROM employee AS T1 INNER JOIN jobs AS T2 ON T1.job_id = T2.job_id WHERE T1.job_lvl > 200
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Among all employees, who have job level greater than 200. State the employee name and job description.
191
Name all the authors for all business titles.
SELECT T3.au_fname, T3.au_lname FROM titles AS T1 INNER JOIN titleauthor AS T2 ON T1.title_id = T2.title_id INNER JOIN authors AS T3 ON T2.au_id = T3.au_id WHERE T1.type = 'business'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Name all the authors for all business titles.
192
List all the titles and year to date sales by author who are not on contract.
SELECT T1.title_id, T1.ytd_sales FROM titles AS T1 INNER JOIN titleauthor AS T2 ON T1.title_id = T2.title_id INNER JOIN authors AS T3 ON T2.au_id = T3.au_id WHERE T3.contract = 0
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # List all the titles and year to date sales by author who are not on contract.
193
For all authors from CA who are not on contract, which title of his/hers has the most year to date sales.
SELECT T1.title FROM titles AS T1 INNER JOIN titleauthor AS T2 ON T1.title_id = T2.title_id INNER JOIN authors AS T3 ON T2.au_id = T3.au_id WHERE T3.contract = 0 AND T3.state = 'CA' ORDER BY T1.ytd_sales DESC LIMIT 1
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # For all authors from CA who are not on contract, which title of his/hers has the most year to date sales.
194
Name all the authors for 'Sushi, Anyone?'.
SELECT T3.au_fname, T3.au_lname FROM titles AS T1 INNER JOIN titleauthor AS T2 ON T1.title_id = T2.title_id INNER JOIN authors AS T3 ON T2.au_id = T3.au_id WHERE T1.title = 'Sushi, Anyone?'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Name all the authors for 'Sushi, Anyone?'.
195
Calculate the percentage of the employees who are Editor or Designer?
SELECT CAST(SUM(CASE WHEN T2.job_desc IN ('Editor', 'Designer') THEN 1 ELSE 0 END) AS REAL) * 100 / COUNT(T1.job_id) FROM employee AS T1 INNER JOIN jobs AS T2 ON T1.job_id = T2.job_id
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Calculate the percentage of the employees who are Editor or Designer?
196
List all titles which have year to date sales higher than the average order by pubisher name.
SELECT T1.title FROM titles AS T1 INNER JOIN publishers AS T2 ON T1.pub_id = T2.pub_id WHERE T1.ytd_sales > ( SELECT AVG(ytd_sales) FROM titles )
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # List all titles which have year to date sales higher than the average order by pubisher name.
197
How many publishers are in the USA?
SELECT COUNT(pub_id) FROM publishers WHERE country = 'USA'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # How many publishers are in the USA?
198
What is the publisher's information of New Moon Books?
SELECT T1.pr_info FROM pub_info AS T1 INNER JOIN publishers AS T2 ON T1.pub_id = T2.pub_id WHERE T2.pub_name = 'New Moon Books'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # What is the publisher's information of New Moon Books?
199
Please list the first names of the employees who work as Managing Editor.
SELECT T1.fname FROM employee AS T1 INNER JOIN jobs AS T2 ON T1.job_id = T2.job_id WHERE T2.job_desc = 'Managing Editor'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Please list the first names of the employees who work as Managing Editor.
200
What is the highest level of job to get to for the employee who got hired the earliest?
SELECT T2.max_lvl FROM employee AS T1 INNER JOIN jobs AS T2 ON T1.job_id = T2.job_id ORDER BY T1.hire_date LIMIT 1
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # What is the highest level of job to get to for the employee who got hired the earliest?
201
In which city is the store with the highest total sales quantity located?
SELECT T2.city FROM sales AS T1 INNER JOIN stores AS T2 ON T1.stor_id = T2.stor_id GROUP BY T2.city ORDER BY SUM(T1.qty) DESC LIMIT 1
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # In which city is the store with the highest total sales quantity located?
202
What is the price of the book that sells the best?
SELECT T2.price FROM sales AS T1 INNER JOIN titles AS T2 ON T1.title_id = T2.title_id ORDER BY T1.qty DESC LIMIT 1
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # What is the price of the book that sells the best?
203
Please list the stores that ordered the book "Life Without Fear".
SELECT T2.stor_name FROM sales AS T1 INNER JOIN stores AS T2 ON T1.stor_id = T2.stor_id INNER JOIN titles AS T3 ON T1.title_id = T3.title_id WHERE T3.title = 'Life Without Fear'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Please list the stores that ordered the book "Life Without Fear".
204
Among the stores that have ordered the book "Life Without Fear", how many of them are located in Massachusetts?
SELECT COUNT(T1.stor_id) FROM sales AS T1 INNER JOIN stores AS T2 ON T1.stor_id = T2.stor_id INNER JOIN titles AS T3 ON T1.title_id = T3.title_id WHERE T2.state = 'Massachusetts'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Among the stores that have ordered the book "Life Without Fear", how many of them are located in Massachusetts?
205
In which country is the publisher of the book "Life Without Fear" located?
SELECT T2.country FROM titles AS T1 INNER JOIN publishers AS T2 ON T1.pub_id = T2.pub_id WHERE T1.title = 'Life Without Fear'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # In which country is the publisher of the book "Life Without Fear" located?
206
What is the publisher that has published the most expensive book?
SELECT T2.pub_name FROM titles AS T1 INNER JOIN publishers AS T2 ON T1.pub_id = T2.pub_id ORDER BY T1.price DESC LIMIT 1
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # What is the publisher that has published the most expensive book?
207
Among the publishers in the USA, how many of them have published books that are over $15?
SELECT COUNT(DISTINCT T1.pub_id) FROM titles AS T1 INNER JOIN publishers AS T2 ON T1.pub_id = T2.pub_id WHERE T2.country = 'USA' AND T1.price > 15
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Among the publishers in the USA, how many of them have published books that are over $15?
208
Please give more detailed information about the first three books that sell the best.
SELECT T1.notes FROM titles AS T1 INNER JOIN sales AS T2 ON T1.title_id = T2.title_id ORDER BY T2.qty DESC LIMIT 3
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Please give more detailed information about the first three books that sell the best.
209
How many books on business have the bookstores in Massachusetts ordered?
SELECT SUM(T1.qty) FROM sales AS T1 INNER JOIN stores AS T2 ON T1.stor_id = T2.stor_id INNER JOIN titles AS T3 ON T1.title_id = T3.title_id WHERE T2.state = 'Massachusetts' AND T3.type = 'business'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # How many books on business have the bookstores in Massachusetts ordered?
210
What is the average quantity of each order for the book "Life Without Fear"?
SELECT CAST(SUM(T2.qty) AS REAL) / COUNT(T1.title_id) FROM titles AS T1 INNER JOIN sales AS T2 ON T1.title_id = T2.title_id WHERE T1.title = 'Life Without Fear'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # What is the average quantity of each order for the book "Life Without Fear"?
211
What is the average level employees working as Managing Editor are at? How many levels are there between the average level and the highest level?
SELECT AVG(T2.job_lvl), T1.max_lvl - AVG(T2.job_lvl) FROM jobs AS T1 INNER JOIN employee AS T2 ON T1.job_id = T2.job_id WHERE T1.job_desc = 'Managing Editor' GROUP BY T2.job_id, T1.max_lvl
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # What is the average level employees working as Managing Editor are at? How many levels are there between the average level and the highest level?
212
Which one is the cheapest business book?
SELECT title FROM titles WHERE type = 'business' ORDER BY price LIMIT 1
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Which one is the cheapest business book?
213
Which type of book had the most pre-paid amount?
SELECT type FROM titles ORDER BY advance DESC LIMIT 1
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Which type of book had the most pre-paid amount?
214
What's the royalty for the bestseller book?
SELECT royalty FROM titles ORDER BY ytd_sales DESC LIMIT 1
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # What's the royalty for the bestseller book?
215
Which job level is O'Rourke at?
SELECT job_lvl FROM employee WHERE lname = 'O''Rourke'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Which job level is O'Rourke at?
216
Show me the employ id of the highest employee who doesn't have a middle name.
SELECT emp_id FROM employee WHERE minit = '' ORDER BY job_lvl DESC LIMIT 1
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Show me the employ id of the highest employee who doesn't have a middle name.
217
Is the author of "Sushi, Anyone?" on the contract?
SELECT T1.contract FROM authors AS T1 INNER JOIN titleauthor AS T2 ON T1.au_id = T2.au_id INNER JOIN titles AS T3 ON T2.title_id = T3.title_id WHERE T3.title = 'Sushi, Anyone?'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Is the author of "Sushi, Anyone?" on the contract?
218
Which publisher had the highest job level? Give his/her full name.
SELECT T1.fname, T1.minit, T1.lname FROM employee AS T1 INNER JOIN jobs AS T2 ON T1.job_id = T2.job_id ORDER BY T1.job_lvl DESC LIMIT 1
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Which publisher had the highest job level? Give his/her full name.
219
What's Pedro S Afonso's job title?
SELECT T2.job_desc FROM employee AS T1 INNER JOIN jobs AS T2 ON T1.job_id = T2.job_id WHERE T1.fname = 'Pedro' AND T1.minit = 'S' AND T1.lname = 'Afonso'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # What's Pedro S Afonso's job title?
220
How many levels are there left for Diego W Roel to reach if he/she could go to the max level for his/her position?
SELECT T2.max_lvl - T1.job_lvl FROM employee AS T1 INNER JOIN jobs AS T2 ON T1.job_id = T2.job_id WHERE T1.fname = 'Diego' AND T1.minit = 'W' AND T1.lname = 'Roel'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # How many levels are there left for Diego W Roel to reach if he/she could go to the max level for his/her position?
221
What's on the notes for the order happened on 1994/9/14?
SELECT T1.notes FROM titles AS T1 INNER JOIN sales AS T2 ON T1.title_id = T2.title_id WHERE STRFTIME('%Y-%m-%d', T2.ord_date) = '1994-09-14'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # What's on the notes for the order happened on 1994/9/14?
222
List the type of the book for the order which was sold on 1993/5/29.
SELECT DISTINCT T1.type FROM titles AS T1 INNER JOIN sales AS T2 ON T1.title_id = T2.title_id WHERE STRFTIME('%Y-%m-%d', T2.ord_date) = '1993-05-29'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # List the type of the book for the order which was sold on 1993/5/29.
223
Tell me about the information of the French publisher.
SELECT T1.pr_info FROM pub_info AS T1 INNER JOIN publishers AS T2 ON T1.pub_id = T2.pub_id WHERE T2.country = 'France'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Tell me about the information of the French publisher.
224
What's the publisher of the book "Silicon Valley Gastronomic Treats"? Give the publisher's name.
SELECT T2.pub_name FROM titles AS T1 INNER JOIN publishers AS T2 ON T1.pub_id = T2.pub_id WHERE T1.title = 'Silicon Valley Gastronomic Treats'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # What's the publisher of the book "Silicon Valley Gastronomic Treats"? Give the publisher's name.
225
Which city did Victoria P Ashworth work in?
SELECT T2.city FROM employee AS T1 INNER JOIN publishers AS T2 ON T1.pub_id = T2.pub_id WHERE T1.fname = 'Victoria' AND T1.minit = 'P' AND T1.lname = 'Ashworth'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Which city did Victoria P Ashworth work in?
226
How many sales did the store in Remulade make?
SELECT COUNT(T1.ord_num) FROM sales AS T1 INNER JOIN stores AS T2 ON T1.stor_id = T2.stor_id WHERE T2.city = 'Remulade'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # How many sales did the store in Remulade make?
227
For the quantities, what percent more did the store in Fremont sell than the store in Portland in 1993?
SELECT CAST(SUM(CASE WHEN T2.city = 'Fremont' THEN qty END) - SUM(CASE WHEN T2.city = 'Portland' THEN qty END) AS REAL) * 100 / SUM(CASE WHEN T2.city = 'Fremont' THEN qty END) FROM sales AS T1 INNER JOIN stores AS T2 ON T1.stor_id = T2.stor_id WHERE STRFTIME('%Y', T1.ord_date) = '1993'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # For the quantities, what percent more did the store in Fremont sell than the store in Portland in 1993?
228
Among all the employees, how many percent more for the publishers than designers?
SELECT CAST(SUM(CASE WHEN T2.job_desc = 'publisher' THEN 1 ELSE 0 END) - SUM(CASE WHEN T2.job_desc = 'designer' THEN 1 ELSE 0 END) AS REAL) * 100 / COUNT(T1.job_id) FROM employee AS T1 INNER JOIN jobs AS T2 ON T1.job_id = T2.job_id
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Among all the employees, how many percent more for the publishers than designers?
229
Find and list the full name of employees who were hired between 1990 and 1995. Also, arrange them in the descending order of job level.
SELECT fname, minit, lname FROM employee WHERE STRFTIME('%Y', hire_date) BETWEEN '1990' AND '1995' ORDER BY job_lvl DESC
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Find and list the full name of employees who were hired between 1990 and 1995. Also, arrange them in the descending order of job level.
230
Which titles has above average royalty rate? Give those title's name, type and price?
SELECT DISTINCT T1.title, T1.type, T1.price FROM titles AS T1 INNER JOIN roysched AS T2 ON T1.title_id = T2.title_id WHERE T2.royalty > ( SELECT CAST(SUM(royalty) AS REAL) / COUNT(title_id) FROM roysched )
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Which titles has above average royalty rate? Give those title's name, type and price?
231
In 1994 which title had less order quanty than the average order quantity? Find the title name, type and price.
SELECT DISTINCT T1.title, T1.type, T1.price FROM titles AS T1 INNER JOIN sales AS T2 ON T1.title_id = T2.title_id WHERE T2.ord_date LIKE '1994%' AND T2.Qty < ( SELECT CAST(SUM(T4.qty) AS REAL) / COUNT(T3.title_id) FROM titles AS T3 INNER JOIN sales AS T4 ON T3.title_id = T4.title_id )
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # In 1994 which title had less order quanty than the average order quantity? Find the title name, type and price.
232
List the title name, type, and price of the titles published by New Moon Books. Arrange the list in ascending order of price.
SELECT T1.title, T1.type, T1.price FROM titles AS T1 INNER JOIN publishers AS T2 ON T1.pub_id = T2.pub_id WHERE T2.pub_name = 'New Moon Books' ORDER BY T1.price
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # List the title name, type, and price of the titles published by New Moon Books. Arrange the list in ascending order of price.
233
In the books published by US publishers, which book has the highest royalty? List these books in the descending order of royalty.
SELECT T1.title FROM titles AS T1 INNER JOIN publishers AS T2 ON T1.pub_id = T2.pub_id INNER JOIN roysched AS T3 ON T1.title_id = T3.title_id WHERE T2.country = 'USA' ORDER BY T1.royalty DESC
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # In the books published by US publishers, which book has the highest royalty? List these books in the descending order of royalty.
234
Find the difference between the average royalty of titles published by US and non US publishers?
SELECT (CAST(SUM(CASE WHEN T2.country = 'USA' THEN T1.royalty ELSE 0 END) AS REAL) / SUM(CASE WHEN T2.country = 'USA' THEN 1 ELSE 0 END)) - (CAST(SUM(CASE WHEN T2.country != 'USA' THEN T1.royalty ELSE 0 END) AS REAL) / SUM(CASE WHEN T2.country != 'USA' THEN 1 ELSE 0 END)) FROM titles AS T1 INNER JOIN publishers AS T2 ON T1.pub_id = T2.pub_id INNER JOIN roysched AS T3 ON T1.title_id = T3.title_id
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Find the difference between the average royalty of titles published by US and non US publishers?
235
Calculate the average level difference between the Marketing editors hired by the US and non-US publishers?
SELECT (CAST(SUM(CASE WHEN T1.country = 'USA' THEN job_lvl ELSE 0 END) AS REAL) / SUM(CASE WHEN T1.country = 'USA' THEN 1 ELSE 0 END)) - (CAST(SUM(CASE WHEN T1.country != 'USA' THEN job_lvl ELSE 0 END) AS REAL) / SUM(CASE WHEN T1.country != 'USA' THEN 1 ELSE 0 END)) FROM publishers AS T1 INNER JOIN employee AS T2 ON T1.pub_id = T2.pub_id INNER JOIN jobs AS T3 ON T2.job_id = T3.job_id WHERE T3.job_desc = 'Managing Editor'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Calculate the average level difference between the Marketing editors hired by the US and non-US publishers?
236
Which title is about helpful hints on how to use your electronic resources, which publisher published it and what is the price of this book?
SELECT T1.title, T2.pub_name, T1.price FROM titles AS T1 INNER JOIN publishers AS T2 ON T1.pub_id = T2.pub_id WHERE T1.notes = 'Helpful hints on how to use your electronic resources to the best advantage.'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Which title is about helpful hints on how to use your electronic resources, which publisher published it and what is the price of this book?
237
Of the titles, which title is about the Carefully researched study of the effects of strong emotions on the body, which state-based publisher published this book, and what is the year-to-date sale?
SELECT T1.title, T2.pub_name, T1.ytd_sales FROM titles AS T1 INNER JOIN publishers AS T2 ON T1.pub_id = T2.pub_id WHERE T1.notes = 'Carefully researched study of the effects of strong emotions on the body. Metabolic charts included.'
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Of the titles, which title is about the Carefully researched study of the effects of strong emotions on the body, which state-based publisher published this book, and what is the year-to-date sale?
238
Name the top five titles that sold more than average and list them in descending order of the number of sales in California stores?
SELECT T1.title FROM titles AS T1 INNER JOIN sales AS T2 ON T1.title_id = T2.title_id INNER JOIN publishers AS T3 ON T1.pub_id = T3.pub_id WHERE T2.qty > ( SELECT CAST(SUM(qty) AS REAL) / COUNT(title_id) FROM sales ) AND T3.state = 'CA' ORDER BY T2.qty DESC LIMIT 5
book_publishing_company
Database Schema: authors (au_id text, au_lname text, au_fname text, phone text, address text, city text, state text, zip text, contract text, , PRIMARY KEY(au_id), ) #discounts (discounttype text, stor_id text, lowqty integer, highqty integer, discount real, , , FOREIGN KEY(stor_id) REFERENCES stores(stor_id)) #employee (emp_id text, fname text, minit text, lname text, job_id integer, job_lvl integer, pub_id text, hire_date datetime, , PRIMARY KEY(emp_id), FOREIGN KEY(job_id) REFERENCES jobs(job_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #jobs (job_id integer, job_desc text, min_lvl integer, max_lvl integer, , PRIMARY KEY(job_id), ) #pub_info (pub_id text, logo blob, pr_info text, , PRIMARY KEY(pub_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) #publishers (pub_id text, pub_name text, city text, state text, country text, , PRIMARY KEY(pub_id), ) #roysched (title_id text, lorange integer, hirange integer, royalty integer, , , FOREIGN KEY(title_id) REFERENCES titles(title_id)) #sales (stor_id text, ord_num text, ord_date datetime, qty integer, payterms text, title_id text, , PRIMARY KEY(stor_id), PRIMARY KEY(ord_num), PRIMARY KEY(title_id), FOREIGN KEY(stor_id) REFERENCES stores(stor_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #stores (stor_id text, stor_name text, stor_address text, city text, state text, zip text, , PRIMARY KEY(stor_id), ) #titleauthor (au_id text, title_id text, au_ord integer, royaltyper integer, , PRIMARY KEY(au_id), PRIMARY KEY(title_id), FOREIGN KEY(au_id) REFERENCES authors(au_id), FOREIGN KEY(title_id) REFERENCES titles(title_id)) #titles (title_id text, title text, type text, pub_id text, price real, advance real, royalty integer, ytd_sales integer, notes text, pubdate datetime, , PRIMARY KEY(title_id), FOREIGN KEY(pub_id) REFERENCES publishers(pub_id)) # Name the top five titles that sold more than average and list them in descending order of the number of sales in California stores?
239
On which day was the most verbose complaint received?
SELECT `Date received` FROM callcenterlogs WHERE ser_time = ( SELECT MAX(ser_time) FROM callcenterlogs )
retail_complains
Database Schema: 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)) #client (client_id text, 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, , PRIMARY KEY(client_id), FOREIGN KEY(district_id) REFERENCES district(district_id)) #district (district_id integer, city text, state_abbrev text, division text, , PRIMARY KEY(district_id), FOREIGN KEY(state_abbrev) REFERENCES state(StateCode)) #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), PRIMARY KEY(Client_ID), FOREIGN KEY(Client_ID) REFERENCES client(client_id), FOREIGN KEY(Complaint ID) REFERENCES callcenterlogs(Complaint ID)) #reviews (Date date, Stars integer, Reviews text, Product text, district_id integer, , PRIMARY KEY(Date), FOREIGN KEY(district_id) REFERENCES district(district_id)) #state (StateCode text, State text, Region text, , PRIMARY KEY(StateCode), ) # On which day was the most verbose complaint received?
240
When did the earliest complaint start on 2017/3/22?
SELECT MIN(ser_time) FROM callcenterlogs WHERE `Date received` = '2017-03-22'
retail_complains
Database Schema: 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)) #client (client_id text, 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, , PRIMARY KEY(client_id), FOREIGN KEY(district_id) REFERENCES district(district_id)) #district (district_id integer, city text, state_abbrev text, division text, , PRIMARY KEY(district_id), FOREIGN KEY(state_abbrev) REFERENCES state(StateCode)) #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), PRIMARY KEY(Client_ID), FOREIGN KEY(Client_ID) REFERENCES client(client_id), FOREIGN KEY(Complaint ID) REFERENCES callcenterlogs(Complaint ID)) #reviews (Date date, Stars integer, Reviews text, Product text, district_id integer, , PRIMARY KEY(Date), FOREIGN KEY(district_id) REFERENCES district(district_id)) #state (StateCode text, State text, Region text, , PRIMARY KEY(StateCode), ) # When did the earliest complaint start on 2017/3/22?
241
Which complaint is more urgent, complaint ID CR2400594 or ID CR2405641?
SELECT CASE WHEN SUM(CASE WHEN `Complaint ID` = 'CR2400594' THEN priority END) > SUM(CASE WHEN `Complaint ID` = 'CR2405641' THEN priority END) THEN 'CR2400594' ELSE 'CR2405641' END FROM callcenterlogs
retail_complains
Database Schema: 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)) #client (client_id text, 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, , PRIMARY KEY(client_id), FOREIGN KEY(district_id) REFERENCES district(district_id)) #district (district_id integer, city text, state_abbrev text, division text, , PRIMARY KEY(district_id), FOREIGN KEY(state_abbrev) REFERENCES state(StateCode)) #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), PRIMARY KEY(Client_ID), FOREIGN KEY(Client_ID) REFERENCES client(client_id), FOREIGN KEY(Complaint ID) REFERENCES callcenterlogs(Complaint ID)) #reviews (Date date, Stars integer, Reviews text, Product text, district_id integer, , PRIMARY KEY(Date), FOREIGN KEY(district_id) REFERENCES district(district_id)) #state (StateCode text, State text, Region text, , PRIMARY KEY(StateCode), ) # Which complaint is more urgent, complaint ID CR2400594 or ID CR2405641?
242
Please list the full names of all the male clients born after the year 1990.
SELECT first, middle, last FROM client WHERE year > 1990
retail_complains
Database Schema: 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)) #client (client_id text, 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, , PRIMARY KEY(client_id), FOREIGN KEY(district_id) REFERENCES district(district_id)) #district (district_id integer, city text, state_abbrev text, division text, , PRIMARY KEY(district_id), FOREIGN KEY(state_abbrev) REFERENCES state(StateCode)) #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), PRIMARY KEY(Client_ID), FOREIGN KEY(Client_ID) REFERENCES client(client_id), FOREIGN KEY(Complaint ID) REFERENCES callcenterlogs(Complaint ID)) #reviews (Date date, Stars integer, Reviews text, Product text, district_id integer, , PRIMARY KEY(Date), FOREIGN KEY(district_id) REFERENCES district(district_id)) #state (StateCode text, State text, Region text, , PRIMARY KEY(StateCode), ) # Please list the full names of all the male clients born after the year 1990.
243
How many complaints have the client Diesel Galloway filed?
SELECT COUNT(T1.client_id) FROM client AS T1 INNER JOIN events AS T2 ON T1.client_id = T2.Client_ID WHERE T1.first = 'Diesel' AND T1.last = 'Galloway'
retail_complains
Database Schema: 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)) #client (client_id text, 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, , PRIMARY KEY(client_id), FOREIGN KEY(district_id) REFERENCES district(district_id)) #district (district_id integer, city text, state_abbrev text, division text, , PRIMARY KEY(district_id), FOREIGN KEY(state_abbrev) REFERENCES state(StateCode)) #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), PRIMARY KEY(Client_ID), FOREIGN KEY(Client_ID) REFERENCES client(client_id), FOREIGN KEY(Complaint ID) REFERENCES callcenterlogs(Complaint ID)) #reviews (Date date, Stars integer, Reviews text, Product text, district_id integer, , PRIMARY KEY(Date), FOREIGN KEY(district_id) REFERENCES district(district_id)) #state (StateCode text, State text, Region text, , PRIMARY KEY(StateCode), ) # How many complaints have the client Diesel Galloway filed?
244
What is the detailed product of the complaint filed by Diesel Galloway on 2014/7/3?
SELECT T2.`Sub-product` FROM client AS T1 INNER JOIN events AS T2 ON T1.client_id = T2.Client_ID WHERE T1.first = 'Diesel' AND T1.last = 'Galloway' AND T2.`Date received` = '2014-07-03'
retail_complains
Database Schema: 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)) #client (client_id text, 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, , PRIMARY KEY(client_id), FOREIGN KEY(district_id) REFERENCES district(district_id)) #district (district_id integer, city text, state_abbrev text, division text, , PRIMARY KEY(district_id), FOREIGN KEY(state_abbrev) REFERENCES state(StateCode)) #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), PRIMARY KEY(Client_ID), FOREIGN KEY(Client_ID) REFERENCES client(client_id), FOREIGN KEY(Complaint ID) REFERENCES callcenterlogs(Complaint ID)) #reviews (Date date, Stars integer, Reviews text, Product text, district_id integer, , PRIMARY KEY(Date), FOREIGN KEY(district_id) REFERENCES district(district_id)) #state (StateCode text, State text, Region text, , PRIMARY KEY(StateCode), ) # What is the detailed product of the complaint filed by Diesel Galloway on 2014/7/3?
245
Was the tag in the complaint filed by Matthew Pierce on 2016/10/28 approved by himself?
SELECT CASE WHEN T2.`Consumer consent provided?` IN (NULL, 'N/A', 'Empty') THEN 'No' ELSE 'Yes' END FROM client AS T1 INNER JOIN events AS T2 ON T1.client_id = T2.Client_ID WHERE T1.first = 'Matthew' AND T1.last = 'Pierce' AND T2.`Date received` = '2016-10-28'
retail_complains
Database Schema: 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)) #client (client_id text, 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, , PRIMARY KEY(client_id), FOREIGN KEY(district_id) REFERENCES district(district_id)) #district (district_id integer, city text, state_abbrev text, division text, , PRIMARY KEY(district_id), FOREIGN KEY(state_abbrev) REFERENCES state(StateCode)) #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), PRIMARY KEY(Client_ID), FOREIGN KEY(Client_ID) REFERENCES client(client_id), FOREIGN KEY(Complaint ID) REFERENCES callcenterlogs(Complaint ID)) #reviews (Date date, Stars integer, Reviews text, Product text, district_id integer, , PRIMARY KEY(Date), FOREIGN KEY(district_id) REFERENCES district(district_id)) #state (StateCode text, State text, Region text, , PRIMARY KEY(StateCode), ) # Was the tag in the complaint filed by Matthew Pierce on 2016/10/28 approved by himself?
246
For how long was the complaint filed by Matthew Pierce on 2016/10/28 delayed?
SELECT 365 * (strftime('%Y', T2.`Date sent to company`) - strftime('%Y', T2.`Date received`)) + 30 * (strftime('%M', T2.`Date sent to company`) - strftime('%M', T2.`Date received`)) + (strftime('%d', T2.`Date sent to company`) - strftime('%d', T2.`Date received`)) FROM client AS T1 INNER JOIN events AS T2 ON T1.client_id = T2.Client_ID WHERE T1.first = 'Matthew' AND T1.last = 'Pierce' AND T2.`Date received` = '2016-10-28'
retail_complains
Database Schema: 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)) #client (client_id text, 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, , PRIMARY KEY(client_id), FOREIGN KEY(district_id) REFERENCES district(district_id)) #district (district_id integer, city text, state_abbrev text, division text, , PRIMARY KEY(district_id), FOREIGN KEY(state_abbrev) REFERENCES state(StateCode)) #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), PRIMARY KEY(Client_ID), FOREIGN KEY(Client_ID) REFERENCES client(client_id), FOREIGN KEY(Complaint ID) REFERENCES callcenterlogs(Complaint ID)) #reviews (Date date, Stars integer, Reviews text, Product text, district_id integer, , PRIMARY KEY(Date), FOREIGN KEY(district_id) REFERENCES district(district_id)) #state (StateCode text, State text, Region text, , PRIMARY KEY(StateCode), ) # For how long was the complaint filed by Matthew Pierce on 2016/10/28 delayed?
247
What is the full name of the client whose complaint on 2017/3/27 was received by MICHAL?
SELECT T1.first, T1.middle, T1.last FROM client AS T1 INNER JOIN callcenterlogs AS T2 ON T1.client_id = T2.`rand client` WHERE T2.`Date received` = '2017-03-27' AND T2.server = 'MICHAL'
retail_complains
Database Schema: 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)) #client (client_id text, 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, , PRIMARY KEY(client_id), FOREIGN KEY(district_id) REFERENCES district(district_id)) #district (district_id integer, city text, state_abbrev text, division text, , PRIMARY KEY(district_id), FOREIGN KEY(state_abbrev) REFERENCES state(StateCode)) #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), PRIMARY KEY(Client_ID), FOREIGN KEY(Client_ID) REFERENCES client(client_id), FOREIGN KEY(Complaint ID) REFERENCES callcenterlogs(Complaint ID)) #reviews (Date date, Stars integer, Reviews text, Product text, district_id integer, , PRIMARY KEY(Date), FOREIGN KEY(district_id) REFERENCES district(district_id)) #state (StateCode text, State text, Region text, , PRIMARY KEY(StateCode), ) # What is the full name of the client whose complaint on 2017/3/27 was received by MICHAL?
248
For how long did the complaint filed on 2017/3/27 by Rachel Hicks last?
SELECT T2.ser_time FROM client AS T1 INNER JOIN callcenterlogs AS T2 ON T1.client_id = T2.`rand client` WHERE T1.first = 'Rachel' AND T1.last = 'Hicks' AND T2.`Date received` = '2017-03-27'
retail_complains
Database Schema: 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)) #client (client_id text, 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, , PRIMARY KEY(client_id), FOREIGN KEY(district_id) REFERENCES district(district_id)) #district (district_id integer, city text, state_abbrev text, division text, , PRIMARY KEY(district_id), FOREIGN KEY(state_abbrev) REFERENCES state(StateCode)) #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), PRIMARY KEY(Client_ID), FOREIGN KEY(Client_ID) REFERENCES client(client_id), FOREIGN KEY(Complaint ID) REFERENCES callcenterlogs(Complaint ID)) #reviews (Date date, Stars integer, Reviews text, Product text, district_id integer, , PRIMARY KEY(Date), FOREIGN KEY(district_id) REFERENCES district(district_id)) #state (StateCode text, State text, Region text, , PRIMARY KEY(StateCode), ) # For how long did the complaint filed on 2017/3/27 by Rachel Hicks last?
249
Among all the clients from the New York city, how many of them have filed a complaint on the issue of Deposits and withdrawals?
SELECT COUNT(T2.Issue) FROM client AS T1 INNER JOIN events AS T2 ON T1.client_id = T2.Client_ID WHERE T2.Issue = 'Deposits and withdrawals' AND T1.city = 'New York City'
retail_complains
Database Schema: 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)) #client (client_id text, 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, , PRIMARY KEY(client_id), FOREIGN KEY(district_id) REFERENCES district(district_id)) #district (district_id integer, city text, state_abbrev text, division text, , PRIMARY KEY(district_id), FOREIGN KEY(state_abbrev) REFERENCES state(StateCode)) #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), PRIMARY KEY(Client_ID), FOREIGN KEY(Client_ID) REFERENCES client(client_id), FOREIGN KEY(Complaint ID) REFERENCES callcenterlogs(Complaint ID)) #reviews (Date date, Stars integer, Reviews text, Product text, district_id integer, , PRIMARY KEY(Date), FOREIGN KEY(district_id) REFERENCES district(district_id)) #state (StateCode text, State text, Region text, , PRIMARY KEY(StateCode), ) # Among all the clients from the New York city, how many of them have filed a complaint on the issue of Deposits and withdrawals?
250
Please list the full names of all the clients whose complaints are still in progress.
SELECT T1.first, T1.middle, T1.last FROM client AS T1 INNER JOIN events AS T2 ON T1.client_id = T2.Client_ID WHERE T2.`Company response to consumer` = 'In progress'
retail_complains
Database Schema: 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)) #client (client_id text, 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, , PRIMARY KEY(client_id), FOREIGN KEY(district_id) REFERENCES district(district_id)) #district (district_id integer, city text, state_abbrev text, division text, , PRIMARY KEY(district_id), FOREIGN KEY(state_abbrev) REFERENCES state(StateCode)) #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), PRIMARY KEY(Client_ID), FOREIGN KEY(Client_ID) REFERENCES client(client_id), FOREIGN KEY(Complaint ID) REFERENCES callcenterlogs(Complaint ID)) #reviews (Date date, Stars integer, Reviews text, Product text, district_id integer, , PRIMARY KEY(Date), FOREIGN KEY(district_id) REFERENCES district(district_id)) #state (StateCode text, State text, Region text, , PRIMARY KEY(StateCode), ) # Please list the full names of all the clients whose complaints are still in progress.
251
Among the clients who did receive a timely response for their complaint, how many of them are from New York?
SELECT COUNT(T1.city) FROM client AS T1 INNER JOIN events AS T2 ON T1.client_id = T2.Client_ID WHERE T2.`Timely response?` = 'No' AND T1.city = 'New York City'
retail_complains
Database Schema: 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)) #client (client_id text, 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, , PRIMARY KEY(client_id), FOREIGN KEY(district_id) REFERENCES district(district_id)) #district (district_id integer, city text, state_abbrev text, division text, , PRIMARY KEY(district_id), FOREIGN KEY(state_abbrev) REFERENCES state(StateCode)) #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), PRIMARY KEY(Client_ID), FOREIGN KEY(Client_ID) REFERENCES client(client_id), FOREIGN KEY(Complaint ID) REFERENCES callcenterlogs(Complaint ID)) #reviews (Date date, Stars integer, Reviews text, Product text, district_id integer, , PRIMARY KEY(Date), FOREIGN KEY(district_id) REFERENCES district(district_id)) #state (StateCode text, State text, Region text, , PRIMARY KEY(StateCode), ) # Among the clients who did receive a timely response for their complaint, how many of them are from New York?
252
How many complaints on credit cards in the year 2016 were filed by male clients?
SELECT COUNT(T1.sex) FROM client AS T1 INNER JOIN events AS T2 ON T1.client_id = T2.Client_ID WHERE strftime('%Y', T2.`Date received`) = '2016' AND T1.sex = 'Male' AND T2.Product = 'Credit card'
retail_complains
Database Schema: 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)) #client (client_id text, 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, , PRIMARY KEY(client_id), FOREIGN KEY(district_id) REFERENCES district(district_id)) #district (district_id integer, city text, state_abbrev text, division text, , PRIMARY KEY(district_id), FOREIGN KEY(state_abbrev) REFERENCES state(StateCode)) #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), PRIMARY KEY(Client_ID), FOREIGN KEY(Client_ID) REFERENCES client(client_id), FOREIGN KEY(Complaint ID) REFERENCES callcenterlogs(Complaint ID)) #reviews (Date date, Stars integer, Reviews text, Product text, district_id integer, , PRIMARY KEY(Date), FOREIGN KEY(district_id) REFERENCES district(district_id)) #state (StateCode text, State text, Region text, , PRIMARY KEY(StateCode), ) # How many complaints on credit cards in the year 2016 were filed by male clients?
253

Dataset Card for "bird-with-chat"

More Information needed

Downloads last month
35
Edit dataset card