Database: cre_Doc_Control_Systems

Question: How many documents were shipped by USPS?
SQL: SELECT count(*) FROM Ref_Shipping_Agents JOIN Documents ON Documents.shipping_agent_code = Ref_Shipping_Agents.shipping_agent_code WHERE Ref_Shipping_Agents.shipping_agent_name = "USPS";

Question: Which shipping agent shipped the most documents? List the shipping agent name and the number of documents.
SQL: SELECT Ref_Shipping_Agents.shipping_agent_name , count(Documents.document_id) FROM Ref_Shipping_Agents JOIN Documents ON Documents.shipping_agent_code = Ref_Shipping_Agents.shipping_agent_code GROUP BY Ref_Shipping_Agents.shipping_agent_code ORDER BY count(Documents.document_id) DESC LIMIT 1;

Question: What is the receipt date of the document with id 3?
SQL: SELECT receipt_date FROM Documents WHERE document_id = 3;

Question: What address was the document with id 4 mailed to?
SQL: SELECT Addresses.address_details FROM Addresses JOIN Documents_Mailed ON Documents_Mailed.mailed_to_address_id = Addresses.address_id WHERE document_id = 4;

Question: What is the mail date of the document with id 7?
SQL: SELECT mailing_date FROM Documents_Mailed WHERE document_id = 7;

Question: List the document ids of documents with the status done and type Paper, which not shipped by the shipping agent named USPS.
SQL: SELECT document_id FROM Documents WHERE document_status_code  =  "done" AND document_type_code = "Paper" EXCEPT SELECT document_id FROM Documents JOIN Ref_Shipping_Agents ON Documents.shipping_agent_code = Ref_Shipping_Agents.shipping_agent_code WHERE Ref_Shipping_Agents.shipping_agent_name = "USPS";

Question: List document id of documents status is done and document type is Paper and the document is shipped by shipping agent named USPS.
SQL: SELECT document_id FROM Documents WHERE document_status_code  =  "done" AND document_type_code = "Paper" INTERSECT SELECT document_id FROM Documents JOIN Ref_Shipping_Agents ON Documents.shipping_agent_code = Ref_Shipping_Agents.shipping_agent_code WHERE Ref_Shipping_Agents.shipping_agent_name = "USPS";

Question: What is draft detail of the document with id 7?
SQL: SELECT draft_details FROM Document_Drafts WHERE document_id = 7;

Question: How many draft copies does the document with id 2 have?
SQL: SELECT count(*) FROM Draft_Copies WHERE document_id = 2;

Question: Which document has the most draft copies? List its document id and number of draft copies.
SQL: SELECT document_id , count(copy_number) FROM Draft_Copies GROUP BY document_id ORDER BY count(copy_number) DESC LIMIT 1;

Question: Which documents have more than 1 draft copies? List document id and number of draft copies.
SQL: SELECT document_id , count(*) FROM Draft_Copies GROUP BY document_id HAVING count(*)  >  1;

Question: List all employees in the circulation history of the document with id 1. List the employee's name.
SQL: SELECT Employees.employee_name FROM Employees JOIN Circulation_History ON Circulation_History.employee_id = Employees.employee_id WHERE Circulation_History.document_id = 1;