db_id
stringclasses
127 values
query
stringlengths
20
523
question
stringlengths
16
224
schema
stringclasses
127 values
network_2
SELECT avg(age) , gender FROM Person GROUP BY gender
What is the average age for each gender?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT avg(age) , gender FROM Person GROUP BY gender
How old is each gender, on average?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT avg(age) , job FROM Person GROUP BY job
What is average age for different job title?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT avg(age) , job FROM Person GROUP BY job
How old is the average person for each job?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT avg(age) , job FROM Person WHERE gender = 'male' GROUP BY job
What is average age of male for different job title?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT avg(age) , job FROM Person WHERE gender = 'male' GROUP BY job
What is the average age for a male in each job?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT min(age) , job FROM Person GROUP BY job
What is minimum age for different job title?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT min(age) , job FROM Person GROUP BY job
How old is the youngest person for each job?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT count(*) , gender FROM Person WHERE age < 40 GROUP BY gender
Find the number of people who is under 40 for each gender.
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT count(*) , gender FROM Person WHERE age < 40 GROUP BY gender
How many people are under 40 for each gender?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT name FROM Person WHERE age > (SELECT min(age) FROM person WHERE job = 'engineer') ORDER BY age
Find the name of people whose age is greater than any engineer sorted by their age.
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT name FROM Person WHERE age > (SELECT min(age) FROM person WHERE job = 'engineer') ORDER BY age
What is the name of all the people who are older than at least one engineer? Order them by age.
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT count(*) FROM Person WHERE age > (SELECT max(age) FROM person WHERE job = 'engineer')
Find the number of people whose age is greater than all engineers.
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT count(*) FROM Person WHERE age > (SELECT max(age) FROM person WHERE job = 'engineer')
How many people are older than every engineer?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT name , job FROM Person ORDER BY name
list the name, job title of all people ordered by their names.
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT name , job FROM Person ORDER BY name
What are the names and job titles of every person ordered alphabetically by name?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT name FROM Person ORDER BY age DESC
Find the names of all person sorted in the descending order using age.
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT name FROM Person ORDER BY age DESC
What are the names of everybody sorted by age in descending order?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT name FROM Person WHERE gender = 'male' ORDER BY age
Find the name and age of all males in order of their age.
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT name FROM Person WHERE gender = 'male' ORDER BY age
What is the name and age of every male? Order the results by age.
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT T1.name , T1.age FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend = 'Dan' INTERSECT SELECT T1.name , T1.age FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend = 'Alice'
Find the name and age of the person who is a friend of both Dan and Alice.
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT T1.name , T1.age FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend = 'Dan' INTERSECT SELECT T1.name , T1.age FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend = 'Alice'
What are the names and ages of every person who is a friend of both Dan and Alice?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT DISTINCT T1.name , T1.age FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend = 'Dan' OR T2.friend = 'Alice'
Find the name and age of the person who is a friend of Dan or Alice.
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT DISTINCT T1.name , T1.age FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend = 'Dan' OR T2.friend = 'Alice'
What are the different names and ages of every friend of either Dan or alice?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend IN (SELECT name FROM Person WHERE age > 40) INTERSECT SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend IN (SELECT name FROM Person WHERE age < 30)
Find the name of the person who has friends with age above 40 and under age 30?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend IN (SELECT name FROM Person WHERE age > 40) INTERSECT SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend IN (SELECT name FROM Person WHERE age < 30)
What are the names of every person who has a friend over 40 and under 30?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend IN (SELECT name FROM Person WHERE age > 40) EXCEPT SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend IN (SELECT name FROM Person WHERE age < 30)
Find the name of the person who has friends with age above 40 but not under age 30?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend IN (SELECT name FROM Person WHERE age > 40) EXCEPT SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend IN (SELECT name FROM Person WHERE age < 30)
What are the names of the people who are older 40 but no friends under age 30?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT name FROM person EXCEPT SELECT T2.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.friend WHERE T1.job = 'student'
Find the name of the person who has no student friends.
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT name FROM person EXCEPT SELECT T2.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.friend WHERE T1.job = 'student'
What are the names of the people who have no friends who are students?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT name FROM PersonFriend GROUP BY name HAVING count(*) = 1
Find the person who has exactly one friend.
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT name FROM PersonFriend GROUP BY name HAVING count(*) = 1
What are the names of everybody who has exactly one friend?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT T2.friend FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T1.name = 'Bob'
Who are the friends of Bob?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT T2.friend FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T1.name = 'Bob'
Who are Bob's friends?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend = 'Bob'
Find the name of persons who are friends with Bob.
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend = 'Bob'
What are the names of all of Bob's friends?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend = 'Zach' AND T1.gender = 'female'
Find the names of females who are friends with Zach
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend = 'Zach' AND T1.gender = 'female'
What are the names of all females who are friends with Zach?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT T2.friend FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.friend WHERE T2.name = 'Alice' AND T1.gender = 'female'
Find the female friends of Alice.
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT T2.friend FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.friend WHERE T2.name = 'Alice' AND T1.gender = 'female'
What are all the friends of Alice who are female?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT T2.friend FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.friend WHERE T2.name = 'Alice' AND T1.gender = 'male' AND T1.job = 'doctor'
Find the male friend of Alice whose job is a doctor?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT T2.friend FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.friend WHERE T2.name = 'Alice' AND T1.gender = 'male' AND T1.job = 'doctor'
Who are the friends of Alice that are doctors?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT T2.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.friend WHERE T1.city = 'new york city'
Who has a friend that is from new york city?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT T2.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.friend WHERE T1.city = 'new york city'
What are the names of all friends who are from New York?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT DISTINCT T2.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.friend WHERE T1.age < (SELECT avg(age) FROM person)
Who has friends that are younger than the average age?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT DISTINCT T2.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.friend WHERE T1.age < (SELECT avg(age) FROM person)
What are the different names of friends who are younger than the average age for a friend?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT DISTINCT T2.name , T2.friend , T1.age FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.friend WHERE T1.age > (SELECT avg(age) FROM person)
Who has friends that are older than the average age? Print their friends and their ages as well
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT DISTINCT T2.name , T2.friend , T1.age FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.friend WHERE T1.age > (SELECT avg(age) FROM person)
Whare the names, friends, and ages of all people who are older than the average age of a person?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT friend FROM PersonFriend WHERE name = 'Zach' AND YEAR = (SELECT max(YEAR) FROM PersonFriend WHERE name = 'Zach')
Who is the friend of Zach with longest year relationship?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT friend FROM PersonFriend WHERE name = 'Zach' AND YEAR = (SELECT max(YEAR) FROM PersonFriend WHERE name = 'Zach')
Which friend of Zach has the longest-lasting friendship?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT T1.age FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.friend WHERE T2.name = 'Zach' AND T2.year = (SELECT max(YEAR) FROM PersonFriend WHERE name = 'Zach')
What is the age of the friend of Zach with longest year relationship?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT T1.age FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.friend WHERE T2.name = 'Zach' AND T2.year = (SELECT max(YEAR) FROM PersonFriend WHERE name = 'Zach')
What are the ages of all of Zach's friends who are in the longest relationship?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT name FROM PersonFriend WHERE friend = 'Alice' AND YEAR = (SELECT min(YEAR) FROM PersonFriend WHERE friend = 'Alice')
Find the name of persons who are friends with Alice for the shortest years.
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT name FROM PersonFriend WHERE friend = 'Alice' AND YEAR = (SELECT min(YEAR) FROM PersonFriend WHERE friend = 'Alice')
What are the names of all people who are friends with Alice for the shortest amount of time?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT T1.name , T1.age , T1.job FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend = 'Alice' AND T2.year = (SELECT max(YEAR) FROM PersonFriend WHERE friend = 'Alice')
Find the name, age, and job title of persons who are friends with Alice for the longest years.
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT T1.name , T1.age , T1.job FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend = 'Alice' AND T2.year = (SELECT max(YEAR) FROM PersonFriend WHERE friend = 'Alice')
What are the names, ages, and jobs of all people who are friends with Alice for the longest amount of time?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT name FROM person EXCEPT SELECT name FROM PersonFriend
Who is the person that has no friend?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT name FROM person EXCEPT SELECT name FROM PersonFriend
What are the names of all people who do not have friends?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT T2.name , avg(T1.age) FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.friend GROUP BY T2.name ORDER BY avg(T1.age) DESC LIMIT 1
Which person whose friends have the oldest average age?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT T2.name , avg(T1.age) FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.friend GROUP BY T2.name ORDER BY avg(T1.age) DESC LIMIT 1
What is the name of the person who has the oldest average age for their friends, and what is that average age?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT count(DISTINCT name) FROM PersonFriend WHERE friend NOT IN (SELECT name FROM person WHERE city = 'Austin')
What is the total number of people who has no friend living in the city of Austin.
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT count(DISTINCT name) FROM PersonFriend WHERE friend NOT IN (SELECT name FROM person WHERE city = 'Austin')
What is the total number of people who have no friends living in Austin?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT DISTINCT T4.name FROM PersonFriend AS T1 JOIN Person AS T2 ON T1.name = T2.name JOIN PersonFriend AS T3 ON T1.friend = T3.name JOIN PersonFriend AS T4 ON T3.friend = T4.name WHERE T2.name = 'Alice' AND T4.name != 'Alice'
Find Alice's friends of friends.
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
network_2
SELECT DISTINCT T4.name FROM PersonFriend AS T1 JOIN Person AS T2 ON T1.name = T2.name JOIN PersonFriend AS T3 ON T1.friend = T3.name JOIN PersonFriend AS T4 ON T3.friend = T4.name WHERE T2.name = 'Alice' AND T4.name != 'Alice'
What are the names of all of Alice's friends of friends?
CREATE TABLE Person ( name varchar(20) PRIMARY KEY, age INTEGER, city TEXT, gender TEXT, job TEXT ); CREATE TABLE PersonFriend ( name varchar(20), friend varchar(20), year INTEGER, FOREIGN KEY (name) REFERENCES Person(name), FOREIGN KEY (friend) REFERENCES Person(name) ); INSERT INTO Person VALUES ('Alice',25,'new york city','female','student'); INSERT INTO PersonFriend VALUES ('Alice','Bob',10);
decoration_competition
SELECT count(*) FROM member
How many members are there?
PRAGMA foreign_keys = ON; CREATE TABLE "college" ( "College_ID" int, "Name" text, "Leader_Name" text, "College_Location" text, PRIMARY KEY ("College_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Country" text, "College_ID" int, PRIMARY KEY ("Member_ID"), FOREIGN KEY ("College_ID") REFERENCES `college`("College_ID") ); CREATE TABLE "round" ( "Round_ID" int, "Member_ID" int, "Decoration_Theme" text, "Rank_in_Round" int, PRIMARY KEY ("Member_ID","Round_ID"), FOREIGN KEY ("Member_ID") REFERENCES "member"("Member_ID") ); INSERT INTO "college" VALUES ("1","Saskatchewan School","Ousame Tounkara","Ottawa"); INSERT INTO "member" VALUES ("1","Jack Nicklaus","United States",1); INSERT INTO "round" VALUES (1,1,"Walk on the Moon",1);
decoration_competition
SELECT Name FROM member ORDER BY Name ASC
List the names of members in ascending alphabetical order.
PRAGMA foreign_keys = ON; CREATE TABLE "college" ( "College_ID" int, "Name" text, "Leader_Name" text, "College_Location" text, PRIMARY KEY ("College_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Country" text, "College_ID" int, PRIMARY KEY ("Member_ID"), FOREIGN KEY ("College_ID") REFERENCES `college`("College_ID") ); CREATE TABLE "round" ( "Round_ID" int, "Member_ID" int, "Decoration_Theme" text, "Rank_in_Round" int, PRIMARY KEY ("Member_ID","Round_ID"), FOREIGN KEY ("Member_ID") REFERENCES "member"("Member_ID") ); INSERT INTO "college" VALUES ("1","Saskatchewan School","Ousame Tounkara","Ottawa"); INSERT INTO "member" VALUES ("1","Jack Nicklaus","United States",1); INSERT INTO "round" VALUES (1,1,"Walk on the Moon",1);
decoration_competition
SELECT Name , Country FROM member
What are the names and countries of members?
PRAGMA foreign_keys = ON; CREATE TABLE "college" ( "College_ID" int, "Name" text, "Leader_Name" text, "College_Location" text, PRIMARY KEY ("College_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Country" text, "College_ID" int, PRIMARY KEY ("Member_ID"), FOREIGN KEY ("College_ID") REFERENCES `college`("College_ID") ); CREATE TABLE "round" ( "Round_ID" int, "Member_ID" int, "Decoration_Theme" text, "Rank_in_Round" int, PRIMARY KEY ("Member_ID","Round_ID"), FOREIGN KEY ("Member_ID") REFERENCES "member"("Member_ID") ); INSERT INTO "college" VALUES ("1","Saskatchewan School","Ousame Tounkara","Ottawa"); INSERT INTO "member" VALUES ("1","Jack Nicklaus","United States",1); INSERT INTO "round" VALUES (1,1,"Walk on the Moon",1);
decoration_competition
SELECT Name FROM member WHERE Country = "United States" OR Country = "Canada"
Show the names of members whose country is "United States" or "Canada".
PRAGMA foreign_keys = ON; CREATE TABLE "college" ( "College_ID" int, "Name" text, "Leader_Name" text, "College_Location" text, PRIMARY KEY ("College_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Country" text, "College_ID" int, PRIMARY KEY ("Member_ID"), FOREIGN KEY ("College_ID") REFERENCES `college`("College_ID") ); CREATE TABLE "round" ( "Round_ID" int, "Member_ID" int, "Decoration_Theme" text, "Rank_in_Round" int, PRIMARY KEY ("Member_ID","Round_ID"), FOREIGN KEY ("Member_ID") REFERENCES "member"("Member_ID") ); INSERT INTO "college" VALUES ("1","Saskatchewan School","Ousame Tounkara","Ottawa"); INSERT INTO "member" VALUES ("1","Jack Nicklaus","United States",1); INSERT INTO "round" VALUES (1,1,"Walk on the Moon",1);
decoration_competition
SELECT Country , COUNT(*) FROM member GROUP BY Country
Show the different countries and the number of members from each.
PRAGMA foreign_keys = ON; CREATE TABLE "college" ( "College_ID" int, "Name" text, "Leader_Name" text, "College_Location" text, PRIMARY KEY ("College_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Country" text, "College_ID" int, PRIMARY KEY ("Member_ID"), FOREIGN KEY ("College_ID") REFERENCES `college`("College_ID") ); CREATE TABLE "round" ( "Round_ID" int, "Member_ID" int, "Decoration_Theme" text, "Rank_in_Round" int, PRIMARY KEY ("Member_ID","Round_ID"), FOREIGN KEY ("Member_ID") REFERENCES "member"("Member_ID") ); INSERT INTO "college" VALUES ("1","Saskatchewan School","Ousame Tounkara","Ottawa"); INSERT INTO "member" VALUES ("1","Jack Nicklaus","United States",1); INSERT INTO "round" VALUES (1,1,"Walk on the Moon",1);
decoration_competition
SELECT Country FROM member GROUP BY Country ORDER BY COUNT(*) DESC LIMIT 1
Show the most common country across members.
PRAGMA foreign_keys = ON; CREATE TABLE "college" ( "College_ID" int, "Name" text, "Leader_Name" text, "College_Location" text, PRIMARY KEY ("College_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Country" text, "College_ID" int, PRIMARY KEY ("Member_ID"), FOREIGN KEY ("College_ID") REFERENCES `college`("College_ID") ); CREATE TABLE "round" ( "Round_ID" int, "Member_ID" int, "Decoration_Theme" text, "Rank_in_Round" int, PRIMARY KEY ("Member_ID","Round_ID"), FOREIGN KEY ("Member_ID") REFERENCES "member"("Member_ID") ); INSERT INTO "college" VALUES ("1","Saskatchewan School","Ousame Tounkara","Ottawa"); INSERT INTO "member" VALUES ("1","Jack Nicklaus","United States",1); INSERT INTO "round" VALUES (1,1,"Walk on the Moon",1);
decoration_competition
SELECT Country FROM member GROUP BY Country HAVING COUNT(*) > 2
Which countries have more than two members?
PRAGMA foreign_keys = ON; CREATE TABLE "college" ( "College_ID" int, "Name" text, "Leader_Name" text, "College_Location" text, PRIMARY KEY ("College_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Country" text, "College_ID" int, PRIMARY KEY ("Member_ID"), FOREIGN KEY ("College_ID") REFERENCES `college`("College_ID") ); CREATE TABLE "round" ( "Round_ID" int, "Member_ID" int, "Decoration_Theme" text, "Rank_in_Round" int, PRIMARY KEY ("Member_ID","Round_ID"), FOREIGN KEY ("Member_ID") REFERENCES "member"("Member_ID") ); INSERT INTO "college" VALUES ("1","Saskatchewan School","Ousame Tounkara","Ottawa"); INSERT INTO "member" VALUES ("1","Jack Nicklaus","United States",1); INSERT INTO "round" VALUES (1,1,"Walk on the Moon",1);
decoration_competition
SELECT Leader_Name , College_Location FROM college
Show the leader names and locations of colleges.
PRAGMA foreign_keys = ON; CREATE TABLE "college" ( "College_ID" int, "Name" text, "Leader_Name" text, "College_Location" text, PRIMARY KEY ("College_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Country" text, "College_ID" int, PRIMARY KEY ("Member_ID"), FOREIGN KEY ("College_ID") REFERENCES `college`("College_ID") ); CREATE TABLE "round" ( "Round_ID" int, "Member_ID" int, "Decoration_Theme" text, "Rank_in_Round" int, PRIMARY KEY ("Member_ID","Round_ID"), FOREIGN KEY ("Member_ID") REFERENCES "member"("Member_ID") ); INSERT INTO "college" VALUES ("1","Saskatchewan School","Ousame Tounkara","Ottawa"); INSERT INTO "member" VALUES ("1","Jack Nicklaus","United States",1); INSERT INTO "round" VALUES (1,1,"Walk on the Moon",1);
decoration_competition
SELECT T2.Name , T1.Name FROM college AS T1 JOIN member AS T2 ON T1.College_ID = T2.College_ID
Show the names of members and names of colleges they go to.
PRAGMA foreign_keys = ON; CREATE TABLE "college" ( "College_ID" int, "Name" text, "Leader_Name" text, "College_Location" text, PRIMARY KEY ("College_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Country" text, "College_ID" int, PRIMARY KEY ("Member_ID"), FOREIGN KEY ("College_ID") REFERENCES `college`("College_ID") ); CREATE TABLE "round" ( "Round_ID" int, "Member_ID" int, "Decoration_Theme" text, "Rank_in_Round" int, PRIMARY KEY ("Member_ID","Round_ID"), FOREIGN KEY ("Member_ID") REFERENCES "member"("Member_ID") ); INSERT INTO "college" VALUES ("1","Saskatchewan School","Ousame Tounkara","Ottawa"); INSERT INTO "member" VALUES ("1","Jack Nicklaus","United States",1); INSERT INTO "round" VALUES (1,1,"Walk on the Moon",1);
decoration_competition
SELECT T2.Name , T1.College_Location FROM college AS T1 JOIN member AS T2 ON T1.College_ID = T2.College_ID ORDER BY T2.Name ASC
Show the names of members and the locations of colleges they go to in ascending alphabetical order of member names.
PRAGMA foreign_keys = ON; CREATE TABLE "college" ( "College_ID" int, "Name" text, "Leader_Name" text, "College_Location" text, PRIMARY KEY ("College_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Country" text, "College_ID" int, PRIMARY KEY ("Member_ID"), FOREIGN KEY ("College_ID") REFERENCES `college`("College_ID") ); CREATE TABLE "round" ( "Round_ID" int, "Member_ID" int, "Decoration_Theme" text, "Rank_in_Round" int, PRIMARY KEY ("Member_ID","Round_ID"), FOREIGN KEY ("Member_ID") REFERENCES "member"("Member_ID") ); INSERT INTO "college" VALUES ("1","Saskatchewan School","Ousame Tounkara","Ottawa"); INSERT INTO "member" VALUES ("1","Jack Nicklaus","United States",1); INSERT INTO "round" VALUES (1,1,"Walk on the Moon",1);
decoration_competition
SELECT DISTINCT T1.Leader_Name FROM college AS T1 JOIN member AS T2 ON T1.College_ID = T2.College_ID WHERE T2.Country = "Canada"
Show the distinct leader names of colleges associated with members from country "Canada".
PRAGMA foreign_keys = ON; CREATE TABLE "college" ( "College_ID" int, "Name" text, "Leader_Name" text, "College_Location" text, PRIMARY KEY ("College_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Country" text, "College_ID" int, PRIMARY KEY ("Member_ID"), FOREIGN KEY ("College_ID") REFERENCES `college`("College_ID") ); CREATE TABLE "round" ( "Round_ID" int, "Member_ID" int, "Decoration_Theme" text, "Rank_in_Round" int, PRIMARY KEY ("Member_ID","Round_ID"), FOREIGN KEY ("Member_ID") REFERENCES "member"("Member_ID") ); INSERT INTO "college" VALUES ("1","Saskatchewan School","Ousame Tounkara","Ottawa"); INSERT INTO "member" VALUES ("1","Jack Nicklaus","United States",1); INSERT INTO "round" VALUES (1,1,"Walk on the Moon",1);
decoration_competition
SELECT T1.Name , T2.Decoration_Theme FROM member AS T1 JOIN round AS T2 ON T1.Member_ID = T2.Member_ID
Show the names of members and the decoration themes they have.
PRAGMA foreign_keys = ON; CREATE TABLE "college" ( "College_ID" int, "Name" text, "Leader_Name" text, "College_Location" text, PRIMARY KEY ("College_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Country" text, "College_ID" int, PRIMARY KEY ("Member_ID"), FOREIGN KEY ("College_ID") REFERENCES `college`("College_ID") ); CREATE TABLE "round" ( "Round_ID" int, "Member_ID" int, "Decoration_Theme" text, "Rank_in_Round" int, PRIMARY KEY ("Member_ID","Round_ID"), FOREIGN KEY ("Member_ID") REFERENCES "member"("Member_ID") ); INSERT INTO "college" VALUES ("1","Saskatchewan School","Ousame Tounkara","Ottawa"); INSERT INTO "member" VALUES ("1","Jack Nicklaus","United States",1); INSERT INTO "round" VALUES (1,1,"Walk on the Moon",1);
decoration_competition
SELECT T1.Name FROM member AS T1 JOIN round AS T2 ON T1.Member_ID = T2.Member_ID WHERE T2.Rank_in_Round > 3
Show the names of members that have a rank in round higher than 3.
PRAGMA foreign_keys = ON; CREATE TABLE "college" ( "College_ID" int, "Name" text, "Leader_Name" text, "College_Location" text, PRIMARY KEY ("College_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Country" text, "College_ID" int, PRIMARY KEY ("Member_ID"), FOREIGN KEY ("College_ID") REFERENCES `college`("College_ID") ); CREATE TABLE "round" ( "Round_ID" int, "Member_ID" int, "Decoration_Theme" text, "Rank_in_Round" int, PRIMARY KEY ("Member_ID","Round_ID"), FOREIGN KEY ("Member_ID") REFERENCES "member"("Member_ID") ); INSERT INTO "college" VALUES ("1","Saskatchewan School","Ousame Tounkara","Ottawa"); INSERT INTO "member" VALUES ("1","Jack Nicklaus","United States",1); INSERT INTO "round" VALUES (1,1,"Walk on the Moon",1);
decoration_competition
SELECT T1.Name FROM member AS T1 JOIN round AS T2 ON T1.Member_ID = T2.Member_ID ORDER BY Rank_in_Round ASC
Show the names of members in ascending order of their rank in rounds.
PRAGMA foreign_keys = ON; CREATE TABLE "college" ( "College_ID" int, "Name" text, "Leader_Name" text, "College_Location" text, PRIMARY KEY ("College_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Country" text, "College_ID" int, PRIMARY KEY ("Member_ID"), FOREIGN KEY ("College_ID") REFERENCES `college`("College_ID") ); CREATE TABLE "round" ( "Round_ID" int, "Member_ID" int, "Decoration_Theme" text, "Rank_in_Round" int, PRIMARY KEY ("Member_ID","Round_ID"), FOREIGN KEY ("Member_ID") REFERENCES "member"("Member_ID") ); INSERT INTO "college" VALUES ("1","Saskatchewan School","Ousame Tounkara","Ottawa"); INSERT INTO "member" VALUES ("1","Jack Nicklaus","United States",1); INSERT INTO "round" VALUES (1,1,"Walk on the Moon",1);
decoration_competition
SELECT Name FROM member WHERE Member_ID NOT IN (SELECT Member_ID FROM round)
List the names of members who did not participate in any round.
PRAGMA foreign_keys = ON; CREATE TABLE "college" ( "College_ID" int, "Name" text, "Leader_Name" text, "College_Location" text, PRIMARY KEY ("College_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Country" text, "College_ID" int, PRIMARY KEY ("Member_ID"), FOREIGN KEY ("College_ID") REFERENCES `college`("College_ID") ); CREATE TABLE "round" ( "Round_ID" int, "Member_ID" int, "Decoration_Theme" text, "Rank_in_Round" int, PRIMARY KEY ("Member_ID","Round_ID"), FOREIGN KEY ("Member_ID") REFERENCES "member"("Member_ID") ); INSERT INTO "college" VALUES ("1","Saskatchewan School","Ousame Tounkara","Ottawa"); INSERT INTO "member" VALUES ("1","Jack Nicklaus","United States",1); INSERT INTO "round" VALUES (1,1,"Walk on the Moon",1);
document_management
SELECT document_name , access_count FROM documents ORDER BY document_name
Find the name and access counts of all documents, in alphabetic order of the document name.
PRAGMA foreign_keys = ON; CREATE TABLE `Roles` ( `role_code` VARCHAR(15) PRIMARY KEY, `role_description` VARCHAR(80) ); CREATE TABLE `Users` ( `user_id` INTEGER PRIMARY KEY, `role_code` VARCHAR(15) NOT NULL, `user_name` VARCHAR(40), `user_login` VARCHAR(40), `password` VARCHAR(40), FOREIGN KEY (`role_code` ) REFERENCES `Roles`(`role_code` ) ); CREATE TABLE `Document_Structures` ( `document_structure_code` VARCHAR(15) PRIMARY KEY, `parent_document_structure_code` VARCHAR(15), `document_structure_description` VARCHAR(80) ); CREATE TABLE `Functional_Areas` ( `functional_area_code` VARCHAR(15) PRIMARY KEY, `parent_functional_area_code` VARCHAR(15), `functional_area_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Images` ( `image_id` INTEGER PRIMARY KEY, `image_alt_text` VARCHAR(80), `image_name` VARCHAR(40), `image_url` VARCHAR(255) ); CREATE TABLE `Documents` ( `document_code` VARCHAR(15) PRIMARY KEY, `document_structure_code` VARCHAR(15) NOT NULL, `document_type_code` VARCHAR(15) NOT NULL, `access_count` INTEGER, `document_name` VARCHAR(80), FOREIGN KEY (`document_structure_code` ) REFERENCES `Document_Structures`(`document_structure_code` ) ); CREATE TABLE `Document_Functional_Areas` ( `document_code` VARCHAR(15) NOT NULL, `functional_area_code` VARCHAR(15) NOT NULL, FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ), FOREIGN KEY (`functional_area_code` ) REFERENCES `Functional_Areas`(`functional_area_code` ) ); CREATE TABLE `Document_Sections` ( `section_id` INTEGER PRIMARY KEY, `document_code` VARCHAR(15) NOT NULL, `section_sequence` INTEGER, `section_code` VARCHAR(20), `section_title` VARCHAR(80), FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ) ); CREATE TABLE `Document_Sections_Images` ( `section_id` INTEGER NOT NULL, `image_id` INTEGER NOT NULL, PRIMARY KEY (`section_id`,`image_id`), FOREIGN KEY (`section_id` ) REFERENCES `Document_Sections`(`section_id` ), FOREIGN KEY (`image_id` ) REFERENCES `Images`(`image_id` ) ); INSERT INTO Roles (`role_code`, `role_description`) VALUES ('DBA', 'Database Administrator')INSERT INTO Users (`user_id`, `role_code`, `user_name`, `user_login`, `password`) VALUES (1, 'PROJ-MGR', 'dickens.elta', '0', 'e72b5a2d50b39a8760764a5f7a9d68ca2f076877')INSERT INTO Document_Structures (`document_structure_code`, `parent_document_structure_code`, `document_structure_description`) VALUES ('1', '1', 'Header')INSERT INTO Functional_Areas (`functional_area_code`, `parent_functional_area_code`, `functional_area_description`) VALUES ('8', '8', 'Signature')INSERT INTO Images (`image_id`, `image_alt_text`, `image_name`, `image_url`) VALUES (1, 'Lea', 'top1', 'http://www.rempelnader.com/1.jpg')INSERT INTO Documents (`document_code`, `document_structure_code`, `document_type_code`, `access_count`, `document_name`) VALUES ('217', '8', 'Book', 1864, 'Learning English')INSERT INTO Document_Functional_Areas (`document_code`, `functional_area_code`) VALUES ('675', '9')INSERT INTO Document_Sections (`section_id`, `document_code`, `section_sequence`, `section_code`, `section_title`) VALUES (40, '465', 4964, '93', 'after')INSERT INTO Document_Sections_Images (`section_id`, `image_id`) VALUES (93, 6)
document_management
SELECT document_name , access_count FROM documents ORDER BY document_name
What are the names of all the documents, as well as the access counts of each, ordered alphabetically?
PRAGMA foreign_keys = ON; CREATE TABLE `Roles` ( `role_code` VARCHAR(15) PRIMARY KEY, `role_description` VARCHAR(80) ); CREATE TABLE `Users` ( `user_id` INTEGER PRIMARY KEY, `role_code` VARCHAR(15) NOT NULL, `user_name` VARCHAR(40), `user_login` VARCHAR(40), `password` VARCHAR(40), FOREIGN KEY (`role_code` ) REFERENCES `Roles`(`role_code` ) ); CREATE TABLE `Document_Structures` ( `document_structure_code` VARCHAR(15) PRIMARY KEY, `parent_document_structure_code` VARCHAR(15), `document_structure_description` VARCHAR(80) ); CREATE TABLE `Functional_Areas` ( `functional_area_code` VARCHAR(15) PRIMARY KEY, `parent_functional_area_code` VARCHAR(15), `functional_area_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Images` ( `image_id` INTEGER PRIMARY KEY, `image_alt_text` VARCHAR(80), `image_name` VARCHAR(40), `image_url` VARCHAR(255) ); CREATE TABLE `Documents` ( `document_code` VARCHAR(15) PRIMARY KEY, `document_structure_code` VARCHAR(15) NOT NULL, `document_type_code` VARCHAR(15) NOT NULL, `access_count` INTEGER, `document_name` VARCHAR(80), FOREIGN KEY (`document_structure_code` ) REFERENCES `Document_Structures`(`document_structure_code` ) ); CREATE TABLE `Document_Functional_Areas` ( `document_code` VARCHAR(15) NOT NULL, `functional_area_code` VARCHAR(15) NOT NULL, FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ), FOREIGN KEY (`functional_area_code` ) REFERENCES `Functional_Areas`(`functional_area_code` ) ); CREATE TABLE `Document_Sections` ( `section_id` INTEGER PRIMARY KEY, `document_code` VARCHAR(15) NOT NULL, `section_sequence` INTEGER, `section_code` VARCHAR(20), `section_title` VARCHAR(80), FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ) ); CREATE TABLE `Document_Sections_Images` ( `section_id` INTEGER NOT NULL, `image_id` INTEGER NOT NULL, PRIMARY KEY (`section_id`,`image_id`), FOREIGN KEY (`section_id` ) REFERENCES `Document_Sections`(`section_id` ), FOREIGN KEY (`image_id` ) REFERENCES `Images`(`image_id` ) ); INSERT INTO Roles (`role_code`, `role_description`) VALUES ('DBA', 'Database Administrator')INSERT INTO Users (`user_id`, `role_code`, `user_name`, `user_login`, `password`) VALUES (1, 'PROJ-MGR', 'dickens.elta', '0', 'e72b5a2d50b39a8760764a5f7a9d68ca2f076877')INSERT INTO Document_Structures (`document_structure_code`, `parent_document_structure_code`, `document_structure_description`) VALUES ('1', '1', 'Header')INSERT INTO Functional_Areas (`functional_area_code`, `parent_functional_area_code`, `functional_area_description`) VALUES ('8', '8', 'Signature')INSERT INTO Images (`image_id`, `image_alt_text`, `image_name`, `image_url`) VALUES (1, 'Lea', 'top1', 'http://www.rempelnader.com/1.jpg')INSERT INTO Documents (`document_code`, `document_structure_code`, `document_type_code`, `access_count`, `document_name`) VALUES ('217', '8', 'Book', 1864, 'Learning English')INSERT INTO Document_Functional_Areas (`document_code`, `functional_area_code`) VALUES ('675', '9')INSERT INTO Document_Sections (`section_id`, `document_code`, `section_sequence`, `section_code`, `section_title`) VALUES (40, '465', 4964, '93', 'after')INSERT INTO Document_Sections_Images (`section_id`, `image_id`) VALUES (93, 6)
document_management
SELECT document_name , access_count FROM documents ORDER BY access_count DESC LIMIT 1
Find the name of the document that has been accessed the greatest number of times, as well as the count of how many times it has been accessed?
PRAGMA foreign_keys = ON; CREATE TABLE `Roles` ( `role_code` VARCHAR(15) PRIMARY KEY, `role_description` VARCHAR(80) ); CREATE TABLE `Users` ( `user_id` INTEGER PRIMARY KEY, `role_code` VARCHAR(15) NOT NULL, `user_name` VARCHAR(40), `user_login` VARCHAR(40), `password` VARCHAR(40), FOREIGN KEY (`role_code` ) REFERENCES `Roles`(`role_code` ) ); CREATE TABLE `Document_Structures` ( `document_structure_code` VARCHAR(15) PRIMARY KEY, `parent_document_structure_code` VARCHAR(15), `document_structure_description` VARCHAR(80) ); CREATE TABLE `Functional_Areas` ( `functional_area_code` VARCHAR(15) PRIMARY KEY, `parent_functional_area_code` VARCHAR(15), `functional_area_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Images` ( `image_id` INTEGER PRIMARY KEY, `image_alt_text` VARCHAR(80), `image_name` VARCHAR(40), `image_url` VARCHAR(255) ); CREATE TABLE `Documents` ( `document_code` VARCHAR(15) PRIMARY KEY, `document_structure_code` VARCHAR(15) NOT NULL, `document_type_code` VARCHAR(15) NOT NULL, `access_count` INTEGER, `document_name` VARCHAR(80), FOREIGN KEY (`document_structure_code` ) REFERENCES `Document_Structures`(`document_structure_code` ) ); CREATE TABLE `Document_Functional_Areas` ( `document_code` VARCHAR(15) NOT NULL, `functional_area_code` VARCHAR(15) NOT NULL, FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ), FOREIGN KEY (`functional_area_code` ) REFERENCES `Functional_Areas`(`functional_area_code` ) ); CREATE TABLE `Document_Sections` ( `section_id` INTEGER PRIMARY KEY, `document_code` VARCHAR(15) NOT NULL, `section_sequence` INTEGER, `section_code` VARCHAR(20), `section_title` VARCHAR(80), FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ) ); CREATE TABLE `Document_Sections_Images` ( `section_id` INTEGER NOT NULL, `image_id` INTEGER NOT NULL, PRIMARY KEY (`section_id`,`image_id`), FOREIGN KEY (`section_id` ) REFERENCES `Document_Sections`(`section_id` ), FOREIGN KEY (`image_id` ) REFERENCES `Images`(`image_id` ) ); INSERT INTO Roles (`role_code`, `role_description`) VALUES ('DBA', 'Database Administrator')INSERT INTO Users (`user_id`, `role_code`, `user_name`, `user_login`, `password`) VALUES (1, 'PROJ-MGR', 'dickens.elta', '0', 'e72b5a2d50b39a8760764a5f7a9d68ca2f076877')INSERT INTO Document_Structures (`document_structure_code`, `parent_document_structure_code`, `document_structure_description`) VALUES ('1', '1', 'Header')INSERT INTO Functional_Areas (`functional_area_code`, `parent_functional_area_code`, `functional_area_description`) VALUES ('8', '8', 'Signature')INSERT INTO Images (`image_id`, `image_alt_text`, `image_name`, `image_url`) VALUES (1, 'Lea', 'top1', 'http://www.rempelnader.com/1.jpg')INSERT INTO Documents (`document_code`, `document_structure_code`, `document_type_code`, `access_count`, `document_name`) VALUES ('217', '8', 'Book', 1864, 'Learning English')INSERT INTO Document_Functional_Areas (`document_code`, `functional_area_code`) VALUES ('675', '9')INSERT INTO Document_Sections (`section_id`, `document_code`, `section_sequence`, `section_code`, `section_title`) VALUES (40, '465', 4964, '93', 'after')INSERT INTO Document_Sections_Images (`section_id`, `image_id`) VALUES (93, 6)
document_management
SELECT document_name , access_count FROM documents ORDER BY access_count DESC LIMIT 1
What is the name of the document which has been accessed the most times, as well as the number of times it has been accessed?
PRAGMA foreign_keys = ON; CREATE TABLE `Roles` ( `role_code` VARCHAR(15) PRIMARY KEY, `role_description` VARCHAR(80) ); CREATE TABLE `Users` ( `user_id` INTEGER PRIMARY KEY, `role_code` VARCHAR(15) NOT NULL, `user_name` VARCHAR(40), `user_login` VARCHAR(40), `password` VARCHAR(40), FOREIGN KEY (`role_code` ) REFERENCES `Roles`(`role_code` ) ); CREATE TABLE `Document_Structures` ( `document_structure_code` VARCHAR(15) PRIMARY KEY, `parent_document_structure_code` VARCHAR(15), `document_structure_description` VARCHAR(80) ); CREATE TABLE `Functional_Areas` ( `functional_area_code` VARCHAR(15) PRIMARY KEY, `parent_functional_area_code` VARCHAR(15), `functional_area_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Images` ( `image_id` INTEGER PRIMARY KEY, `image_alt_text` VARCHAR(80), `image_name` VARCHAR(40), `image_url` VARCHAR(255) ); CREATE TABLE `Documents` ( `document_code` VARCHAR(15) PRIMARY KEY, `document_structure_code` VARCHAR(15) NOT NULL, `document_type_code` VARCHAR(15) NOT NULL, `access_count` INTEGER, `document_name` VARCHAR(80), FOREIGN KEY (`document_structure_code` ) REFERENCES `Document_Structures`(`document_structure_code` ) ); CREATE TABLE `Document_Functional_Areas` ( `document_code` VARCHAR(15) NOT NULL, `functional_area_code` VARCHAR(15) NOT NULL, FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ), FOREIGN KEY (`functional_area_code` ) REFERENCES `Functional_Areas`(`functional_area_code` ) ); CREATE TABLE `Document_Sections` ( `section_id` INTEGER PRIMARY KEY, `document_code` VARCHAR(15) NOT NULL, `section_sequence` INTEGER, `section_code` VARCHAR(20), `section_title` VARCHAR(80), FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ) ); CREATE TABLE `Document_Sections_Images` ( `section_id` INTEGER NOT NULL, `image_id` INTEGER NOT NULL, PRIMARY KEY (`section_id`,`image_id`), FOREIGN KEY (`section_id` ) REFERENCES `Document_Sections`(`section_id` ), FOREIGN KEY (`image_id` ) REFERENCES `Images`(`image_id` ) ); INSERT INTO Roles (`role_code`, `role_description`) VALUES ('DBA', 'Database Administrator')INSERT INTO Users (`user_id`, `role_code`, `user_name`, `user_login`, `password`) VALUES (1, 'PROJ-MGR', 'dickens.elta', '0', 'e72b5a2d50b39a8760764a5f7a9d68ca2f076877')INSERT INTO Document_Structures (`document_structure_code`, `parent_document_structure_code`, `document_structure_description`) VALUES ('1', '1', 'Header')INSERT INTO Functional_Areas (`functional_area_code`, `parent_functional_area_code`, `functional_area_description`) VALUES ('8', '8', 'Signature')INSERT INTO Images (`image_id`, `image_alt_text`, `image_name`, `image_url`) VALUES (1, 'Lea', 'top1', 'http://www.rempelnader.com/1.jpg')INSERT INTO Documents (`document_code`, `document_structure_code`, `document_type_code`, `access_count`, `document_name`) VALUES ('217', '8', 'Book', 1864, 'Learning English')INSERT INTO Document_Functional_Areas (`document_code`, `functional_area_code`) VALUES ('675', '9')INSERT INTO Document_Sections (`section_id`, `document_code`, `section_sequence`, `section_code`, `section_title`) VALUES (40, '465', 4964, '93', 'after')INSERT INTO Document_Sections_Images (`section_id`, `image_id`) VALUES (93, 6)
document_management
SELECT document_type_code FROM documents GROUP BY document_type_code HAVING count(*) > 4
Find the types of documents with more than 4 documents.
PRAGMA foreign_keys = ON; CREATE TABLE `Roles` ( `role_code` VARCHAR(15) PRIMARY KEY, `role_description` VARCHAR(80) ); CREATE TABLE `Users` ( `user_id` INTEGER PRIMARY KEY, `role_code` VARCHAR(15) NOT NULL, `user_name` VARCHAR(40), `user_login` VARCHAR(40), `password` VARCHAR(40), FOREIGN KEY (`role_code` ) REFERENCES `Roles`(`role_code` ) ); CREATE TABLE `Document_Structures` ( `document_structure_code` VARCHAR(15) PRIMARY KEY, `parent_document_structure_code` VARCHAR(15), `document_structure_description` VARCHAR(80) ); CREATE TABLE `Functional_Areas` ( `functional_area_code` VARCHAR(15) PRIMARY KEY, `parent_functional_area_code` VARCHAR(15), `functional_area_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Images` ( `image_id` INTEGER PRIMARY KEY, `image_alt_text` VARCHAR(80), `image_name` VARCHAR(40), `image_url` VARCHAR(255) ); CREATE TABLE `Documents` ( `document_code` VARCHAR(15) PRIMARY KEY, `document_structure_code` VARCHAR(15) NOT NULL, `document_type_code` VARCHAR(15) NOT NULL, `access_count` INTEGER, `document_name` VARCHAR(80), FOREIGN KEY (`document_structure_code` ) REFERENCES `Document_Structures`(`document_structure_code` ) ); CREATE TABLE `Document_Functional_Areas` ( `document_code` VARCHAR(15) NOT NULL, `functional_area_code` VARCHAR(15) NOT NULL, FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ), FOREIGN KEY (`functional_area_code` ) REFERENCES `Functional_Areas`(`functional_area_code` ) ); CREATE TABLE `Document_Sections` ( `section_id` INTEGER PRIMARY KEY, `document_code` VARCHAR(15) NOT NULL, `section_sequence` INTEGER, `section_code` VARCHAR(20), `section_title` VARCHAR(80), FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ) ); CREATE TABLE `Document_Sections_Images` ( `section_id` INTEGER NOT NULL, `image_id` INTEGER NOT NULL, PRIMARY KEY (`section_id`,`image_id`), FOREIGN KEY (`section_id` ) REFERENCES `Document_Sections`(`section_id` ), FOREIGN KEY (`image_id` ) REFERENCES `Images`(`image_id` ) ); INSERT INTO Roles (`role_code`, `role_description`) VALUES ('DBA', 'Database Administrator')INSERT INTO Users (`user_id`, `role_code`, `user_name`, `user_login`, `password`) VALUES (1, 'PROJ-MGR', 'dickens.elta', '0', 'e72b5a2d50b39a8760764a5f7a9d68ca2f076877')INSERT INTO Document_Structures (`document_structure_code`, `parent_document_structure_code`, `document_structure_description`) VALUES ('1', '1', 'Header')INSERT INTO Functional_Areas (`functional_area_code`, `parent_functional_area_code`, `functional_area_description`) VALUES ('8', '8', 'Signature')INSERT INTO Images (`image_id`, `image_alt_text`, `image_name`, `image_url`) VALUES (1, 'Lea', 'top1', 'http://www.rempelnader.com/1.jpg')INSERT INTO Documents (`document_code`, `document_structure_code`, `document_type_code`, `access_count`, `document_name`) VALUES ('217', '8', 'Book', 1864, 'Learning English')INSERT INTO Document_Functional_Areas (`document_code`, `functional_area_code`) VALUES ('675', '9')INSERT INTO Document_Sections (`section_id`, `document_code`, `section_sequence`, `section_code`, `section_title`) VALUES (40, '465', 4964, '93', 'after')INSERT INTO Document_Sections_Images (`section_id`, `image_id`) VALUES (93, 6)
document_management
SELECT document_type_code FROM documents GROUP BY document_type_code HAVING count(*) > 4
What are the codes of types of documents of which there are for or more?
PRAGMA foreign_keys = ON; CREATE TABLE `Roles` ( `role_code` VARCHAR(15) PRIMARY KEY, `role_description` VARCHAR(80) ); CREATE TABLE `Users` ( `user_id` INTEGER PRIMARY KEY, `role_code` VARCHAR(15) NOT NULL, `user_name` VARCHAR(40), `user_login` VARCHAR(40), `password` VARCHAR(40), FOREIGN KEY (`role_code` ) REFERENCES `Roles`(`role_code` ) ); CREATE TABLE `Document_Structures` ( `document_structure_code` VARCHAR(15) PRIMARY KEY, `parent_document_structure_code` VARCHAR(15), `document_structure_description` VARCHAR(80) ); CREATE TABLE `Functional_Areas` ( `functional_area_code` VARCHAR(15) PRIMARY KEY, `parent_functional_area_code` VARCHAR(15), `functional_area_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Images` ( `image_id` INTEGER PRIMARY KEY, `image_alt_text` VARCHAR(80), `image_name` VARCHAR(40), `image_url` VARCHAR(255) ); CREATE TABLE `Documents` ( `document_code` VARCHAR(15) PRIMARY KEY, `document_structure_code` VARCHAR(15) NOT NULL, `document_type_code` VARCHAR(15) NOT NULL, `access_count` INTEGER, `document_name` VARCHAR(80), FOREIGN KEY (`document_structure_code` ) REFERENCES `Document_Structures`(`document_structure_code` ) ); CREATE TABLE `Document_Functional_Areas` ( `document_code` VARCHAR(15) NOT NULL, `functional_area_code` VARCHAR(15) NOT NULL, FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ), FOREIGN KEY (`functional_area_code` ) REFERENCES `Functional_Areas`(`functional_area_code` ) ); CREATE TABLE `Document_Sections` ( `section_id` INTEGER PRIMARY KEY, `document_code` VARCHAR(15) NOT NULL, `section_sequence` INTEGER, `section_code` VARCHAR(20), `section_title` VARCHAR(80), FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ) ); CREATE TABLE `Document_Sections_Images` ( `section_id` INTEGER NOT NULL, `image_id` INTEGER NOT NULL, PRIMARY KEY (`section_id`,`image_id`), FOREIGN KEY (`section_id` ) REFERENCES `Document_Sections`(`section_id` ), FOREIGN KEY (`image_id` ) REFERENCES `Images`(`image_id` ) ); INSERT INTO Roles (`role_code`, `role_description`) VALUES ('DBA', 'Database Administrator')INSERT INTO Users (`user_id`, `role_code`, `user_name`, `user_login`, `password`) VALUES (1, 'PROJ-MGR', 'dickens.elta', '0', 'e72b5a2d50b39a8760764a5f7a9d68ca2f076877')INSERT INTO Document_Structures (`document_structure_code`, `parent_document_structure_code`, `document_structure_description`) VALUES ('1', '1', 'Header')INSERT INTO Functional_Areas (`functional_area_code`, `parent_functional_area_code`, `functional_area_description`) VALUES ('8', '8', 'Signature')INSERT INTO Images (`image_id`, `image_alt_text`, `image_name`, `image_url`) VALUES (1, 'Lea', 'top1', 'http://www.rempelnader.com/1.jpg')INSERT INTO Documents (`document_code`, `document_structure_code`, `document_type_code`, `access_count`, `document_name`) VALUES ('217', '8', 'Book', 1864, 'Learning English')INSERT INTO Document_Functional_Areas (`document_code`, `functional_area_code`) VALUES ('675', '9')INSERT INTO Document_Sections (`section_id`, `document_code`, `section_sequence`, `section_code`, `section_title`) VALUES (40, '465', 4964, '93', 'after')INSERT INTO Document_Sections_Images (`section_id`, `image_id`) VALUES (93, 6)
document_management
SELECT sum(access_count) FROM documents GROUP BY document_type_code ORDER BY count(*) DESC LIMIT 1
Find the total access count of all documents in the most popular document type.
PRAGMA foreign_keys = ON; CREATE TABLE `Roles` ( `role_code` VARCHAR(15) PRIMARY KEY, `role_description` VARCHAR(80) ); CREATE TABLE `Users` ( `user_id` INTEGER PRIMARY KEY, `role_code` VARCHAR(15) NOT NULL, `user_name` VARCHAR(40), `user_login` VARCHAR(40), `password` VARCHAR(40), FOREIGN KEY (`role_code` ) REFERENCES `Roles`(`role_code` ) ); CREATE TABLE `Document_Structures` ( `document_structure_code` VARCHAR(15) PRIMARY KEY, `parent_document_structure_code` VARCHAR(15), `document_structure_description` VARCHAR(80) ); CREATE TABLE `Functional_Areas` ( `functional_area_code` VARCHAR(15) PRIMARY KEY, `parent_functional_area_code` VARCHAR(15), `functional_area_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Images` ( `image_id` INTEGER PRIMARY KEY, `image_alt_text` VARCHAR(80), `image_name` VARCHAR(40), `image_url` VARCHAR(255) ); CREATE TABLE `Documents` ( `document_code` VARCHAR(15) PRIMARY KEY, `document_structure_code` VARCHAR(15) NOT NULL, `document_type_code` VARCHAR(15) NOT NULL, `access_count` INTEGER, `document_name` VARCHAR(80), FOREIGN KEY (`document_structure_code` ) REFERENCES `Document_Structures`(`document_structure_code` ) ); CREATE TABLE `Document_Functional_Areas` ( `document_code` VARCHAR(15) NOT NULL, `functional_area_code` VARCHAR(15) NOT NULL, FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ), FOREIGN KEY (`functional_area_code` ) REFERENCES `Functional_Areas`(`functional_area_code` ) ); CREATE TABLE `Document_Sections` ( `section_id` INTEGER PRIMARY KEY, `document_code` VARCHAR(15) NOT NULL, `section_sequence` INTEGER, `section_code` VARCHAR(20), `section_title` VARCHAR(80), FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ) ); CREATE TABLE `Document_Sections_Images` ( `section_id` INTEGER NOT NULL, `image_id` INTEGER NOT NULL, PRIMARY KEY (`section_id`,`image_id`), FOREIGN KEY (`section_id` ) REFERENCES `Document_Sections`(`section_id` ), FOREIGN KEY (`image_id` ) REFERENCES `Images`(`image_id` ) ); INSERT INTO Roles (`role_code`, `role_description`) VALUES ('DBA', 'Database Administrator')INSERT INTO Users (`user_id`, `role_code`, `user_name`, `user_login`, `password`) VALUES (1, 'PROJ-MGR', 'dickens.elta', '0', 'e72b5a2d50b39a8760764a5f7a9d68ca2f076877')INSERT INTO Document_Structures (`document_structure_code`, `parent_document_structure_code`, `document_structure_description`) VALUES ('1', '1', 'Header')INSERT INTO Functional_Areas (`functional_area_code`, `parent_functional_area_code`, `functional_area_description`) VALUES ('8', '8', 'Signature')INSERT INTO Images (`image_id`, `image_alt_text`, `image_name`, `image_url`) VALUES (1, 'Lea', 'top1', 'http://www.rempelnader.com/1.jpg')INSERT INTO Documents (`document_code`, `document_structure_code`, `document_type_code`, `access_count`, `document_name`) VALUES ('217', '8', 'Book', 1864, 'Learning English')INSERT INTO Document_Functional_Areas (`document_code`, `functional_area_code`) VALUES ('675', '9')INSERT INTO Document_Sections (`section_id`, `document_code`, `section_sequence`, `section_code`, `section_title`) VALUES (40, '465', 4964, '93', 'after')INSERT INTO Document_Sections_Images (`section_id`, `image_id`) VALUES (93, 6)
document_management
SELECT sum(access_count) FROM documents GROUP BY document_type_code ORDER BY count(*) DESC LIMIT 1
What is the total access count of documents that are of the most common document type?
PRAGMA foreign_keys = ON; CREATE TABLE `Roles` ( `role_code` VARCHAR(15) PRIMARY KEY, `role_description` VARCHAR(80) ); CREATE TABLE `Users` ( `user_id` INTEGER PRIMARY KEY, `role_code` VARCHAR(15) NOT NULL, `user_name` VARCHAR(40), `user_login` VARCHAR(40), `password` VARCHAR(40), FOREIGN KEY (`role_code` ) REFERENCES `Roles`(`role_code` ) ); CREATE TABLE `Document_Structures` ( `document_structure_code` VARCHAR(15) PRIMARY KEY, `parent_document_structure_code` VARCHAR(15), `document_structure_description` VARCHAR(80) ); CREATE TABLE `Functional_Areas` ( `functional_area_code` VARCHAR(15) PRIMARY KEY, `parent_functional_area_code` VARCHAR(15), `functional_area_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Images` ( `image_id` INTEGER PRIMARY KEY, `image_alt_text` VARCHAR(80), `image_name` VARCHAR(40), `image_url` VARCHAR(255) ); CREATE TABLE `Documents` ( `document_code` VARCHAR(15) PRIMARY KEY, `document_structure_code` VARCHAR(15) NOT NULL, `document_type_code` VARCHAR(15) NOT NULL, `access_count` INTEGER, `document_name` VARCHAR(80), FOREIGN KEY (`document_structure_code` ) REFERENCES `Document_Structures`(`document_structure_code` ) ); CREATE TABLE `Document_Functional_Areas` ( `document_code` VARCHAR(15) NOT NULL, `functional_area_code` VARCHAR(15) NOT NULL, FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ), FOREIGN KEY (`functional_area_code` ) REFERENCES `Functional_Areas`(`functional_area_code` ) ); CREATE TABLE `Document_Sections` ( `section_id` INTEGER PRIMARY KEY, `document_code` VARCHAR(15) NOT NULL, `section_sequence` INTEGER, `section_code` VARCHAR(20), `section_title` VARCHAR(80), FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ) ); CREATE TABLE `Document_Sections_Images` ( `section_id` INTEGER NOT NULL, `image_id` INTEGER NOT NULL, PRIMARY KEY (`section_id`,`image_id`), FOREIGN KEY (`section_id` ) REFERENCES `Document_Sections`(`section_id` ), FOREIGN KEY (`image_id` ) REFERENCES `Images`(`image_id` ) ); INSERT INTO Roles (`role_code`, `role_description`) VALUES ('DBA', 'Database Administrator')INSERT INTO Users (`user_id`, `role_code`, `user_name`, `user_login`, `password`) VALUES (1, 'PROJ-MGR', 'dickens.elta', '0', 'e72b5a2d50b39a8760764a5f7a9d68ca2f076877')INSERT INTO Document_Structures (`document_structure_code`, `parent_document_structure_code`, `document_structure_description`) VALUES ('1', '1', 'Header')INSERT INTO Functional_Areas (`functional_area_code`, `parent_functional_area_code`, `functional_area_description`) VALUES ('8', '8', 'Signature')INSERT INTO Images (`image_id`, `image_alt_text`, `image_name`, `image_url`) VALUES (1, 'Lea', 'top1', 'http://www.rempelnader.com/1.jpg')INSERT INTO Documents (`document_code`, `document_structure_code`, `document_type_code`, `access_count`, `document_name`) VALUES ('217', '8', 'Book', 1864, 'Learning English')INSERT INTO Document_Functional_Areas (`document_code`, `functional_area_code`) VALUES ('675', '9')INSERT INTO Document_Sections (`section_id`, `document_code`, `section_sequence`, `section_code`, `section_title`) VALUES (40, '465', 4964, '93', 'after')INSERT INTO Document_Sections_Images (`section_id`, `image_id`) VALUES (93, 6)
document_management
SELECT avg(access_count) FROM documents
What is the average access count of documents?
PRAGMA foreign_keys = ON; CREATE TABLE `Roles` ( `role_code` VARCHAR(15) PRIMARY KEY, `role_description` VARCHAR(80) ); CREATE TABLE `Users` ( `user_id` INTEGER PRIMARY KEY, `role_code` VARCHAR(15) NOT NULL, `user_name` VARCHAR(40), `user_login` VARCHAR(40), `password` VARCHAR(40), FOREIGN KEY (`role_code` ) REFERENCES `Roles`(`role_code` ) ); CREATE TABLE `Document_Structures` ( `document_structure_code` VARCHAR(15) PRIMARY KEY, `parent_document_structure_code` VARCHAR(15), `document_structure_description` VARCHAR(80) ); CREATE TABLE `Functional_Areas` ( `functional_area_code` VARCHAR(15) PRIMARY KEY, `parent_functional_area_code` VARCHAR(15), `functional_area_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Images` ( `image_id` INTEGER PRIMARY KEY, `image_alt_text` VARCHAR(80), `image_name` VARCHAR(40), `image_url` VARCHAR(255) ); CREATE TABLE `Documents` ( `document_code` VARCHAR(15) PRIMARY KEY, `document_structure_code` VARCHAR(15) NOT NULL, `document_type_code` VARCHAR(15) NOT NULL, `access_count` INTEGER, `document_name` VARCHAR(80), FOREIGN KEY (`document_structure_code` ) REFERENCES `Document_Structures`(`document_structure_code` ) ); CREATE TABLE `Document_Functional_Areas` ( `document_code` VARCHAR(15) NOT NULL, `functional_area_code` VARCHAR(15) NOT NULL, FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ), FOREIGN KEY (`functional_area_code` ) REFERENCES `Functional_Areas`(`functional_area_code` ) ); CREATE TABLE `Document_Sections` ( `section_id` INTEGER PRIMARY KEY, `document_code` VARCHAR(15) NOT NULL, `section_sequence` INTEGER, `section_code` VARCHAR(20), `section_title` VARCHAR(80), FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ) ); CREATE TABLE `Document_Sections_Images` ( `section_id` INTEGER NOT NULL, `image_id` INTEGER NOT NULL, PRIMARY KEY (`section_id`,`image_id`), FOREIGN KEY (`section_id` ) REFERENCES `Document_Sections`(`section_id` ), FOREIGN KEY (`image_id` ) REFERENCES `Images`(`image_id` ) ); INSERT INTO Roles (`role_code`, `role_description`) VALUES ('DBA', 'Database Administrator')INSERT INTO Users (`user_id`, `role_code`, `user_name`, `user_login`, `password`) VALUES (1, 'PROJ-MGR', 'dickens.elta', '0', 'e72b5a2d50b39a8760764a5f7a9d68ca2f076877')INSERT INTO Document_Structures (`document_structure_code`, `parent_document_structure_code`, `document_structure_description`) VALUES ('1', '1', 'Header')INSERT INTO Functional_Areas (`functional_area_code`, `parent_functional_area_code`, `functional_area_description`) VALUES ('8', '8', 'Signature')INSERT INTO Images (`image_id`, `image_alt_text`, `image_name`, `image_url`) VALUES (1, 'Lea', 'top1', 'http://www.rempelnader.com/1.jpg')INSERT INTO Documents (`document_code`, `document_structure_code`, `document_type_code`, `access_count`, `document_name`) VALUES ('217', '8', 'Book', 1864, 'Learning English')INSERT INTO Document_Functional_Areas (`document_code`, `functional_area_code`) VALUES ('675', '9')INSERT INTO Document_Sections (`section_id`, `document_code`, `section_sequence`, `section_code`, `section_title`) VALUES (40, '465', 4964, '93', 'after')INSERT INTO Document_Sections_Images (`section_id`, `image_id`) VALUES (93, 6)
document_management
SELECT avg(access_count) FROM documents
Find the average access count across all documents?
PRAGMA foreign_keys = ON; CREATE TABLE `Roles` ( `role_code` VARCHAR(15) PRIMARY KEY, `role_description` VARCHAR(80) ); CREATE TABLE `Users` ( `user_id` INTEGER PRIMARY KEY, `role_code` VARCHAR(15) NOT NULL, `user_name` VARCHAR(40), `user_login` VARCHAR(40), `password` VARCHAR(40), FOREIGN KEY (`role_code` ) REFERENCES `Roles`(`role_code` ) ); CREATE TABLE `Document_Structures` ( `document_structure_code` VARCHAR(15) PRIMARY KEY, `parent_document_structure_code` VARCHAR(15), `document_structure_description` VARCHAR(80) ); CREATE TABLE `Functional_Areas` ( `functional_area_code` VARCHAR(15) PRIMARY KEY, `parent_functional_area_code` VARCHAR(15), `functional_area_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Images` ( `image_id` INTEGER PRIMARY KEY, `image_alt_text` VARCHAR(80), `image_name` VARCHAR(40), `image_url` VARCHAR(255) ); CREATE TABLE `Documents` ( `document_code` VARCHAR(15) PRIMARY KEY, `document_structure_code` VARCHAR(15) NOT NULL, `document_type_code` VARCHAR(15) NOT NULL, `access_count` INTEGER, `document_name` VARCHAR(80), FOREIGN KEY (`document_structure_code` ) REFERENCES `Document_Structures`(`document_structure_code` ) ); CREATE TABLE `Document_Functional_Areas` ( `document_code` VARCHAR(15) NOT NULL, `functional_area_code` VARCHAR(15) NOT NULL, FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ), FOREIGN KEY (`functional_area_code` ) REFERENCES `Functional_Areas`(`functional_area_code` ) ); CREATE TABLE `Document_Sections` ( `section_id` INTEGER PRIMARY KEY, `document_code` VARCHAR(15) NOT NULL, `section_sequence` INTEGER, `section_code` VARCHAR(20), `section_title` VARCHAR(80), FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ) ); CREATE TABLE `Document_Sections_Images` ( `section_id` INTEGER NOT NULL, `image_id` INTEGER NOT NULL, PRIMARY KEY (`section_id`,`image_id`), FOREIGN KEY (`section_id` ) REFERENCES `Document_Sections`(`section_id` ), FOREIGN KEY (`image_id` ) REFERENCES `Images`(`image_id` ) ); INSERT INTO Roles (`role_code`, `role_description`) VALUES ('DBA', 'Database Administrator')INSERT INTO Users (`user_id`, `role_code`, `user_name`, `user_login`, `password`) VALUES (1, 'PROJ-MGR', 'dickens.elta', '0', 'e72b5a2d50b39a8760764a5f7a9d68ca2f076877')INSERT INTO Document_Structures (`document_structure_code`, `parent_document_structure_code`, `document_structure_description`) VALUES ('1', '1', 'Header')INSERT INTO Functional_Areas (`functional_area_code`, `parent_functional_area_code`, `functional_area_description`) VALUES ('8', '8', 'Signature')INSERT INTO Images (`image_id`, `image_alt_text`, `image_name`, `image_url`) VALUES (1, 'Lea', 'top1', 'http://www.rempelnader.com/1.jpg')INSERT INTO Documents (`document_code`, `document_structure_code`, `document_type_code`, `access_count`, `document_name`) VALUES ('217', '8', 'Book', 1864, 'Learning English')INSERT INTO Document_Functional_Areas (`document_code`, `functional_area_code`) VALUES ('675', '9')INSERT INTO Document_Sections (`section_id`, `document_code`, `section_sequence`, `section_code`, `section_title`) VALUES (40, '465', 4964, '93', 'after')INSERT INTO Document_Sections_Images (`section_id`, `image_id`) VALUES (93, 6)
document_management
SELECT t2.document_structure_description FROM documents AS t1 JOIN document_structures AS t2 ON t1.document_structure_code = t2.document_structure_code GROUP BY t1.document_structure_code ORDER BY count(*) DESC LIMIT 1
What is the structure of the document with the least number of accesses?
PRAGMA foreign_keys = ON; CREATE TABLE `Roles` ( `role_code` VARCHAR(15) PRIMARY KEY, `role_description` VARCHAR(80) ); CREATE TABLE `Users` ( `user_id` INTEGER PRIMARY KEY, `role_code` VARCHAR(15) NOT NULL, `user_name` VARCHAR(40), `user_login` VARCHAR(40), `password` VARCHAR(40), FOREIGN KEY (`role_code` ) REFERENCES `Roles`(`role_code` ) ); CREATE TABLE `Document_Structures` ( `document_structure_code` VARCHAR(15) PRIMARY KEY, `parent_document_structure_code` VARCHAR(15), `document_structure_description` VARCHAR(80) ); CREATE TABLE `Functional_Areas` ( `functional_area_code` VARCHAR(15) PRIMARY KEY, `parent_functional_area_code` VARCHAR(15), `functional_area_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Images` ( `image_id` INTEGER PRIMARY KEY, `image_alt_text` VARCHAR(80), `image_name` VARCHAR(40), `image_url` VARCHAR(255) ); CREATE TABLE `Documents` ( `document_code` VARCHAR(15) PRIMARY KEY, `document_structure_code` VARCHAR(15) NOT NULL, `document_type_code` VARCHAR(15) NOT NULL, `access_count` INTEGER, `document_name` VARCHAR(80), FOREIGN KEY (`document_structure_code` ) REFERENCES `Document_Structures`(`document_structure_code` ) ); CREATE TABLE `Document_Functional_Areas` ( `document_code` VARCHAR(15) NOT NULL, `functional_area_code` VARCHAR(15) NOT NULL, FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ), FOREIGN KEY (`functional_area_code` ) REFERENCES `Functional_Areas`(`functional_area_code` ) ); CREATE TABLE `Document_Sections` ( `section_id` INTEGER PRIMARY KEY, `document_code` VARCHAR(15) NOT NULL, `section_sequence` INTEGER, `section_code` VARCHAR(20), `section_title` VARCHAR(80), FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ) ); CREATE TABLE `Document_Sections_Images` ( `section_id` INTEGER NOT NULL, `image_id` INTEGER NOT NULL, PRIMARY KEY (`section_id`,`image_id`), FOREIGN KEY (`section_id` ) REFERENCES `Document_Sections`(`section_id` ), FOREIGN KEY (`image_id` ) REFERENCES `Images`(`image_id` ) ); INSERT INTO Roles (`role_code`, `role_description`) VALUES ('DBA', 'Database Administrator')INSERT INTO Users (`user_id`, `role_code`, `user_name`, `user_login`, `password`) VALUES (1, 'PROJ-MGR', 'dickens.elta', '0', 'e72b5a2d50b39a8760764a5f7a9d68ca2f076877')INSERT INTO Document_Structures (`document_structure_code`, `parent_document_structure_code`, `document_structure_description`) VALUES ('1', '1', 'Header')INSERT INTO Functional_Areas (`functional_area_code`, `parent_functional_area_code`, `functional_area_description`) VALUES ('8', '8', 'Signature')INSERT INTO Images (`image_id`, `image_alt_text`, `image_name`, `image_url`) VALUES (1, 'Lea', 'top1', 'http://www.rempelnader.com/1.jpg')INSERT INTO Documents (`document_code`, `document_structure_code`, `document_type_code`, `access_count`, `document_name`) VALUES ('217', '8', 'Book', 1864, 'Learning English')INSERT INTO Document_Functional_Areas (`document_code`, `functional_area_code`) VALUES ('675', '9')INSERT INTO Document_Sections (`section_id`, `document_code`, `section_sequence`, `section_code`, `section_title`) VALUES (40, '465', 4964, '93', 'after')INSERT INTO Document_Sections_Images (`section_id`, `image_id`) VALUES (93, 6)
document_management
SELECT t2.document_structure_description FROM documents AS t1 JOIN document_structures AS t2 ON t1.document_structure_code = t2.document_structure_code GROUP BY t1.document_structure_code ORDER BY count(*) DESC LIMIT 1
Return the structure description of the document that has been accessed the fewest number of times.
PRAGMA foreign_keys = ON; CREATE TABLE `Roles` ( `role_code` VARCHAR(15) PRIMARY KEY, `role_description` VARCHAR(80) ); CREATE TABLE `Users` ( `user_id` INTEGER PRIMARY KEY, `role_code` VARCHAR(15) NOT NULL, `user_name` VARCHAR(40), `user_login` VARCHAR(40), `password` VARCHAR(40), FOREIGN KEY (`role_code` ) REFERENCES `Roles`(`role_code` ) ); CREATE TABLE `Document_Structures` ( `document_structure_code` VARCHAR(15) PRIMARY KEY, `parent_document_structure_code` VARCHAR(15), `document_structure_description` VARCHAR(80) ); CREATE TABLE `Functional_Areas` ( `functional_area_code` VARCHAR(15) PRIMARY KEY, `parent_functional_area_code` VARCHAR(15), `functional_area_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Images` ( `image_id` INTEGER PRIMARY KEY, `image_alt_text` VARCHAR(80), `image_name` VARCHAR(40), `image_url` VARCHAR(255) ); CREATE TABLE `Documents` ( `document_code` VARCHAR(15) PRIMARY KEY, `document_structure_code` VARCHAR(15) NOT NULL, `document_type_code` VARCHAR(15) NOT NULL, `access_count` INTEGER, `document_name` VARCHAR(80), FOREIGN KEY (`document_structure_code` ) REFERENCES `Document_Structures`(`document_structure_code` ) ); CREATE TABLE `Document_Functional_Areas` ( `document_code` VARCHAR(15) NOT NULL, `functional_area_code` VARCHAR(15) NOT NULL, FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ), FOREIGN KEY (`functional_area_code` ) REFERENCES `Functional_Areas`(`functional_area_code` ) ); CREATE TABLE `Document_Sections` ( `section_id` INTEGER PRIMARY KEY, `document_code` VARCHAR(15) NOT NULL, `section_sequence` INTEGER, `section_code` VARCHAR(20), `section_title` VARCHAR(80), FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ) ); CREATE TABLE `Document_Sections_Images` ( `section_id` INTEGER NOT NULL, `image_id` INTEGER NOT NULL, PRIMARY KEY (`section_id`,`image_id`), FOREIGN KEY (`section_id` ) REFERENCES `Document_Sections`(`section_id` ), FOREIGN KEY (`image_id` ) REFERENCES `Images`(`image_id` ) ); INSERT INTO Roles (`role_code`, `role_description`) VALUES ('DBA', 'Database Administrator')INSERT INTO Users (`user_id`, `role_code`, `user_name`, `user_login`, `password`) VALUES (1, 'PROJ-MGR', 'dickens.elta', '0', 'e72b5a2d50b39a8760764a5f7a9d68ca2f076877')INSERT INTO Document_Structures (`document_structure_code`, `parent_document_structure_code`, `document_structure_description`) VALUES ('1', '1', 'Header')INSERT INTO Functional_Areas (`functional_area_code`, `parent_functional_area_code`, `functional_area_description`) VALUES ('8', '8', 'Signature')INSERT INTO Images (`image_id`, `image_alt_text`, `image_name`, `image_url`) VALUES (1, 'Lea', 'top1', 'http://www.rempelnader.com/1.jpg')INSERT INTO Documents (`document_code`, `document_structure_code`, `document_type_code`, `access_count`, `document_name`) VALUES ('217', '8', 'Book', 1864, 'Learning English')INSERT INTO Document_Functional_Areas (`document_code`, `functional_area_code`) VALUES ('675', '9')INSERT INTO Document_Sections (`section_id`, `document_code`, `section_sequence`, `section_code`, `section_title`) VALUES (40, '465', 4964, '93', 'after')INSERT INTO Document_Sections_Images (`section_id`, `image_id`) VALUES (93, 6)
document_management
SELECT document_type_code FROM documents WHERE document_name = "David CV"
What is the type of the document named "David CV"?
PRAGMA foreign_keys = ON; CREATE TABLE `Roles` ( `role_code` VARCHAR(15) PRIMARY KEY, `role_description` VARCHAR(80) ); CREATE TABLE `Users` ( `user_id` INTEGER PRIMARY KEY, `role_code` VARCHAR(15) NOT NULL, `user_name` VARCHAR(40), `user_login` VARCHAR(40), `password` VARCHAR(40), FOREIGN KEY (`role_code` ) REFERENCES `Roles`(`role_code` ) ); CREATE TABLE `Document_Structures` ( `document_structure_code` VARCHAR(15) PRIMARY KEY, `parent_document_structure_code` VARCHAR(15), `document_structure_description` VARCHAR(80) ); CREATE TABLE `Functional_Areas` ( `functional_area_code` VARCHAR(15) PRIMARY KEY, `parent_functional_area_code` VARCHAR(15), `functional_area_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Images` ( `image_id` INTEGER PRIMARY KEY, `image_alt_text` VARCHAR(80), `image_name` VARCHAR(40), `image_url` VARCHAR(255) ); CREATE TABLE `Documents` ( `document_code` VARCHAR(15) PRIMARY KEY, `document_structure_code` VARCHAR(15) NOT NULL, `document_type_code` VARCHAR(15) NOT NULL, `access_count` INTEGER, `document_name` VARCHAR(80), FOREIGN KEY (`document_structure_code` ) REFERENCES `Document_Structures`(`document_structure_code` ) ); CREATE TABLE `Document_Functional_Areas` ( `document_code` VARCHAR(15) NOT NULL, `functional_area_code` VARCHAR(15) NOT NULL, FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ), FOREIGN KEY (`functional_area_code` ) REFERENCES `Functional_Areas`(`functional_area_code` ) ); CREATE TABLE `Document_Sections` ( `section_id` INTEGER PRIMARY KEY, `document_code` VARCHAR(15) NOT NULL, `section_sequence` INTEGER, `section_code` VARCHAR(20), `section_title` VARCHAR(80), FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ) ); CREATE TABLE `Document_Sections_Images` ( `section_id` INTEGER NOT NULL, `image_id` INTEGER NOT NULL, PRIMARY KEY (`section_id`,`image_id`), FOREIGN KEY (`section_id` ) REFERENCES `Document_Sections`(`section_id` ), FOREIGN KEY (`image_id` ) REFERENCES `Images`(`image_id` ) ); INSERT INTO Roles (`role_code`, `role_description`) VALUES ('DBA', 'Database Administrator')INSERT INTO Users (`user_id`, `role_code`, `user_name`, `user_login`, `password`) VALUES (1, 'PROJ-MGR', 'dickens.elta', '0', 'e72b5a2d50b39a8760764a5f7a9d68ca2f076877')INSERT INTO Document_Structures (`document_structure_code`, `parent_document_structure_code`, `document_structure_description`) VALUES ('1', '1', 'Header')INSERT INTO Functional_Areas (`functional_area_code`, `parent_functional_area_code`, `functional_area_description`) VALUES ('8', '8', 'Signature')INSERT INTO Images (`image_id`, `image_alt_text`, `image_name`, `image_url`) VALUES (1, 'Lea', 'top1', 'http://www.rempelnader.com/1.jpg')INSERT INTO Documents (`document_code`, `document_structure_code`, `document_type_code`, `access_count`, `document_name`) VALUES ('217', '8', 'Book', 1864, 'Learning English')INSERT INTO Document_Functional_Areas (`document_code`, `functional_area_code`) VALUES ('675', '9')INSERT INTO Document_Sections (`section_id`, `document_code`, `section_sequence`, `section_code`, `section_title`) VALUES (40, '465', 4964, '93', 'after')INSERT INTO Document_Sections_Images (`section_id`, `image_id`) VALUES (93, 6)
document_management
SELECT document_type_code FROM documents WHERE document_name = "David CV"
Return the type code of the document named "David CV".
PRAGMA foreign_keys = ON; CREATE TABLE `Roles` ( `role_code` VARCHAR(15) PRIMARY KEY, `role_description` VARCHAR(80) ); CREATE TABLE `Users` ( `user_id` INTEGER PRIMARY KEY, `role_code` VARCHAR(15) NOT NULL, `user_name` VARCHAR(40), `user_login` VARCHAR(40), `password` VARCHAR(40), FOREIGN KEY (`role_code` ) REFERENCES `Roles`(`role_code` ) ); CREATE TABLE `Document_Structures` ( `document_structure_code` VARCHAR(15) PRIMARY KEY, `parent_document_structure_code` VARCHAR(15), `document_structure_description` VARCHAR(80) ); CREATE TABLE `Functional_Areas` ( `functional_area_code` VARCHAR(15) PRIMARY KEY, `parent_functional_area_code` VARCHAR(15), `functional_area_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Images` ( `image_id` INTEGER PRIMARY KEY, `image_alt_text` VARCHAR(80), `image_name` VARCHAR(40), `image_url` VARCHAR(255) ); CREATE TABLE `Documents` ( `document_code` VARCHAR(15) PRIMARY KEY, `document_structure_code` VARCHAR(15) NOT NULL, `document_type_code` VARCHAR(15) NOT NULL, `access_count` INTEGER, `document_name` VARCHAR(80), FOREIGN KEY (`document_structure_code` ) REFERENCES `Document_Structures`(`document_structure_code` ) ); CREATE TABLE `Document_Functional_Areas` ( `document_code` VARCHAR(15) NOT NULL, `functional_area_code` VARCHAR(15) NOT NULL, FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ), FOREIGN KEY (`functional_area_code` ) REFERENCES `Functional_Areas`(`functional_area_code` ) ); CREATE TABLE `Document_Sections` ( `section_id` INTEGER PRIMARY KEY, `document_code` VARCHAR(15) NOT NULL, `section_sequence` INTEGER, `section_code` VARCHAR(20), `section_title` VARCHAR(80), FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ) ); CREATE TABLE `Document_Sections_Images` ( `section_id` INTEGER NOT NULL, `image_id` INTEGER NOT NULL, PRIMARY KEY (`section_id`,`image_id`), FOREIGN KEY (`section_id` ) REFERENCES `Document_Sections`(`section_id` ), FOREIGN KEY (`image_id` ) REFERENCES `Images`(`image_id` ) ); INSERT INTO Roles (`role_code`, `role_description`) VALUES ('DBA', 'Database Administrator')INSERT INTO Users (`user_id`, `role_code`, `user_name`, `user_login`, `password`) VALUES (1, 'PROJ-MGR', 'dickens.elta', '0', 'e72b5a2d50b39a8760764a5f7a9d68ca2f076877')INSERT INTO Document_Structures (`document_structure_code`, `parent_document_structure_code`, `document_structure_description`) VALUES ('1', '1', 'Header')INSERT INTO Functional_Areas (`functional_area_code`, `parent_functional_area_code`, `functional_area_description`) VALUES ('8', '8', 'Signature')INSERT INTO Images (`image_id`, `image_alt_text`, `image_name`, `image_url`) VALUES (1, 'Lea', 'top1', 'http://www.rempelnader.com/1.jpg')INSERT INTO Documents (`document_code`, `document_structure_code`, `document_type_code`, `access_count`, `document_name`) VALUES ('217', '8', 'Book', 1864, 'Learning English')INSERT INTO Document_Functional_Areas (`document_code`, `functional_area_code`) VALUES ('675', '9')INSERT INTO Document_Sections (`section_id`, `document_code`, `section_sequence`, `section_code`, `section_title`) VALUES (40, '465', 4964, '93', 'after')INSERT INTO Document_Sections_Images (`section_id`, `image_id`) VALUES (93, 6)
document_management
SELECT document_name FROM documents GROUP BY document_type_code ORDER BY count(*) DESC LIMIT 3 INTERSECT SELECT document_name FROM documents GROUP BY document_structure_code ORDER BY count(*) DESC LIMIT 3
Find the list of documents that are both in the most three popular type and have the most three popular structure.
PRAGMA foreign_keys = ON; CREATE TABLE `Roles` ( `role_code` VARCHAR(15) PRIMARY KEY, `role_description` VARCHAR(80) ); CREATE TABLE `Users` ( `user_id` INTEGER PRIMARY KEY, `role_code` VARCHAR(15) NOT NULL, `user_name` VARCHAR(40), `user_login` VARCHAR(40), `password` VARCHAR(40), FOREIGN KEY (`role_code` ) REFERENCES `Roles`(`role_code` ) ); CREATE TABLE `Document_Structures` ( `document_structure_code` VARCHAR(15) PRIMARY KEY, `parent_document_structure_code` VARCHAR(15), `document_structure_description` VARCHAR(80) ); CREATE TABLE `Functional_Areas` ( `functional_area_code` VARCHAR(15) PRIMARY KEY, `parent_functional_area_code` VARCHAR(15), `functional_area_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Images` ( `image_id` INTEGER PRIMARY KEY, `image_alt_text` VARCHAR(80), `image_name` VARCHAR(40), `image_url` VARCHAR(255) ); CREATE TABLE `Documents` ( `document_code` VARCHAR(15) PRIMARY KEY, `document_structure_code` VARCHAR(15) NOT NULL, `document_type_code` VARCHAR(15) NOT NULL, `access_count` INTEGER, `document_name` VARCHAR(80), FOREIGN KEY (`document_structure_code` ) REFERENCES `Document_Structures`(`document_structure_code` ) ); CREATE TABLE `Document_Functional_Areas` ( `document_code` VARCHAR(15) NOT NULL, `functional_area_code` VARCHAR(15) NOT NULL, FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ), FOREIGN KEY (`functional_area_code` ) REFERENCES `Functional_Areas`(`functional_area_code` ) ); CREATE TABLE `Document_Sections` ( `section_id` INTEGER PRIMARY KEY, `document_code` VARCHAR(15) NOT NULL, `section_sequence` INTEGER, `section_code` VARCHAR(20), `section_title` VARCHAR(80), FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ) ); CREATE TABLE `Document_Sections_Images` ( `section_id` INTEGER NOT NULL, `image_id` INTEGER NOT NULL, PRIMARY KEY (`section_id`,`image_id`), FOREIGN KEY (`section_id` ) REFERENCES `Document_Sections`(`section_id` ), FOREIGN KEY (`image_id` ) REFERENCES `Images`(`image_id` ) ); INSERT INTO Roles (`role_code`, `role_description`) VALUES ('DBA', 'Database Administrator')INSERT INTO Users (`user_id`, `role_code`, `user_name`, `user_login`, `password`) VALUES (1, 'PROJ-MGR', 'dickens.elta', '0', 'e72b5a2d50b39a8760764a5f7a9d68ca2f076877')INSERT INTO Document_Structures (`document_structure_code`, `parent_document_structure_code`, `document_structure_description`) VALUES ('1', '1', 'Header')INSERT INTO Functional_Areas (`functional_area_code`, `parent_functional_area_code`, `functional_area_description`) VALUES ('8', '8', 'Signature')INSERT INTO Images (`image_id`, `image_alt_text`, `image_name`, `image_url`) VALUES (1, 'Lea', 'top1', 'http://www.rempelnader.com/1.jpg')INSERT INTO Documents (`document_code`, `document_structure_code`, `document_type_code`, `access_count`, `document_name`) VALUES ('217', '8', 'Book', 1864, 'Learning English')INSERT INTO Document_Functional_Areas (`document_code`, `functional_area_code`) VALUES ('675', '9')INSERT INTO Document_Sections (`section_id`, `document_code`, `section_sequence`, `section_code`, `section_title`) VALUES (40, '465', 4964, '93', 'after')INSERT INTO Document_Sections_Images (`section_id`, `image_id`) VALUES (93, 6)
document_management
SELECT document_name FROM documents GROUP BY document_type_code ORDER BY count(*) DESC LIMIT 3 INTERSECT SELECT document_name FROM documents GROUP BY document_structure_code ORDER BY count(*) DESC LIMIT 3
What are the names of documents that have both one of the three most common types and one of three most common structures?
PRAGMA foreign_keys = ON; CREATE TABLE `Roles` ( `role_code` VARCHAR(15) PRIMARY KEY, `role_description` VARCHAR(80) ); CREATE TABLE `Users` ( `user_id` INTEGER PRIMARY KEY, `role_code` VARCHAR(15) NOT NULL, `user_name` VARCHAR(40), `user_login` VARCHAR(40), `password` VARCHAR(40), FOREIGN KEY (`role_code` ) REFERENCES `Roles`(`role_code` ) ); CREATE TABLE `Document_Structures` ( `document_structure_code` VARCHAR(15) PRIMARY KEY, `parent_document_structure_code` VARCHAR(15), `document_structure_description` VARCHAR(80) ); CREATE TABLE `Functional_Areas` ( `functional_area_code` VARCHAR(15) PRIMARY KEY, `parent_functional_area_code` VARCHAR(15), `functional_area_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Images` ( `image_id` INTEGER PRIMARY KEY, `image_alt_text` VARCHAR(80), `image_name` VARCHAR(40), `image_url` VARCHAR(255) ); CREATE TABLE `Documents` ( `document_code` VARCHAR(15) PRIMARY KEY, `document_structure_code` VARCHAR(15) NOT NULL, `document_type_code` VARCHAR(15) NOT NULL, `access_count` INTEGER, `document_name` VARCHAR(80), FOREIGN KEY (`document_structure_code` ) REFERENCES `Document_Structures`(`document_structure_code` ) ); CREATE TABLE `Document_Functional_Areas` ( `document_code` VARCHAR(15) NOT NULL, `functional_area_code` VARCHAR(15) NOT NULL, FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ), FOREIGN KEY (`functional_area_code` ) REFERENCES `Functional_Areas`(`functional_area_code` ) ); CREATE TABLE `Document_Sections` ( `section_id` INTEGER PRIMARY KEY, `document_code` VARCHAR(15) NOT NULL, `section_sequence` INTEGER, `section_code` VARCHAR(20), `section_title` VARCHAR(80), FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ) ); CREATE TABLE `Document_Sections_Images` ( `section_id` INTEGER NOT NULL, `image_id` INTEGER NOT NULL, PRIMARY KEY (`section_id`,`image_id`), FOREIGN KEY (`section_id` ) REFERENCES `Document_Sections`(`section_id` ), FOREIGN KEY (`image_id` ) REFERENCES `Images`(`image_id` ) ); INSERT INTO Roles (`role_code`, `role_description`) VALUES ('DBA', 'Database Administrator')INSERT INTO Users (`user_id`, `role_code`, `user_name`, `user_login`, `password`) VALUES (1, 'PROJ-MGR', 'dickens.elta', '0', 'e72b5a2d50b39a8760764a5f7a9d68ca2f076877')INSERT INTO Document_Structures (`document_structure_code`, `parent_document_structure_code`, `document_structure_description`) VALUES ('1', '1', 'Header')INSERT INTO Functional_Areas (`functional_area_code`, `parent_functional_area_code`, `functional_area_description`) VALUES ('8', '8', 'Signature')INSERT INTO Images (`image_id`, `image_alt_text`, `image_name`, `image_url`) VALUES (1, 'Lea', 'top1', 'http://www.rempelnader.com/1.jpg')INSERT INTO Documents (`document_code`, `document_structure_code`, `document_type_code`, `access_count`, `document_name`) VALUES ('217', '8', 'Book', 1864, 'Learning English')INSERT INTO Document_Functional_Areas (`document_code`, `functional_area_code`) VALUES ('675', '9')INSERT INTO Document_Sections (`section_id`, `document_code`, `section_sequence`, `section_code`, `section_title`) VALUES (40, '465', 4964, '93', 'after')INSERT INTO Document_Sections_Images (`section_id`, `image_id`) VALUES (93, 6)
document_management
SELECT document_type_code FROM documents GROUP BY document_type_code HAVING sum(access_count) > 10000
What document types do have more than 10000 total access number.
PRAGMA foreign_keys = ON; CREATE TABLE `Roles` ( `role_code` VARCHAR(15) PRIMARY KEY, `role_description` VARCHAR(80) ); CREATE TABLE `Users` ( `user_id` INTEGER PRIMARY KEY, `role_code` VARCHAR(15) NOT NULL, `user_name` VARCHAR(40), `user_login` VARCHAR(40), `password` VARCHAR(40), FOREIGN KEY (`role_code` ) REFERENCES `Roles`(`role_code` ) ); CREATE TABLE `Document_Structures` ( `document_structure_code` VARCHAR(15) PRIMARY KEY, `parent_document_structure_code` VARCHAR(15), `document_structure_description` VARCHAR(80) ); CREATE TABLE `Functional_Areas` ( `functional_area_code` VARCHAR(15) PRIMARY KEY, `parent_functional_area_code` VARCHAR(15), `functional_area_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Images` ( `image_id` INTEGER PRIMARY KEY, `image_alt_text` VARCHAR(80), `image_name` VARCHAR(40), `image_url` VARCHAR(255) ); CREATE TABLE `Documents` ( `document_code` VARCHAR(15) PRIMARY KEY, `document_structure_code` VARCHAR(15) NOT NULL, `document_type_code` VARCHAR(15) NOT NULL, `access_count` INTEGER, `document_name` VARCHAR(80), FOREIGN KEY (`document_structure_code` ) REFERENCES `Document_Structures`(`document_structure_code` ) ); CREATE TABLE `Document_Functional_Areas` ( `document_code` VARCHAR(15) NOT NULL, `functional_area_code` VARCHAR(15) NOT NULL, FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ), FOREIGN KEY (`functional_area_code` ) REFERENCES `Functional_Areas`(`functional_area_code` ) ); CREATE TABLE `Document_Sections` ( `section_id` INTEGER PRIMARY KEY, `document_code` VARCHAR(15) NOT NULL, `section_sequence` INTEGER, `section_code` VARCHAR(20), `section_title` VARCHAR(80), FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ) ); CREATE TABLE `Document_Sections_Images` ( `section_id` INTEGER NOT NULL, `image_id` INTEGER NOT NULL, PRIMARY KEY (`section_id`,`image_id`), FOREIGN KEY (`section_id` ) REFERENCES `Document_Sections`(`section_id` ), FOREIGN KEY (`image_id` ) REFERENCES `Images`(`image_id` ) ); INSERT INTO Roles (`role_code`, `role_description`) VALUES ('DBA', 'Database Administrator')INSERT INTO Users (`user_id`, `role_code`, `user_name`, `user_login`, `password`) VALUES (1, 'PROJ-MGR', 'dickens.elta', '0', 'e72b5a2d50b39a8760764a5f7a9d68ca2f076877')INSERT INTO Document_Structures (`document_structure_code`, `parent_document_structure_code`, `document_structure_description`) VALUES ('1', '1', 'Header')INSERT INTO Functional_Areas (`functional_area_code`, `parent_functional_area_code`, `functional_area_description`) VALUES ('8', '8', 'Signature')INSERT INTO Images (`image_id`, `image_alt_text`, `image_name`, `image_url`) VALUES (1, 'Lea', 'top1', 'http://www.rempelnader.com/1.jpg')INSERT INTO Documents (`document_code`, `document_structure_code`, `document_type_code`, `access_count`, `document_name`) VALUES ('217', '8', 'Book', 1864, 'Learning English')INSERT INTO Document_Functional_Areas (`document_code`, `functional_area_code`) VALUES ('675', '9')INSERT INTO Document_Sections (`section_id`, `document_code`, `section_sequence`, `section_code`, `section_title`) VALUES (40, '465', 4964, '93', 'after')INSERT INTO Document_Sections_Images (`section_id`, `image_id`) VALUES (93, 6)
document_management
SELECT document_type_code FROM documents GROUP BY document_type_code HAVING sum(access_count) > 10000
Return the codes of the document types that do not have a total access count of over 10000.
PRAGMA foreign_keys = ON; CREATE TABLE `Roles` ( `role_code` VARCHAR(15) PRIMARY KEY, `role_description` VARCHAR(80) ); CREATE TABLE `Users` ( `user_id` INTEGER PRIMARY KEY, `role_code` VARCHAR(15) NOT NULL, `user_name` VARCHAR(40), `user_login` VARCHAR(40), `password` VARCHAR(40), FOREIGN KEY (`role_code` ) REFERENCES `Roles`(`role_code` ) ); CREATE TABLE `Document_Structures` ( `document_structure_code` VARCHAR(15) PRIMARY KEY, `parent_document_structure_code` VARCHAR(15), `document_structure_description` VARCHAR(80) ); CREATE TABLE `Functional_Areas` ( `functional_area_code` VARCHAR(15) PRIMARY KEY, `parent_functional_area_code` VARCHAR(15), `functional_area_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Images` ( `image_id` INTEGER PRIMARY KEY, `image_alt_text` VARCHAR(80), `image_name` VARCHAR(40), `image_url` VARCHAR(255) ); CREATE TABLE `Documents` ( `document_code` VARCHAR(15) PRIMARY KEY, `document_structure_code` VARCHAR(15) NOT NULL, `document_type_code` VARCHAR(15) NOT NULL, `access_count` INTEGER, `document_name` VARCHAR(80), FOREIGN KEY (`document_structure_code` ) REFERENCES `Document_Structures`(`document_structure_code` ) ); CREATE TABLE `Document_Functional_Areas` ( `document_code` VARCHAR(15) NOT NULL, `functional_area_code` VARCHAR(15) NOT NULL, FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ), FOREIGN KEY (`functional_area_code` ) REFERENCES `Functional_Areas`(`functional_area_code` ) ); CREATE TABLE `Document_Sections` ( `section_id` INTEGER PRIMARY KEY, `document_code` VARCHAR(15) NOT NULL, `section_sequence` INTEGER, `section_code` VARCHAR(20), `section_title` VARCHAR(80), FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ) ); CREATE TABLE `Document_Sections_Images` ( `section_id` INTEGER NOT NULL, `image_id` INTEGER NOT NULL, PRIMARY KEY (`section_id`,`image_id`), FOREIGN KEY (`section_id` ) REFERENCES `Document_Sections`(`section_id` ), FOREIGN KEY (`image_id` ) REFERENCES `Images`(`image_id` ) ); INSERT INTO Roles (`role_code`, `role_description`) VALUES ('DBA', 'Database Administrator')INSERT INTO Users (`user_id`, `role_code`, `user_name`, `user_login`, `password`) VALUES (1, 'PROJ-MGR', 'dickens.elta', '0', 'e72b5a2d50b39a8760764a5f7a9d68ca2f076877')INSERT INTO Document_Structures (`document_structure_code`, `parent_document_structure_code`, `document_structure_description`) VALUES ('1', '1', 'Header')INSERT INTO Functional_Areas (`functional_area_code`, `parent_functional_area_code`, `functional_area_description`) VALUES ('8', '8', 'Signature')INSERT INTO Images (`image_id`, `image_alt_text`, `image_name`, `image_url`) VALUES (1, 'Lea', 'top1', 'http://www.rempelnader.com/1.jpg')INSERT INTO Documents (`document_code`, `document_structure_code`, `document_type_code`, `access_count`, `document_name`) VALUES ('217', '8', 'Book', 1864, 'Learning English')INSERT INTO Document_Functional_Areas (`document_code`, `functional_area_code`) VALUES ('675', '9')INSERT INTO Document_Sections (`section_id`, `document_code`, `section_sequence`, `section_code`, `section_title`) VALUES (40, '465', 4964, '93', 'after')INSERT INTO Document_Sections_Images (`section_id`, `image_id`) VALUES (93, 6)
document_management
SELECT t2.section_title FROM documents AS t1 JOIN document_sections AS t2 ON t1.document_code = t2.document_code WHERE t1.document_name = "David CV"
What are all the section titles of the document named "David CV"?
PRAGMA foreign_keys = ON; CREATE TABLE `Roles` ( `role_code` VARCHAR(15) PRIMARY KEY, `role_description` VARCHAR(80) ); CREATE TABLE `Users` ( `user_id` INTEGER PRIMARY KEY, `role_code` VARCHAR(15) NOT NULL, `user_name` VARCHAR(40), `user_login` VARCHAR(40), `password` VARCHAR(40), FOREIGN KEY (`role_code` ) REFERENCES `Roles`(`role_code` ) ); CREATE TABLE `Document_Structures` ( `document_structure_code` VARCHAR(15) PRIMARY KEY, `parent_document_structure_code` VARCHAR(15), `document_structure_description` VARCHAR(80) ); CREATE TABLE `Functional_Areas` ( `functional_area_code` VARCHAR(15) PRIMARY KEY, `parent_functional_area_code` VARCHAR(15), `functional_area_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Images` ( `image_id` INTEGER PRIMARY KEY, `image_alt_text` VARCHAR(80), `image_name` VARCHAR(40), `image_url` VARCHAR(255) ); CREATE TABLE `Documents` ( `document_code` VARCHAR(15) PRIMARY KEY, `document_structure_code` VARCHAR(15) NOT NULL, `document_type_code` VARCHAR(15) NOT NULL, `access_count` INTEGER, `document_name` VARCHAR(80), FOREIGN KEY (`document_structure_code` ) REFERENCES `Document_Structures`(`document_structure_code` ) ); CREATE TABLE `Document_Functional_Areas` ( `document_code` VARCHAR(15) NOT NULL, `functional_area_code` VARCHAR(15) NOT NULL, FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ), FOREIGN KEY (`functional_area_code` ) REFERENCES `Functional_Areas`(`functional_area_code` ) ); CREATE TABLE `Document_Sections` ( `section_id` INTEGER PRIMARY KEY, `document_code` VARCHAR(15) NOT NULL, `section_sequence` INTEGER, `section_code` VARCHAR(20), `section_title` VARCHAR(80), FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ) ); CREATE TABLE `Document_Sections_Images` ( `section_id` INTEGER NOT NULL, `image_id` INTEGER NOT NULL, PRIMARY KEY (`section_id`,`image_id`), FOREIGN KEY (`section_id` ) REFERENCES `Document_Sections`(`section_id` ), FOREIGN KEY (`image_id` ) REFERENCES `Images`(`image_id` ) ); INSERT INTO Roles (`role_code`, `role_description`) VALUES ('DBA', 'Database Administrator')INSERT INTO Users (`user_id`, `role_code`, `user_name`, `user_login`, `password`) VALUES (1, 'PROJ-MGR', 'dickens.elta', '0', 'e72b5a2d50b39a8760764a5f7a9d68ca2f076877')INSERT INTO Document_Structures (`document_structure_code`, `parent_document_structure_code`, `document_structure_description`) VALUES ('1', '1', 'Header')INSERT INTO Functional_Areas (`functional_area_code`, `parent_functional_area_code`, `functional_area_description`) VALUES ('8', '8', 'Signature')INSERT INTO Images (`image_id`, `image_alt_text`, `image_name`, `image_url`) VALUES (1, 'Lea', 'top1', 'http://www.rempelnader.com/1.jpg')INSERT INTO Documents (`document_code`, `document_structure_code`, `document_type_code`, `access_count`, `document_name`) VALUES ('217', '8', 'Book', 1864, 'Learning English')INSERT INTO Document_Functional_Areas (`document_code`, `functional_area_code`) VALUES ('675', '9')INSERT INTO Document_Sections (`section_id`, `document_code`, `section_sequence`, `section_code`, `section_title`) VALUES (40, '465', 4964, '93', 'after')INSERT INTO Document_Sections_Images (`section_id`, `image_id`) VALUES (93, 6)
document_management
SELECT t2.section_title FROM documents AS t1 JOIN document_sections AS t2 ON t1.document_code = t2.document_code WHERE t1.document_name = "David CV"
Give the section titles of the document with the name "David CV".
PRAGMA foreign_keys = ON; CREATE TABLE `Roles` ( `role_code` VARCHAR(15) PRIMARY KEY, `role_description` VARCHAR(80) ); CREATE TABLE `Users` ( `user_id` INTEGER PRIMARY KEY, `role_code` VARCHAR(15) NOT NULL, `user_name` VARCHAR(40), `user_login` VARCHAR(40), `password` VARCHAR(40), FOREIGN KEY (`role_code` ) REFERENCES `Roles`(`role_code` ) ); CREATE TABLE `Document_Structures` ( `document_structure_code` VARCHAR(15) PRIMARY KEY, `parent_document_structure_code` VARCHAR(15), `document_structure_description` VARCHAR(80) ); CREATE TABLE `Functional_Areas` ( `functional_area_code` VARCHAR(15) PRIMARY KEY, `parent_functional_area_code` VARCHAR(15), `functional_area_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Images` ( `image_id` INTEGER PRIMARY KEY, `image_alt_text` VARCHAR(80), `image_name` VARCHAR(40), `image_url` VARCHAR(255) ); CREATE TABLE `Documents` ( `document_code` VARCHAR(15) PRIMARY KEY, `document_structure_code` VARCHAR(15) NOT NULL, `document_type_code` VARCHAR(15) NOT NULL, `access_count` INTEGER, `document_name` VARCHAR(80), FOREIGN KEY (`document_structure_code` ) REFERENCES `Document_Structures`(`document_structure_code` ) ); CREATE TABLE `Document_Functional_Areas` ( `document_code` VARCHAR(15) NOT NULL, `functional_area_code` VARCHAR(15) NOT NULL, FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ), FOREIGN KEY (`functional_area_code` ) REFERENCES `Functional_Areas`(`functional_area_code` ) ); CREATE TABLE `Document_Sections` ( `section_id` INTEGER PRIMARY KEY, `document_code` VARCHAR(15) NOT NULL, `section_sequence` INTEGER, `section_code` VARCHAR(20), `section_title` VARCHAR(80), FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ) ); CREATE TABLE `Document_Sections_Images` ( `section_id` INTEGER NOT NULL, `image_id` INTEGER NOT NULL, PRIMARY KEY (`section_id`,`image_id`), FOREIGN KEY (`section_id` ) REFERENCES `Document_Sections`(`section_id` ), FOREIGN KEY (`image_id` ) REFERENCES `Images`(`image_id` ) ); INSERT INTO Roles (`role_code`, `role_description`) VALUES ('DBA', 'Database Administrator')INSERT INTO Users (`user_id`, `role_code`, `user_name`, `user_login`, `password`) VALUES (1, 'PROJ-MGR', 'dickens.elta', '0', 'e72b5a2d50b39a8760764a5f7a9d68ca2f076877')INSERT INTO Document_Structures (`document_structure_code`, `parent_document_structure_code`, `document_structure_description`) VALUES ('1', '1', 'Header')INSERT INTO Functional_Areas (`functional_area_code`, `parent_functional_area_code`, `functional_area_description`) VALUES ('8', '8', 'Signature')INSERT INTO Images (`image_id`, `image_alt_text`, `image_name`, `image_url`) VALUES (1, 'Lea', 'top1', 'http://www.rempelnader.com/1.jpg')INSERT INTO Documents (`document_code`, `document_structure_code`, `document_type_code`, `access_count`, `document_name`) VALUES ('217', '8', 'Book', 1864, 'Learning English')INSERT INTO Document_Functional_Areas (`document_code`, `functional_area_code`) VALUES ('675', '9')INSERT INTO Document_Sections (`section_id`, `document_code`, `section_sequence`, `section_code`, `section_title`) VALUES (40, '465', 4964, '93', 'after')INSERT INTO Document_Sections_Images (`section_id`, `image_id`) VALUES (93, 6)
document_management
SELECT document_name FROM documents WHERE document_code NOT IN (SELECT document_code FROM document_sections)
Find all the name of documents without any sections.
PRAGMA foreign_keys = ON; CREATE TABLE `Roles` ( `role_code` VARCHAR(15) PRIMARY KEY, `role_description` VARCHAR(80) ); CREATE TABLE `Users` ( `user_id` INTEGER PRIMARY KEY, `role_code` VARCHAR(15) NOT NULL, `user_name` VARCHAR(40), `user_login` VARCHAR(40), `password` VARCHAR(40), FOREIGN KEY (`role_code` ) REFERENCES `Roles`(`role_code` ) ); CREATE TABLE `Document_Structures` ( `document_structure_code` VARCHAR(15) PRIMARY KEY, `parent_document_structure_code` VARCHAR(15), `document_structure_description` VARCHAR(80) ); CREATE TABLE `Functional_Areas` ( `functional_area_code` VARCHAR(15) PRIMARY KEY, `parent_functional_area_code` VARCHAR(15), `functional_area_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Images` ( `image_id` INTEGER PRIMARY KEY, `image_alt_text` VARCHAR(80), `image_name` VARCHAR(40), `image_url` VARCHAR(255) ); CREATE TABLE `Documents` ( `document_code` VARCHAR(15) PRIMARY KEY, `document_structure_code` VARCHAR(15) NOT NULL, `document_type_code` VARCHAR(15) NOT NULL, `access_count` INTEGER, `document_name` VARCHAR(80), FOREIGN KEY (`document_structure_code` ) REFERENCES `Document_Structures`(`document_structure_code` ) ); CREATE TABLE `Document_Functional_Areas` ( `document_code` VARCHAR(15) NOT NULL, `functional_area_code` VARCHAR(15) NOT NULL, FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ), FOREIGN KEY (`functional_area_code` ) REFERENCES `Functional_Areas`(`functional_area_code` ) ); CREATE TABLE `Document_Sections` ( `section_id` INTEGER PRIMARY KEY, `document_code` VARCHAR(15) NOT NULL, `section_sequence` INTEGER, `section_code` VARCHAR(20), `section_title` VARCHAR(80), FOREIGN KEY (`document_code` ) REFERENCES `Documents`(`document_code` ) ); CREATE TABLE `Document_Sections_Images` ( `section_id` INTEGER NOT NULL, `image_id` INTEGER NOT NULL, PRIMARY KEY (`section_id`,`image_id`), FOREIGN KEY (`section_id` ) REFERENCES `Document_Sections`(`section_id` ), FOREIGN KEY (`image_id` ) REFERENCES `Images`(`image_id` ) ); INSERT INTO Roles (`role_code`, `role_description`) VALUES ('DBA', 'Database Administrator')INSERT INTO Users (`user_id`, `role_code`, `user_name`, `user_login`, `password`) VALUES (1, 'PROJ-MGR', 'dickens.elta', '0', 'e72b5a2d50b39a8760764a5f7a9d68ca2f076877')INSERT INTO Document_Structures (`document_structure_code`, `parent_document_structure_code`, `document_structure_description`) VALUES ('1', '1', 'Header')INSERT INTO Functional_Areas (`functional_area_code`, `parent_functional_area_code`, `functional_area_description`) VALUES ('8', '8', 'Signature')INSERT INTO Images (`image_id`, `image_alt_text`, `image_name`, `image_url`) VALUES (1, 'Lea', 'top1', 'http://www.rempelnader.com/1.jpg')INSERT INTO Documents (`document_code`, `document_structure_code`, `document_type_code`, `access_count`, `document_name`) VALUES ('217', '8', 'Book', 1864, 'Learning English')INSERT INTO Document_Functional_Areas (`document_code`, `functional_area_code`) VALUES ('675', '9')INSERT INTO Document_Sections (`section_id`, `document_code`, `section_sequence`, `section_code`, `section_title`) VALUES (40, '465', 4964, '93', 'after')INSERT INTO Document_Sections_Images (`section_id`, `image_id`) VALUES (93, 6)