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 all the budget type codes for documents with expenses.
assistant
SELECT budget_type_code FROM Documents_with_expenses;
human
For each code, show the number of documents.
assistant
SELECT budget_type_code , COUNT( * ) FROM Documents_with_expenses GROUP BY budget_type_code;
human
Sort the codes in descending order of the count.
assistant
SELECT budget_type_code FROM Documents_with_expenses GROUP BY budget_type_code ORDER BY COUNT( * ) DESC;
human
Which has the most?
assistant
SELECT budget_type_code FROM Documents_with_expenses GROUP BY budget_type_code ORDER BY COUNT( * ) DESC LIMIT 1 ;