GPTBlocks

DBChat

DBChat by GPTBlocks

AI Database Engineer - Integrate AI with your data team.

User

What are the tables in the prod schema?

SQL

SELECT table_name FROM information_schema.tables WHERE table_schema = 'prod'

DBChat

The tables in the "prod" schema are:

  • users
  • subscriptions
  • payments
  • invoices
  • transactions
  • products
  • usage_event

User

What is in invoices?

SQL

SELECT * FROM prod.invoices LIMIT 5

DBChat

The "invoices" table in the "prod" schema contains the following columns:

  • invoice_id (integer)
  • user_id (integer)
  • amount (decimal)
  • due_date (date)

Here are the first 5 rows from the "invoices" table:

invoice_iduser_idamountdue_date
11100.002022-02-01
22150.002022-03-01
33200.002022-04-01
44250.002022-05-01
55300.002022-06-01

User

Can you join the user table, so I can see amount by user's name?

SQL

SELECT column_name, data_type FROM information_schema.columns WHERE table_schema = 'prod' AND table_name = 'users'

DBChat

The "users" table in the "prod" schema contains the following columns:

  • user_id (integer)
  • username (character varying)
  • email (character varying)
  • date_registered (date)

I will now use the correct column ("username") to join the tables and retrieve the data.

SQL

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

DBChat

Here is the data showing the amount owed by each user in the "invoices" table:

usernameamountdue_date
john_doe100.002022-02-01
jane_smith150.002022-03-01
alice_jones200.002022-04-01
bob_smith250.002022-05-01
emma_watson300.002022-06-01

User

make this a bar chart

SQL

SELECT u.username, i.amount FROM prod.invoices i JOIN prod.users u ON i.user_id = u.user_id

DBChat

Here is the bar chart showing the invoice amount by user: Invoice Amount by User