human
Schema:
Ref_Document_Types (Document_Type_Code, Document_Type_Name, Document_Type_Description)
Ref_Budget_Codes (Budget_Type_Code, Budget_Type_Description)
Projects (Project_ID, Project_Details)
Documents (Document_ID, Document_Type_Code, Project_ID, Document_Date, Document_Name, Document_Description, Other_Details)
Statements (Statement_ID, Statement_Details)
Documents_with_Expenses (Document_ID, Budget_Type_Code, Document_Details)
Accounts (Account_ID, Statement_ID, Account_Details)
Please answer with SQL.
assistant
Sure, I understand.
human
Show the number of documents.
assistant
SELECT count(*) FROM Documents
human
Show the ids and names of all documents.
assistant
SELECT document_id , document_name FROM Documents
human
What is the id of the project with least number of documents?
assistant
SELECT project_id FROM Documents GROUP BY project_id ORDER BY count(*) ASC LIMIT 1
human
Show project ids and the number of documents in each project.
assistant
SELECT project_id , count(*) FROM Documents GROUP BY project_id
human
Show the ids for projects with at least 2 documents.
assistant
SELECT project_id FROM Documents GROUP BY project_id HAVING count(*) >= 2
human
Return the ids and details corresponding to projects for which there are more than two documents.
assistant
SELECT T1.project_id , T1.project_details FROM Projects AS T1 JOIN Documents AS T2 ON T1.project_id = T2.project_id GROUP BY T1.project_id HAVING COUNT( * ) > 2 ;