Skip to content

stu-dying/sql_authoritative-articles

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Authoritative articles

  1. Using your favorite DB client, design and create a table called authors that would store the first name, the last name, and the sex of each of the following authors:

    • Abi Maxwell (F)
    • Anthony Alofsin (M)
    • Emily Temple (F)
    • Gabrielle Bellot (F)
    • Meg Donohue (F)
    • Philip Eil (M)
    • Roxana Robinson (F)
    • Tobias Carroll (M)
    • Veronica Esposito (F)

    Don’t forget that each table must have an ID field. Please also create the necessary constraints, keys and/or indices for the table. In order to do this you might first need to read this document through the end.

    Copy and paste the SQL query generated by the client below:

    CREATE TABLE ...
    
  2. Manually create a query or a series of queries filling the table with the data. Put the query/queries below:

    INSERT ...
    
  3. Using the client, design and create a table called articles that would store the information from the file articles.xlsx. Use the already created authors table in order to refer to the authors. Don’t forget to create an ID field and all necessary constraints/keys/indices.

    Copy and paste the SQL query generated by the client below:

    CREATE TABLE ...
    
  4. Using the client, fill the table:

    INSERT ...
    
  5. Retrieve articles with the information about the author attached to each row (there should be 12 rows in the result and around 10 columns, including the article’s title, text, rating, and date as well as the author’s name and sex):

    ... here goes your SQL ...
    
  6. To get the twelve rows, you must have used one of the constructions INNER JOIN, LEFT JOIN, RIGHT JOIN, or FULL JOIN. How many rows would the other three have returned? First try to think of the answers and then verify them by running the queries (it’s important you understand the results). Put the numbers below:

    INNER JOIN: ? rows
    LEFT JOIN: ? rows
    RIGHT JOIN: ? rows
    FULL JOIN: ? rows
    
  7. Imagine you’re using pagination to display articles showing five articles per page. Retrieve the content for the first page: create a query that would return the latest five articles, ordered from the latest to the earliest.

    ... here goes your SQL ...
    
  8. Retrieve the content for the second page: articles 6 through 10 (still assuming chronological order).

    ... here goes your SQL ...
    
  9. Retrieve the content for the third page: articles 11 through 15 (never mind there are actually only 12 of them currently in the table).

    ... here goes your SQL ...
    
  10. Count the number of five-article pages required to accommodate all articles:

    ... here goes your SQL ...
    
  11. Calculate an average rating of the articles, rounded to the nearest integer:

    ... here goes your SQL ...
    
  12. Count males and females among the authors. There should be two rows (for males and females) and two columns: sex (F or M) and cnt (count).

    ... here goes your SQL ...
    
  13. Find the date of the earliest (put in the column earliest) and latest (put in the column latest) article written by each author:

    ... here goes your SQL ...
    
  14. Calculate the total length of the text written by each author (count both text and title; you can keep the tags in text while counting):

    ... here goes your SQL ...
    
  15. Output all the authors in a random order. There should be only one column aliased author with the first and last name of the author concatenated (using a space, of course). The order of the rows should be different on each request:

    ... here goes your SQL ...
    
  16. "Anonymize" the authors: replace each author’s last name with the properly capitalized reverse of it. E.g., Alofsin should become Nisfola, Esposito should become Otisopse, etc.

    ... here goes your SQL ...
    
  17. Delete all articles that don’t have an author:

    ... here goes your SQL ...
    
  18. (optional) Delete all authors that haven’t written any articles:

    ... here goes your SQL ...
    

Don’t forget to create a pull request.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published