Giter VIP home page Giter VIP logo

gentle-intro-to-sql's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gentle-intro-to-sql's Issues

Add info on subqueries in select clauses

Possibly as an extension of Part II's subqueries section, we should mention the ability to use subqueries in select clauses. This can be a really powerful feature when combined with calculations #6.

For example, when working with the contributors.db in Part II, we can show how you can find
the percent of all contributions that went to each state using a select-clause subquery.

-- Show the percentage of all contributions spent in each state
SELECT 
    state, 
    sum(amount) as state_total,
    ( (sum(amount) * 1.0 ) / (select sum(amount) from contributors) ) * 100 as pct_of_all_contribs
FROM contributors
GROUP BY state
ORDER BY pct_of_all_contribs DESC
;

Add study exercises

A nice-to-have would be exercises for at least the more difficult sections such as subqueries, group by, having (and eventually) table joins.

Update Importing data to mention auto-import of CSVs

DB Browser's CSV import feature will auto-generate a table on import if none by the specified name already exists. It's a handy feature that's worth documenting in the Importing Data section (in the Appendix).

Self joins (part 3) needs re-working

Excluding the self joins section for now due to a few issues:

  • The last section seems to abruptly cut off (seems like some narrative may not have been committed).
  • The image reference for the join is incorrect (appears to be image from previous section).
  • It's a bit confusing: This particular data set doesn't seem like a good fit to explain this advanced concept. The canonical example for self joins is a table with a foreign key reference to itself, such as an employee's table with a manager foreign key that references other employees in the same table. Here's an example.

Add appendix section on saving scripts

DB Browser doesn't document the save/open buttons or the ability to create new SQL tabs, and students are accidentally exporting the entire db as a SQL script instead of saving tabs as sql scripts.

IS NULL section is incorrect

Neither DB Browser's GUI import nor raw SQLite (on the command line) will import blank fields into a TEXT or VARCHAR column as NULLs. Instead, it replaces those values with an empty string. This causes the queries in the "IS NULL" section of the tutorial (Part 2) to fail to return any rows when trying to match last_name field on IS NULL.

In order to demonstrate the use of IS NULL without a major rewrite of this section, we'll need to manually insert null values in the database. Will need to review this section and decide if all currently blank fields should be made null, or perhaps just the one or two relevant fields.

Further, with this change, the "Importing data" section at end of Part 1 becomes unusable for setting the stage for Part 2. May need to cut this out and just make it a separate section devoted to data importing. And then create a downloadable database file for Part 2 that contains the null values and other bits we need.

Mention "views" on Choosing to Denormalize page

The Choosing to Denormalize page mentions that it can be expensive to do a lot of joins, and therefore sometimes it's worth saving the output of a query in a new table. It goes on to note the downside that this table can become out-of-date if source tables are updated.

Probably worth mentioning "views" on this page as a possible additional strategy to spare you the work of having to update a table. You take the hit in terms of efficiency, it can be useful for scenarios where the query executes in a reasonable amount of time.

Add a section on calculations in select clauses

An important bit of the basics that we don't seem to have covered is how to perform calculations in the select clause. This could be something that we fold in after Part II's Aggregates section, for example by showing how we can do basic math to calculate averages, etc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.