schema
stringlengths 144
5.45k
| question
stringlengths 16
224
| query
stringlengths 18
577
| hardness
stringclasses 5
values |
---|---|---|---|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
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
|
medium
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
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
|
medium
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
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
|
medium
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
Find the types of documents with more than 4 documents.
|
SELECT document_type_code FROM documents GROUP BY document_type_code HAVING count(*) > 4
|
easy
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
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
|
easy
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
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
|
hard
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
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
|
hard
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
What is the average access count of documents?
|
SELECT avg(access_count) FROM documents
|
easy
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
Find the average access count across all documents?
|
SELECT avg(access_count) FROM documents
|
easy
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
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
|
extra
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
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
|
extra
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
What is the type of the document named "David CV"?
|
SELECT document_type_code FROM documents WHERE document_name = "David CV"
|
easy
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
Return the type code of the document named "David CV".
|
SELECT document_type_code FROM documents WHERE document_name = "David CV"
|
easy
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
Find the list of documents that are both in the most three popular type and have the most three popular structure.
|
SELECT document_name FROM documents GROUP BY document_type_code ORDER BY count(*) DESC LIMIT 3 INTERSECT SELECT document_name FROM documents GROUP BY document_structure_code ORDER BY count(*) DESC LIMIT 3
|
extra
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
What are the names of documents that have both one of the three most common types and one of three most common structures?
|
SELECT document_name FROM documents GROUP BY document_type_code ORDER BY count(*) DESC LIMIT 3 INTERSECT SELECT document_name FROM documents GROUP BY document_structure_code ORDER BY count(*) DESC LIMIT 3
|
extra
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
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
|
easy
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
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
|
easy
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
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"
|
medium
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
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"
|
medium
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
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)
|
hard
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
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)
|
hard
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
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
|
hard
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
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
|
hard
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
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"
|
hard
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
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"
|
hard
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
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
|
hard
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
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
|
hard
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
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
|
extra
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
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
|
extra
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
List all the document names which contains "CV".
|
SELECT document_name FROM documents WHERE document_name LIKE "%CV%"
|
medium
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
What are the names of documents that contain the substring "CV"?
|
SELECT document_name FROM documents WHERE document_name LIKE "%CV%"
|
medium
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
How many users are logged in?
|
SELECT count(*) FROM users WHERE user_login = 1
|
easy
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
Count the number of users that are logged in.
|
SELECT count(*) FROM users WHERE user_login = 1
|
easy
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
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)
|
hard
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
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)
|
hard
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
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
|
hard
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
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
|
hard
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
List all the image name and URLs in the order of their names.
|
SELECT image_name , image_url FROM images ORDER BY image_name
|
medium
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
What are the names and urls of images, sorted alphabetically?
|
SELECT image_name , image_url FROM images ORDER BY image_name
|
medium
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
Find the number of users in each role.
|
SELECT count(*) , role_code FROM users GROUP BY role_code
|
medium
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
What are the different role codes for users, and how many users have each?
|
SELECT count(*) , role_code FROM users GROUP BY role_code
|
medium
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
What document types have more than 2 corresponding documents?
|
SELECT document_type_code FROM documents GROUP BY document_type_code HAVING count(*) > 2
|
easy
|
CREATE TABLE Roles (role_code text, role_description text); CREATE TABLE Users (user_id number, role_code text, user_name text, user_login text, password text); CREATE TABLE Document_Structures (document_structure_code text, parent_document_structure_code text, document_structure_description text); CREATE TABLE Functional_Areas (functional_area_code text, parent_functional_area_code text, functional_area_description text); CREATE TABLE Images (image_id number, image_alt_text text, image_name text, image_url text); CREATE TABLE Documents (document_code text, document_structure_code text, document_type_code text, access_count number, document_name text); CREATE TABLE Document_Functional_Areas (document_code text, functional_area_code text); CREATE TABLE Document_Sections (section_id number, document_code text, section_sequence number, section_code text, section_title text); CREATE TABLE Document_Sections_Images (section_id number, image_id number);
|
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
|
easy
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
How many companies are there?
|
SELECT count(*) FROM Companies
|
easy
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
Count the number of companies.
|
SELECT count(*) FROM Companies
|
easy
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
List the names of companies in descending order of market value.
|
SELECT name FROM Companies ORDER BY Market_Value_billion DESC
|
easy
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
Sort the company names in descending order of the company's market value.
|
SELECT name FROM Companies ORDER BY Market_Value_billion DESC
|
easy
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
What are the names of companies whose headquarters are not "USA"?
|
SELECT name FROM Companies WHERE Headquarters != 'USA'
|
easy
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
Find the names of the companies whose headquarters are not located in "USA".
|
SELECT name FROM Companies WHERE Headquarters != 'USA'
|
easy
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
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
|
medium
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
List the name and assets of each company in ascending order of company name.
|
SELECT name , Assets_billion FROM Companies ORDER BY name ASC
|
medium
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
What are the average profits of companies?
|
SELECT avg(Profits_billion) FROM Companies
|
easy
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
Compute the average profits companies make.
|
SELECT avg(Profits_billion) FROM Companies
|
easy
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
What are the maximum and minimum sales of the companies whose industries are not "Banking".
|
SELECT max(Sales_billion) , min(Sales_billion) FROM Companies WHERE Industry != "Banking"
|
medium
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
Find the maximum and minimum sales of the companies that are not in the "Banking" industry.
|
SELECT max(Sales_billion) , min(Sales_billion) FROM Companies WHERE Industry != "Banking"
|
medium
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
How many different industries are the companies in?
|
SELECT count(DISTINCT Industry) FROM Companies
|
easy
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
Count the number of distinct company industries.
|
SELECT count(DISTINCT Industry) FROM Companies
|
easy
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
List the names of buildings in descending order of building height.
|
SELECT name FROM buildings ORDER BY Height DESC
|
easy
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
What are the names of buildings sorted in descending order of building height?
|
SELECT name FROM buildings ORDER BY Height DESC
|
easy
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
Find the stories of the building with the largest height.
|
SELECT Stories FROM buildings ORDER BY Height DESC LIMIT 1
|
medium
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
What is the stories of highest building?
|
SELECT Stories FROM buildings ORDER BY Height DESC LIMIT 1
|
medium
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
List the name of a building along with the name of a company whose office is in the building.
|
SELECT T3.name , T2.name FROM Office_locations AS T1 JOIN buildings AS T2 ON T1.building_id = T2.id JOIN Companies AS T3 ON T1.company_id = T3.id
|
medium
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
For each company, return the company name and the name of the building its office is located in.
|
SELECT T3.name , T2.name FROM Office_locations AS T1 JOIN buildings AS T2 ON T1.building_id = T2.id JOIN Companies AS T3 ON T1.company_id = T3.id
|
medium
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
Show the names of the buildings that have more than one company offices.
|
SELECT T2.name FROM Office_locations AS T1 JOIN buildings AS T2 ON T1.building_id = T2.id JOIN Companies AS T3 ON T1.company_id = T3.id GROUP BY T1.building_id HAVING COUNT(*) > 1
|
hard
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
Which buildings have more than one company offices? Give me the building names.
|
SELECT T2.name FROM Office_locations AS T1 JOIN buildings AS T2 ON T1.building_id = T2.id JOIN Companies AS T3 ON T1.company_id = T3.id GROUP BY T1.building_id HAVING COUNT(*) > 1
|
hard
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
Show the name of the building that has the most company offices.
|
SELECT T2.name FROM Office_locations AS T1 JOIN buildings AS T2 ON T1.building_id = T2.id JOIN Companies AS T3 ON T1.company_id = T3.id GROUP BY T1.building_id ORDER BY COUNT(*) DESC LIMIT 1
|
extra
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
Which building has the largest number of company offices? Give me the building name.
|
SELECT T2.name FROM Office_locations AS T1 JOIN buildings AS T2 ON T1.building_id = T2.id JOIN Companies AS T3 ON T1.company_id = T3.id GROUP BY T1.building_id ORDER BY COUNT(*) DESC LIMIT 1
|
extra
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
Please show the names of the buildings whose status is "on-hold", in ascending order of stories.
|
SELECT name FROM buildings WHERE Status = "on-hold" ORDER BY Stories ASC
|
medium
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
Find the names of the buildings in "on-hold" status, and sort them in ascending order of building stories.
|
SELECT name FROM buildings WHERE Status = "on-hold" ORDER BY Stories ASC
|
medium
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
Please show each industry and the corresponding number of companies in that industry.
|
SELECT Industry , COUNT(*) FROM Companies GROUP BY Industry
|
medium
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
Whah are the name of each industry and the number of companies in that industry?
|
SELECT Industry , COUNT(*) FROM Companies GROUP BY Industry
|
medium
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
Please show the industries of companies in descending order of the number of companies.
|
SELECT Industry FROM Companies GROUP BY Industry ORDER BY COUNT(*) DESC
|
medium
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
Sort all the industries in descending order of the count of companies in each industry
|
SELECT Industry FROM Companies GROUP BY Industry ORDER BY COUNT(*) DESC
|
medium
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
List the industry shared by the most companies.
|
SELECT Industry FROM Companies GROUP BY Industry ORDER BY COUNT(*) DESC LIMIT 1
|
hard
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
Which industry has the most companies?
|
SELECT Industry FROM Companies GROUP BY Industry ORDER BY COUNT(*) DESC LIMIT 1
|
hard
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
List the names of buildings that have no company office.
|
SELECT name FROM buildings WHERE id NOT IN (SELECT building_id FROM Office_locations)
|
hard
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
Which buildings do not have any company office? Give me the building names.
|
SELECT name FROM buildings WHERE id NOT IN (SELECT building_id FROM Office_locations)
|
hard
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
Show the industries shared by companies whose headquarters are "USA" and companies whose headquarters are "China".
|
SELECT Industry FROM Companies WHERE Headquarters = "USA" INTERSECT SELECT Industry FROM Companies WHERE Headquarters = "China"
|
hard
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
Which industries have both companies with headquarter in "USA" and companies with headquarter in "China"?
|
SELECT Industry FROM Companies WHERE Headquarters = "USA" INTERSECT SELECT Industry FROM Companies WHERE Headquarters = "China"
|
hard
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
Find the number of companies whose industry is "Banking" or "Conglomerate",
|
SELECT count(*) FROM Companies WHERE Industry = "Banking" OR Industry = "Conglomerate"
|
medium
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
How many companies are in either "Banking" industry or "Conglomerate" industry?
|
SELECT count(*) FROM Companies WHERE Industry = "Banking" OR Industry = "Conglomerate"
|
medium
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
Show the headquarters shared by more than two companies.
|
SELECT Headquarters FROM Companies GROUP BY Headquarters HAVING COUNT(*) > 2
|
easy
|
CREATE TABLE buildings (id number, name text, City text, Height number, Stories number, Status text); CREATE TABLE Companies (id number, name text, Headquarters text, Industry text, Sales_billion number, Profits_billion number, Assets_billion number, Market_Value_billion text); CREATE TABLE Office_locations (building_id number, company_id number, move_in_year number);
|
Which headquarter locations are used by more than 2 companies?
|
SELECT Headquarters FROM Companies GROUP BY Headquarters HAVING COUNT(*) > 2
|
easy
|
CREATE TABLE Addresses (Address_ID number, address_details text); CREATE TABLE Locations (Location_ID number, Other_Details text); CREATE TABLE Products (Product_ID number, Product_Type_Code text, Product_Name text, Product_Price number); CREATE TABLE Parties (Party_ID number, Party_Details text); CREATE TABLE Assets (Asset_ID number, Other_Details text); CREATE TABLE Channels (Channel_ID number, Other_Details text); CREATE TABLE Finances (Finance_ID number, Other_Details text); CREATE TABLE Events (Event_ID number, Address_ID number, Channel_ID number, Event_Type_Code text, Finance_ID number, Location_ID number); CREATE TABLE Products_in_Events (Product_in_Event_ID number, Event_ID number, Product_ID number); CREATE TABLE Parties_in_Events (Party_ID number, Event_ID number, Role_Code text); CREATE TABLE Agreements (Document_ID number, Event_ID number); CREATE TABLE Assets_in_Events (Asset_ID number, Event_ID number);
|
How many products are there?
|
SELECT count(*) FROM Products
|
easy
|
CREATE TABLE Addresses (Address_ID number, address_details text); CREATE TABLE Locations (Location_ID number, Other_Details text); CREATE TABLE Products (Product_ID number, Product_Type_Code text, Product_Name text, Product_Price number); CREATE TABLE Parties (Party_ID number, Party_Details text); CREATE TABLE Assets (Asset_ID number, Other_Details text); CREATE TABLE Channels (Channel_ID number, Other_Details text); CREATE TABLE Finances (Finance_ID number, Other_Details text); CREATE TABLE Events (Event_ID number, Address_ID number, Channel_ID number, Event_Type_Code text, Finance_ID number, Location_ID number); CREATE TABLE Products_in_Events (Product_in_Event_ID number, Event_ID number, Product_ID number); CREATE TABLE Parties_in_Events (Party_ID number, Event_ID number, Role_Code text); CREATE TABLE Agreements (Document_ID number, Event_ID number); CREATE TABLE Assets_in_Events (Asset_ID number, Event_ID number);
|
List the name of products in ascending order of price.
|
SELECT Product_Name FROM Products ORDER BY Product_Price ASC
|
easy
|
CREATE TABLE Addresses (Address_ID number, address_details text); CREATE TABLE Locations (Location_ID number, Other_Details text); CREATE TABLE Products (Product_ID number, Product_Type_Code text, Product_Name text, Product_Price number); CREATE TABLE Parties (Party_ID number, Party_Details text); CREATE TABLE Assets (Asset_ID number, Other_Details text); CREATE TABLE Channels (Channel_ID number, Other_Details text); CREATE TABLE Finances (Finance_ID number, Other_Details text); CREATE TABLE Events (Event_ID number, Address_ID number, Channel_ID number, Event_Type_Code text, Finance_ID number, Location_ID number); CREATE TABLE Products_in_Events (Product_in_Event_ID number, Event_ID number, Product_ID number); CREATE TABLE Parties_in_Events (Party_ID number, Event_ID number, Role_Code text); CREATE TABLE Agreements (Document_ID number, Event_ID number); CREATE TABLE Assets_in_Events (Asset_ID number, Event_ID number);
|
What are the names and type codes of products?
|
SELECT Product_Name , Product_Type_Code FROM Products
|
medium
|
CREATE TABLE Addresses (Address_ID number, address_details text); CREATE TABLE Locations (Location_ID number, Other_Details text); CREATE TABLE Products (Product_ID number, Product_Type_Code text, Product_Name text, Product_Price number); CREATE TABLE Parties (Party_ID number, Party_Details text); CREATE TABLE Assets (Asset_ID number, Other_Details text); CREATE TABLE Channels (Channel_ID number, Other_Details text); CREATE TABLE Finances (Finance_ID number, Other_Details text); CREATE TABLE Events (Event_ID number, Address_ID number, Channel_ID number, Event_Type_Code text, Finance_ID number, Location_ID number); CREATE TABLE Products_in_Events (Product_in_Event_ID number, Event_ID number, Product_ID number); CREATE TABLE Parties_in_Events (Party_ID number, Event_ID number, Role_Code text); CREATE TABLE Agreements (Document_ID number, Event_ID number); CREATE TABLE Assets_in_Events (Asset_ID number, Event_ID number);
|
Show the prices of the products named "Dining" or "Trading Policy".
|
SELECT Product_Price FROM Products WHERE Product_Name = "Dining" OR Product_Name = "Trading Policy"
|
medium
|
CREATE TABLE Addresses (Address_ID number, address_details text); CREATE TABLE Locations (Location_ID number, Other_Details text); CREATE TABLE Products (Product_ID number, Product_Type_Code text, Product_Name text, Product_Price number); CREATE TABLE Parties (Party_ID number, Party_Details text); CREATE TABLE Assets (Asset_ID number, Other_Details text); CREATE TABLE Channels (Channel_ID number, Other_Details text); CREATE TABLE Finances (Finance_ID number, Other_Details text); CREATE TABLE Events (Event_ID number, Address_ID number, Channel_ID number, Event_Type_Code text, Finance_ID number, Location_ID number); CREATE TABLE Products_in_Events (Product_in_Event_ID number, Event_ID number, Product_ID number); CREATE TABLE Parties_in_Events (Party_ID number, Event_ID number, Role_Code text); CREATE TABLE Agreements (Document_ID number, Event_ID number); CREATE TABLE Assets_in_Events (Asset_ID number, Event_ID number);
|
What is the average price for products?
|
SELECT avg(Product_Price) FROM Products
|
easy
|
CREATE TABLE Addresses (Address_ID number, address_details text); CREATE TABLE Locations (Location_ID number, Other_Details text); CREATE TABLE Products (Product_ID number, Product_Type_Code text, Product_Name text, Product_Price number); CREATE TABLE Parties (Party_ID number, Party_Details text); CREATE TABLE Assets (Asset_ID number, Other_Details text); CREATE TABLE Channels (Channel_ID number, Other_Details text); CREATE TABLE Finances (Finance_ID number, Other_Details text); CREATE TABLE Events (Event_ID number, Address_ID number, Channel_ID number, Event_Type_Code text, Finance_ID number, Location_ID number); CREATE TABLE Products_in_Events (Product_in_Event_ID number, Event_ID number, Product_ID number); CREATE TABLE Parties_in_Events (Party_ID number, Event_ID number, Role_Code text); CREATE TABLE Agreements (Document_ID number, Event_ID number); CREATE TABLE Assets_in_Events (Asset_ID number, Event_ID number);
|
What is the name of the product with the highest price?
|
SELECT Product_Name FROM Products ORDER BY Product_Price DESC LIMIT 1
|
medium
|
CREATE TABLE Addresses (Address_ID number, address_details text); CREATE TABLE Locations (Location_ID number, Other_Details text); CREATE TABLE Products (Product_ID number, Product_Type_Code text, Product_Name text, Product_Price number); CREATE TABLE Parties (Party_ID number, Party_Details text); CREATE TABLE Assets (Asset_ID number, Other_Details text); CREATE TABLE Channels (Channel_ID number, Other_Details text); CREATE TABLE Finances (Finance_ID number, Other_Details text); CREATE TABLE Events (Event_ID number, Address_ID number, Channel_ID number, Event_Type_Code text, Finance_ID number, Location_ID number); CREATE TABLE Products_in_Events (Product_in_Event_ID number, Event_ID number, Product_ID number); CREATE TABLE Parties_in_Events (Party_ID number, Event_ID number, Role_Code text); CREATE TABLE Agreements (Document_ID number, Event_ID number); CREATE TABLE Assets_in_Events (Asset_ID number, Event_ID number);
|
Show different type codes of products and the number of products with each type code.
|
SELECT Product_Type_Code , COUNT(*) FROM Products GROUP BY Product_Type_Code
|
medium
|
CREATE TABLE Addresses (Address_ID number, address_details text); CREATE TABLE Locations (Location_ID number, Other_Details text); CREATE TABLE Products (Product_ID number, Product_Type_Code text, Product_Name text, Product_Price number); CREATE TABLE Parties (Party_ID number, Party_Details text); CREATE TABLE Assets (Asset_ID number, Other_Details text); CREATE TABLE Channels (Channel_ID number, Other_Details text); CREATE TABLE Finances (Finance_ID number, Other_Details text); CREATE TABLE Events (Event_ID number, Address_ID number, Channel_ID number, Event_Type_Code text, Finance_ID number, Location_ID number); CREATE TABLE Products_in_Events (Product_in_Event_ID number, Event_ID number, Product_ID number); CREATE TABLE Parties_in_Events (Party_ID number, Event_ID number, Role_Code text); CREATE TABLE Agreements (Document_ID number, Event_ID number); CREATE TABLE Assets_in_Events (Asset_ID number, Event_ID number);
|
Show the most common type code across products.
|
SELECT Product_Type_Code FROM Products GROUP BY Product_Type_Code ORDER BY COUNT(*) DESC LIMIT 1
|
hard
|
CREATE TABLE Addresses (Address_ID number, address_details text); CREATE TABLE Locations (Location_ID number, Other_Details text); CREATE TABLE Products (Product_ID number, Product_Type_Code text, Product_Name text, Product_Price number); CREATE TABLE Parties (Party_ID number, Party_Details text); CREATE TABLE Assets (Asset_ID number, Other_Details text); CREATE TABLE Channels (Channel_ID number, Other_Details text); CREATE TABLE Finances (Finance_ID number, Other_Details text); CREATE TABLE Events (Event_ID number, Address_ID number, Channel_ID number, Event_Type_Code text, Finance_ID number, Location_ID number); CREATE TABLE Products_in_Events (Product_in_Event_ID number, Event_ID number, Product_ID number); CREATE TABLE Parties_in_Events (Party_ID number, Event_ID number, Role_Code text); CREATE TABLE Agreements (Document_ID number, Event_ID number); CREATE TABLE Assets_in_Events (Asset_ID number, Event_ID number);
|
Show the product type codes that have at least two products.
|
SELECT Product_Type_Code FROM Products GROUP BY Product_Type_Code HAVING COUNT(*) >= 2
|
easy
|
CREATE TABLE Addresses (Address_ID number, address_details text); CREATE TABLE Locations (Location_ID number, Other_Details text); CREATE TABLE Products (Product_ID number, Product_Type_Code text, Product_Name text, Product_Price number); CREATE TABLE Parties (Party_ID number, Party_Details text); CREATE TABLE Assets (Asset_ID number, Other_Details text); CREATE TABLE Channels (Channel_ID number, Other_Details text); CREATE TABLE Finances (Finance_ID number, Other_Details text); CREATE TABLE Events (Event_ID number, Address_ID number, Channel_ID number, Event_Type_Code text, Finance_ID number, Location_ID number); CREATE TABLE Products_in_Events (Product_in_Event_ID number, Event_ID number, Product_ID number); CREATE TABLE Parties_in_Events (Party_ID number, Event_ID number, Role_Code text); CREATE TABLE Agreements (Document_ID number, Event_ID number); CREATE TABLE Assets_in_Events (Asset_ID number, Event_ID number);
|
Show the product type codes that have both products with price higher than 4500 and products with price lower than 3000.
|
SELECT Product_Type_Code FROM Products WHERE Product_Price > 4500 INTERSECT SELECT Product_Type_Code FROM Products WHERE Product_Price < 3000
|
hard
|
CREATE TABLE Addresses (Address_ID number, address_details text); CREATE TABLE Locations (Location_ID number, Other_Details text); CREATE TABLE Products (Product_ID number, Product_Type_Code text, Product_Name text, Product_Price number); CREATE TABLE Parties (Party_ID number, Party_Details text); CREATE TABLE Assets (Asset_ID number, Other_Details text); CREATE TABLE Channels (Channel_ID number, Other_Details text); CREATE TABLE Finances (Finance_ID number, Other_Details text); CREATE TABLE Events (Event_ID number, Address_ID number, Channel_ID number, Event_Type_Code text, Finance_ID number, Location_ID number); CREATE TABLE Products_in_Events (Product_in_Event_ID number, Event_ID number, Product_ID number); CREATE TABLE Parties_in_Events (Party_ID number, Event_ID number, Role_Code text); CREATE TABLE Agreements (Document_ID number, Event_ID number); CREATE TABLE Assets_in_Events (Asset_ID number, Event_ID number);
|
Show the names of products and the number of events they are in.
|
SELECT T1.Product_Name , COUNT(*) FROM Products AS T1 JOIN Products_in_Events AS T2 ON T1.Product_ID = T2.Product_ID GROUP BY T1.Product_Name
|
medium
|
CREATE TABLE Addresses (Address_ID number, address_details text); CREATE TABLE Locations (Location_ID number, Other_Details text); CREATE TABLE Products (Product_ID number, Product_Type_Code text, Product_Name text, Product_Price number); CREATE TABLE Parties (Party_ID number, Party_Details text); CREATE TABLE Assets (Asset_ID number, Other_Details text); CREATE TABLE Channels (Channel_ID number, Other_Details text); CREATE TABLE Finances (Finance_ID number, Other_Details text); CREATE TABLE Events (Event_ID number, Address_ID number, Channel_ID number, Event_Type_Code text, Finance_ID number, Location_ID number); CREATE TABLE Products_in_Events (Product_in_Event_ID number, Event_ID number, Product_ID number); CREATE TABLE Parties_in_Events (Party_ID number, Event_ID number, Role_Code text); CREATE TABLE Agreements (Document_ID number, Event_ID number); CREATE TABLE Assets_in_Events (Asset_ID number, Event_ID number);
|
Show the names of products and the number of events they are in, sorted by the number of events in descending order.
|
SELECT T1.Product_Name , COUNT(*) FROM Products AS T1 JOIN Products_in_Events AS T2 ON T1.Product_ID = T2.Product_ID GROUP BY T1.Product_Name ORDER BY COUNT(*) DESC
|
hard
|
CREATE TABLE Addresses (Address_ID number, address_details text); CREATE TABLE Locations (Location_ID number, Other_Details text); CREATE TABLE Products (Product_ID number, Product_Type_Code text, Product_Name text, Product_Price number); CREATE TABLE Parties (Party_ID number, Party_Details text); CREATE TABLE Assets (Asset_ID number, Other_Details text); CREATE TABLE Channels (Channel_ID number, Other_Details text); CREATE TABLE Finances (Finance_ID number, Other_Details text); CREATE TABLE Events (Event_ID number, Address_ID number, Channel_ID number, Event_Type_Code text, Finance_ID number, Location_ID number); CREATE TABLE Products_in_Events (Product_in_Event_ID number, Event_ID number, Product_ID number); CREATE TABLE Parties_in_Events (Party_ID number, Event_ID number, Role_Code text); CREATE TABLE Agreements (Document_ID number, Event_ID number); CREATE TABLE Assets_in_Events (Asset_ID number, Event_ID number);
|
Show the names of products that are in at least two events.
|
SELECT T1.Product_Name FROM Products AS T1 JOIN Products_in_Events AS T2 ON T1.Product_ID = T2.Product_ID GROUP BY T1.Product_Name HAVING COUNT(*) >= 2
|
medium
|
CREATE TABLE Addresses (Address_ID number, address_details text); CREATE TABLE Locations (Location_ID number, Other_Details text); CREATE TABLE Products (Product_ID number, Product_Type_Code text, Product_Name text, Product_Price number); CREATE TABLE Parties (Party_ID number, Party_Details text); CREATE TABLE Assets (Asset_ID number, Other_Details text); CREATE TABLE Channels (Channel_ID number, Other_Details text); CREATE TABLE Finances (Finance_ID number, Other_Details text); CREATE TABLE Events (Event_ID number, Address_ID number, Channel_ID number, Event_Type_Code text, Finance_ID number, Location_ID number); CREATE TABLE Products_in_Events (Product_in_Event_ID number, Event_ID number, Product_ID number); CREATE TABLE Parties_in_Events (Party_ID number, Event_ID number, Role_Code text); CREATE TABLE Agreements (Document_ID number, Event_ID number); CREATE TABLE Assets_in_Events (Asset_ID number, Event_ID number);
|
Show the names of products that are in at least two events in ascending alphabetical order of product name.
|
SELECT T1.Product_Name FROM Products AS T1 JOIN Products_in_Events AS T2 ON T1.Product_ID = T2.Product_ID GROUP BY T1.Product_Name HAVING COUNT(*) >= 2 ORDER BY T1.Product_Name
|
hard
|
CREATE TABLE Addresses (Address_ID number, address_details text); CREATE TABLE Locations (Location_ID number, Other_Details text); CREATE TABLE Products (Product_ID number, Product_Type_Code text, Product_Name text, Product_Price number); CREATE TABLE Parties (Party_ID number, Party_Details text); CREATE TABLE Assets (Asset_ID number, Other_Details text); CREATE TABLE Channels (Channel_ID number, Other_Details text); CREATE TABLE Finances (Finance_ID number, Other_Details text); CREATE TABLE Events (Event_ID number, Address_ID number, Channel_ID number, Event_Type_Code text, Finance_ID number, Location_ID number); CREATE TABLE Products_in_Events (Product_in_Event_ID number, Event_ID number, Product_ID number); CREATE TABLE Parties_in_Events (Party_ID number, Event_ID number, Role_Code text); CREATE TABLE Agreements (Document_ID number, Event_ID number); CREATE TABLE Assets_in_Events (Asset_ID number, Event_ID number);
|
List the names of products that are not in any event.
|
SELECT Product_Name FROM Products WHERE Product_ID NOT IN (SELECT Product_ID FROM Products_in_Events)
|
hard
|
CREATE TABLE festival_detail (Festival_ID number, Festival_Name text, Chair_Name text, Location text, Year number, Num_of_Audience number); CREATE TABLE artwork (Artwork_ID number, Type text, Name text); CREATE TABLE nomination (Artwork_ID number, Festival_ID number, Result text);
|
How many artworks are there?
|
SELECT count(*) FROM artwork
|
easy
|
CREATE TABLE festival_detail (Festival_ID number, Festival_Name text, Chair_Name text, Location text, Year number, Num_of_Audience number); CREATE TABLE artwork (Artwork_ID number, Type text, Name text); CREATE TABLE nomination (Artwork_ID number, Festival_ID number, Result text);
|
List the name of artworks in ascending alphabetical order.
|
SELECT Name FROM artwork ORDER BY Name ASC
|
easy
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.