Search⌘ K
AI Features

Exercise: Databases

Explore practical techniques for extracting specific customer and product data from MySQL and PostgreSQL databases using Python. Understand how to connect to databases, execute SQL queries, filter data, and export results as CSV files. This lesson helps you apply data extraction skills essential for effective ETL pipelines.

Example

Suppose we’re data analysts working for a retail company and our task is to extract customer and product-related data from two relational databases: MySQL and PostgreSQL. The customer data is stored in MySQL, while the product data is stored in PostgreSQL. The company is interested in focusing its marketing budget on marketing the most expensive products to customers from the USA.

We’ve decided to use Python to connect to both databases, extract the required data, and export it as CSV files to accomplish the task.

Note: Fill in the missing code in the highlighted rows in the code widgets to complete the tasks.

Extracting customer data from MySQL

The first task is to extract data from the customers table from MySQL. The marketing department is interested in marketing to ...