Database: cre_Doc_Template_Mgt

Question: List document IDs, document names, and document descriptions for all documents.
SQL: SELECT document_id ,  document_name ,  document_description FROM Documents

Question: What is the document name and template id for document with description with the letter 'w' in it?
SQL: SELECT document_name ,  template_id FROM Documents WHERE Document_Description LIKE "%w%"

Question: What is the document id, template id and description for document named "Robbin CV"?
SQL: SELECT document_id ,  template_id ,  Document_Description FROM Documents WHERE document_name  =  "Robbin CV"

Question: How many different templates do all document use?
SQL: SELECT count(DISTINCT template_id) FROM Documents

Question: How many documents are using the template with type code 'PPT'?
SQL: SELECT count(*) FROM Documents AS T1 JOIN Templates AS T2 ON T1.Template_ID  =  T2.Template_ID WHERE T2.Template_Type_Code  =  'PPT'

Question: Show all template ids and number of documents using each template.
SQL: SELECT template_id ,  count(*) FROM Documents GROUP BY template_id

Question: What is the id and type code for the template used by the most documents?
SQL: SELECT T1.template_id ,  T2.Template_Type_Code FROM Documents AS T1 JOIN Templates AS T2 ON T1.template_id  =  T2.template_id GROUP BY T1.template_id ORDER BY count(*) DESC LIMIT 1

Question: Show ids for all templates that are used by more than one document.
SQL: SELECT template_id FROM Documents GROUP BY template_id HAVING count(*)  >  1

Question: Show ids for all templates not used by any document.
SQL: SELECT template_id FROM Templates EXCEPT SELECT template_id FROM Documents

Question: How many templates do we have?
SQL: SELECT count(*) FROM Templates

Question: Show template ids, version numbers, and template type codes for all templates.
SQL: SELECT template_id ,  version_number ,  template_type_code FROM Templates

Question: Show all distinct template type codes for all templates.
SQL: SELECT DISTINCT template_type_code FROM Templates

Question: What are the ids of templates with template type code PP or PPT?
SQL: SELECT template_id FROM Templates WHERE template_type_code  =  "PP" OR template_type_code  =  "PPT"

Question: How many templates have template type code CV?
SQL: SELECT count(*) FROM Templates WHERE template_type_code  =  "CV"

Question: What is the version number and template type code for the template with version number later than 5?
SQL: SELECT version_number ,  template_type_code FROM Templates WHERE version_number  >  5

Question: Show all template type codes and number of templates for each.
SQL: SELECT template_type_code ,  count(*) FROM Templates GROUP BY template_type_code

Question: Which template type code has most number of templates?
SQL: SELECT template_type_code FROM Templates GROUP BY template_type_code ORDER BY count(*) DESC LIMIT 1

Question: Show all template type codes with less than three templates.
SQL: SELECT template_type_code FROM Templates GROUP BY template_type_code HAVING count(*)  <  3

Question: What the smallest version number and its template type code?
SQL: SELECT min(Version_Number) ,  template_type_code FROM Templates