spider_version
int64
1
2
db_id
stringclasses
204 values
schema
stringclasses
187 values
question
stringlengths
3
328
query
stringlengths
20
3.81k
1
network_2
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) )
What are the names of everybody who has exactly one friend?
SELECT name FROM PersonFriend GROUP BY name HAVING count(*) = 1
1
network_2
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) )
Who are the friends of Bob?
SELECT T2.friend FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T1.name = 'Bob'
1
network_2
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) )
Who are Bob's friends?
SELECT T2.friend FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T1.name = 'Bob'
1
network_2
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) )
Find the name of persons who are friends with Bob.
SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend = 'Bob'
1
network_2
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) )
What are the names of all of Bob's friends?
SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend = 'Bob'
1
network_2
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) )
Find the names of females who are friends with Zach
SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend = 'Zach' AND T1.gender = 'female'
1
network_2
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) )
What are the names of all females who are friends with Zach?
SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend = 'Zach' AND T1.gender = 'female'
1
network_2
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) )
Find the female friends of Alice.
SELECT T2.friend FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.friend WHERE T2.name = 'Alice' AND T1.gender = 'female'
1
network_2
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) )
What are all the friends of Alice who are female?
SELECT T2.friend FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.friend WHERE T2.name = 'Alice' AND T1.gender = 'female'
1
network_2
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) )
Find the male friend of Alice whose job is a doctor?
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'
1
network_2
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) )
Who are the friends of Alice that are doctors?
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'
1
network_2
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) )
Who has a friend that is from new york city?
SELECT T2.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.friend WHERE T1.city = 'new york city'
1
network_2
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) )
What are the names of all friends who are from New York?
SELECT T2.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.friend WHERE T1.city = 'new york city'
1
network_2
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) )
Who has friends that are younger than the average age?
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)
1
network_2
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) )
What are the different names of friends who are younger than the average age for a friend?
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)
1
network_2
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) )
Who has friends that are older than the average age? Print their friends and their ages as well
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)
1
network_2
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) )
Whare the names, friends, and ages of all people who are older than the average age of a person?
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)
1
network_2
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) )
Who is the friend of Zach with longest year relationship?
SELECT friend FROM PersonFriend WHERE name = 'Zach' AND YEAR = (SELECT max(YEAR) FROM PersonFriend WHERE name = 'Zach')
1
network_2
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) )
Which friend of Zach has the longest-lasting friendship?
SELECT friend FROM PersonFriend WHERE name = 'Zach' AND YEAR = (SELECT max(YEAR) FROM PersonFriend WHERE name = 'Zach')
1
network_2
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) )
What is the age of the friend of Zach with longest year relationship?
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')
1
network_2
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) )
What are the ages of all of Zach's friends who are in the longest relationship?
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')
1
network_2
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) )
Find the name of persons who are friends with Alice for the shortest years.
SELECT name FROM PersonFriend WHERE friend = 'Alice' AND YEAR = (SELECT min(YEAR) FROM PersonFriend WHERE friend = 'Alice')
1
network_2
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) )
What are the names of all people who are friends with Alice for the shortest amount of time?
SELECT name FROM PersonFriend WHERE friend = 'Alice' AND YEAR = (SELECT min(YEAR) FROM PersonFriend WHERE friend = 'Alice')
1
network_2
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) )
Find the name, age, and job title of persons who are friends with Alice for the longest years.
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')
1
network_2
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) )
What are the names, ages, and jobs of all people who are friends with Alice for the longest amount of time?
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')
1
network_2
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) )
Who is the person that has no friend?
SELECT name FROM person EXCEPT SELECT name FROM PersonFriend
1
network_2
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) )
What are the names of all people who do not have friends?
SELECT name FROM person EXCEPT SELECT name FROM PersonFriend
1
network_2
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) )
Which person whose friends have the oldest average age?
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
1
network_2
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) )
What is the name of the person who has the oldest average age for their friends, and what is that average age?
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
1
network_2
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) )
What is the total number of people who has no friend living in the city of Austin.
SELECT count(DISTINCT name) FROM PersonFriend WHERE friend NOT IN (SELECT name FROM person WHERE city = 'Austin')
1
network_2
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) )
What is the total number of people who have no friends living in Austin?
SELECT count(DISTINCT name) FROM PersonFriend WHERE friend NOT IN (SELECT name FROM person WHERE city = 'Austin')
1
network_2
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) )
Find Alice's friends of friends.
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'
1
network_2
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) )
What are the names of all of Alice's friends of friends?
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'
1
decoration_competition
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") )
How many members are there?
SELECT count(*) FROM member
1
decoration_competition
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") )
List the names of members in ascending alphabetical order.
SELECT Name FROM member ORDER BY Name ASC
1
decoration_competition
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") )
What are the names and countries of members?
SELECT Name , Country FROM member
1
decoration_competition
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") )
Show the names of members whose country is "United States" or "Canada".
SELECT Name FROM member WHERE Country = "United States" OR Country = "Canada"
1
decoration_competition
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") )
Show the different countries and the number of members from each.
SELECT Country , COUNT(*) FROM member GROUP BY Country
1
decoration_competition
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") )
Show the most common country across members.
SELECT Country FROM member GROUP BY Country ORDER BY COUNT(*) DESC LIMIT 1
1
decoration_competition
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") )
Which countries have more than two members?
SELECT Country FROM member GROUP BY Country HAVING COUNT(*) > 2
1
decoration_competition
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") )
Show the leader names and locations of colleges.
SELECT Leader_Name , College_Location FROM college
1
decoration_competition
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") )
Show the names of members and names of colleges they go to.
SELECT T2.Name , T1.Name FROM college AS T1 JOIN member AS T2 ON T1.College_ID = T2.College_ID
1
decoration_competition
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") )
Show the names of members and the locations of colleges they go to in ascending alphabetical order of member names.
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
1
decoration_competition
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") )
Show the distinct leader names of colleges associated with members from country "Canada".
SELECT DISTINCT T1.Leader_Name FROM college AS T1 JOIN member AS T2 ON T1.College_ID = T2.College_ID WHERE T2.Country = "Canada"
1
decoration_competition
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") )
Show the names of members and the decoration themes they have.
SELECT T1.Name , T2.Decoration_Theme FROM member AS T1 JOIN round AS T2 ON T1.Member_ID = T2.Member_ID
1
decoration_competition
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") )
Show the names of members that have a rank in round higher than 3.
SELECT T1.Name FROM member AS T1 JOIN round AS T2 ON T1.Member_ID = T2.Member_ID WHERE T2.Rank_in_Round > 3
1
decoration_competition
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") )
Show the names of members in ascending order of their rank in rounds.
SELECT T1.Name FROM member AS T1 JOIN round AS T2 ON T1.Member_ID = T2.Member_ID ORDER BY Rank_in_Round ASC
1
decoration_competition
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") )
List the names of members who did not participate in any round.
SELECT Name FROM member WHERE Member_ID NOT IN (SELECT Member_ID FROM round)
1
document_management
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` ) )
Find the name and access counts of all documents, in alphabetic order of the document name.
SELECT document_name , access_count FROM documents ORDER BY document_name
1
document_management
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` ) )
What are the names of all the documents, as well as the access counts of each, ordered alphabetically?
SELECT document_name , access_count FROM documents ORDER BY document_name
1
document_management
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` ) )
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?
SELECT document_name , access_count FROM documents ORDER BY access_count DESC LIMIT 1
1
document_management
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` ) )
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?
SELECT document_name , access_count FROM documents ORDER BY access_count DESC LIMIT 1
1
document_management
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` ) )
Find the types of documents with more than 4 documents.
SELECT document_type_code FROM documents GROUP BY document_type_code HAVING count(*) > 4
1
document_management
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` ) )
What are the codes of types of documents of which there are for or more?
SELECT document_type_code FROM documents GROUP BY document_type_code HAVING count(*) > 4
1
document_management
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` ) )
Find the total access count of all documents in the most popular document type.
SELECT sum(access_count) FROM documents GROUP BY document_type_code ORDER BY count(*) DESC LIMIT 1
1
document_management
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` ) )
What is the total access count of documents that are of the most common document type?
SELECT sum(access_count) FROM documents GROUP BY document_type_code ORDER BY count(*) DESC LIMIT 1
1
document_management
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` ) )
What is the average access count of documents?
SELECT avg(access_count) FROM documents
1
document_management
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` ) )
Find the average access count across all documents?
SELECT avg(access_count) FROM documents
1
document_management
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` ) )
What is the structure of the document with the least number of accesses?
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
1
document_management
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` ) )
Return the structure description of the document that has been accessed the fewest number of times.
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
1
document_management
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` ) )
What is the type of the document named "David CV"?
SELECT document_type_code FROM documents WHERE document_name = "David CV"
1
document_management
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` ) )
Return the type code of the document named "David CV".
SELECT document_type_code FROM documents WHERE document_name = "David CV"
1
document_management
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` ) )
What document types do have more than 10000 total access number.
SELECT document_type_code FROM documents GROUP BY document_type_code HAVING sum(access_count) > 10000
1
document_management
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` ) )
Return the codes of the document types that do not have a total access count of over 10000.
SELECT document_type_code FROM documents GROUP BY document_type_code HAVING sum(access_count) > 10000
1
document_management
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` ) )
What are all the section titles of the document named "David CV"?
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"
1
document_management
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` ) )
Give the section titles of the document with the name "David CV".
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"
1
document_management
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` ) )
Find all the name of documents without any sections.
SELECT document_name FROM documents WHERE document_code NOT IN (SELECT document_code FROM document_sections)
1
document_management
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` ) )
What are the names of documents that do not have any sections?
SELECT document_name FROM documents WHERE document_code NOT IN (SELECT document_code FROM document_sections)
1
document_management
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` ) )
List all the username and passwords of users with the most popular role.
SELECT user_name , password FROM users GROUP BY role_code ORDER BY count(*) DESC LIMIT 1
1
document_management
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` ) )
What are the usernames and passwords of users that have the most common role?
SELECT user_name , password FROM users GROUP BY role_code ORDER BY count(*) DESC LIMIT 1
1
document_management
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` ) )
Find the average access counts of documents with functional area "Acknowledgement".
SELECT avg(t1.access_count) FROM documents AS t1 JOIN document_functional_areas AS t2 ON t1.document_code = t2.document_code JOIN functional_areas AS t3 ON t2.functional_area_code = t3.functional_area_code WHERE t3.functional_area_description = "Acknowledgement"
1
document_management
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` ) )
What are the average access counts of documents that have the functional area description "Acknowledgement"?
SELECT avg(t1.access_count) FROM documents AS t1 JOIN document_functional_areas AS t2 ON t1.document_code = t2.document_code JOIN functional_areas AS t3 ON t2.functional_area_code = t3.functional_area_code WHERE t3.functional_area_description = "Acknowledgement"
1
document_management
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` ) )
Find names of the document without any images.
SELECT document_name FROM documents EXCEPT SELECT t1.document_name FROM documents AS t1 JOIN document_sections AS t2 ON t1.document_code = t2.document_code JOIN document_sections_images AS t3 ON t2.section_id = t3.section_id
1
document_management
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` ) )
What are the names of documents that do not have any images?
SELECT document_name FROM documents EXCEPT SELECT t1.document_name FROM documents AS t1 JOIN document_sections AS t2 ON t1.document_code = t2.document_code JOIN document_sections_images AS t3 ON t2.section_id = t3.section_id
1
document_management
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` ) )
What is the name of the document with the most number of sections?
SELECT t1.document_name FROM documents AS t1 JOIN document_sections AS t2 ON t1.document_code = t2.document_code GROUP BY t1.document_code ORDER BY count(*) DESC LIMIT 1
1
document_management
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` ) )
Return the name of the document that has the most sections.
SELECT t1.document_name FROM documents AS t1 JOIN document_sections AS t2 ON t1.document_code = t2.document_code GROUP BY t1.document_code ORDER BY count(*) DESC LIMIT 1
1
document_management
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` ) )
List all the document names which contains "CV".
SELECT document_name FROM documents WHERE document_name LIKE "%CV%"
1
document_management
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` ) )
What are the names of documents that contain the substring "CV"?
SELECT document_name FROM documents WHERE document_name LIKE "%CV%"
1
document_management
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` ) )
How many users are logged in?
SELECT count(*) FROM users WHERE user_login = 1
1
document_management
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` ) )
Count the number of users that are logged in.
SELECT count(*) FROM users WHERE user_login = 1
1
document_management
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` ) )
Find the description of the most popular role among the users that have logged in.
SELECT role_description FROM ROLES WHERE role_code = (SELECT role_code FROM users WHERE user_login = 1 GROUP BY role_code ORDER BY count(*) DESC LIMIT 1)
1
document_management
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` ) )
What is the description of the most popular role among users that have logged in?
SELECT role_description FROM ROLES WHERE role_code = (SELECT role_code FROM users WHERE user_login = 1 GROUP BY role_code ORDER BY count(*) DESC LIMIT 1)
1
document_management
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` ) )
Find the average access count of documents with the least popular structure.
SELECT avg(access_count) FROM documents GROUP BY document_structure_code ORDER BY count(*) ASC LIMIT 1
1
document_management
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` ) )
What is the average access count of documents that have the least common structure?
SELECT avg(access_count) FROM documents GROUP BY document_structure_code ORDER BY count(*) ASC LIMIT 1
1
document_management
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` ) )
List all the image name and URLs in the order of their names.
SELECT image_name , image_url FROM images ORDER BY image_name
1
document_management
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` ) )
What are the names and urls of images, sorted alphabetically?
SELECT image_name , image_url FROM images ORDER BY image_name
1
document_management
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` ) )
Find the number of users in each role.
SELECT count(*) , role_code FROM users GROUP BY role_code
1
document_management
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` ) )
What are the different role codes for users, and how many users have each?
SELECT count(*) , role_code FROM users GROUP BY role_code
1
document_management
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` ) )
What document types have more than 2 corresponding documents?
SELECT document_type_code FROM documents GROUP BY document_type_code HAVING count(*) > 2
1
document_management
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` ) )
Give the codes of document types that have more than 2 corresponding documents.
SELECT document_type_code FROM documents GROUP BY document_type_code HAVING count(*) > 2
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
How many companies are there?
SELECT count(*) FROM Companies
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
Count the number of companies.
SELECT count(*) FROM Companies
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
List the names of companies in descending order of market value.
SELECT name FROM Companies ORDER BY Market_Value_billion DESC
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
Sort the company names in descending order of the company's market value.
SELECT name FROM Companies ORDER BY Market_Value_billion DESC
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
What are the names of companies whose headquarters are not "USA"?
SELECT name FROM Companies WHERE Headquarters != 'USA'
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
Find the names of the companies whose headquarters are not located in "USA".
SELECT name FROM Companies WHERE Headquarters != 'USA'
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
What are the name and assets of each company, sorted in ascending order of company name?
SELECT name , Assets_billion FROM Companies ORDER BY name ASC
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
List the name and assets of each company in ascending order of company name.
SELECT name , Assets_billion FROM Companies ORDER BY name ASC
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
What are the average profits of companies?
SELECT avg(Profits_billion) FROM Companies
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
Compute the average profits companies make.
SELECT avg(Profits_billion) FROM Companies