human
Schema:
Roles (role_code, role_description)
Users (user_id, role_code, user_name, user_login, password)
Document_Structures (document_structure_code, parent_document_structure_code, document_structure_description)
Functional_Areas (functional_area_code, parent_functional_area_code, functional_area_description)
Images (image_id, image_alt_text, image_name, image_url)
Documents (document_code, document_structure_code, document_type_code, access_count, document_name)
Document_Functional_Areas (document_code, functional_area_code)
Document_Sections (section_id, document_code, section_sequence, section_code, section_title)
Document_Sections_Images (section_id, image_id)
Please answer with SQL.
assistant
Sure, I understand.
human
What document types do have more than 10000 total access number.
assistant
SELECT document_type_code FROM documents GROUP BY document_type_code HAVING sum(access_count) > 10000
human
What is the average access count of documents?
assistant
SELECT avg(access_count) FROM documents
human
List all the username and passwords of users with the most popular role.
assistant
SELECT user_name , password FROM users GROUP BY role_code ORDER BY count(*) DESC LIMIT 1
human
Find the description of the most popular role among the users that have logged in.
assistant
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)
human
Find the number of users in each role.
assistant
SELECT count(*) , role_code FROM users GROUP BY role_code
human
How many users are logged in?
assistant
SELECT COUNT( * ) FROM users WHERE user_login = 1 ;