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
What is the description for the budget type with code ORG?
assistant
SELECT budget_type_description FROM Ref_budget_codes WHERE budget_type_code = 'ORG'
human
List document type codes and the number of documents in each code.
assistant
SELECT document_type_code , count(*) FROM Documents GROUP BY document_type_code
human
List all budget type codes and descriptions.
assistant
SELECT budget_type_code , budget_type_description FROM Ref_budget_codes
human
What is the budget type code with most number of documents.
assistant
SELECT budget_type_code FROM Documents_with_expenses GROUP BY budget_type_code ORDER BY count(*) DESC LIMIT 1
human
Show the budget type code and description and the corresponding document id.
assistant
SELECT T2.budget_type_code , T2.budget_type_description , T1.document_id FROM Documents_with_expenses AS T1 JOIN Ref_budget_codes AS T2 ON T1.budget_type_code = T2.budget_type_code
human
Show budget type codes and the number of documents in each budget type.
assistant
SELECT budget_type_code , COUNT( * ) FROM Documents_with_expenses GROUP BY budget_type_code ;