AI Database Engineer - Integrate AI with your data team.
What are the tables in the prod schema?
SELECT table_name FROM information_schema.tables WHERE table_schema = 'prod'
The tables in the "prod" schema are:
What is in invoices?
SELECT * FROM prod.invoices LIMIT 5
The "invoices" table in the "prod" schema contains the following columns:
Here are the first 5 rows from the "invoices" table:
invoice_id | user_id | amount | due_date |
---|---|---|---|
1 | 1 | 100.00 | 2022-02-01 |
2 | 2 | 150.00 | 2022-03-01 |
3 | 3 | 200.00 | 2022-04-01 |
4 | 4 | 250.00 | 2022-05-01 |
5 | 5 | 300.00 | 2022-06-01 |
Can you join the user table, so I can see amount by user's name?
SELECT column_name, data_type FROM information_schema.columns WHERE table_schema = 'prod' AND table_name = 'users'
The "users" table in the "prod" schema contains the following columns:
I will now use the correct column ("username") to join the tables and retrieve the data.
SELECT u.username, i.amount, i.due_date FROM prod.invoices i JOIN prod.users u ON i.user_id = u.user_id LIMIT 5
Here is the data showing the amount owed by each user in the "invoices" table:
username | amount | due_date |
---|---|---|
john_doe | 100.00 | 2022-02-01 |
jane_smith | 150.00 | 2022-03-01 |
alice_jones | 200.00 | 2022-04-01 |
bob_smith | 250.00 | 2022-05-01 |
emma_watson | 300.00 | 2022-06-01 |
make this a bar chart
SELECT u.username, i.amount FROM prod.invoices i JOIN prod.users u ON i.user_id = u.user_id
Here is the bar chart showing the invoice amount by user: