1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Databases in Python

Exercise

More practice with joins

You can use the same select statement you built in the last exercise, however, let's add a twist and only return a few columns and use the other table in a group_by() clause.

Instructions

100 XP
  • Build a statement to select:
    • The state column from the census table.
    • The sum of the pop2008 column from the census table.
    • The census_division_name column from the state_fact table.
  • Append a .select_from() to stmt in order to join the census and state_fact tables by the state and name columns.
  • Group the statement by the name column of the state_fact table.
  • Execute the statement stmt_grouped to get all the records and save it as results.
  • Hit 'Submit Answer' to loop over the results object and print each record.