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 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 number of documents.
assistant
SELECT count(*) FROM Documents
human
What are the ids of documents with letter 's' in the name with any expense budgets.
assistant
SELECT T1.document_id FROM Documents AS T1 JOIN Documents_with_expenses AS T2 ON T1.document_id = T2.document_id WHERE T1.document_name LIKE '%s%'
human
What are the ids of documents which don't have expense budgets?
assistant
SELECT document_id FROM Documents EXCEPT SELECT document_id FROM Documents_with_expenses
human
How many documents do not have any expense?
assistant
SELECT count(*) FROM Documents WHERE document_id NOT IN ( SELECT document_id FROM Documents_with_expenses )
human
How many documents have expenses?
assistant
SELECT COUNT( * ) FROM Documents_with_expenses ;