Invoices table with the Customers table on user_id to customer_id to get the customer names for each invoice.Contacts table on user_id to get all contacts for each customer.SELECT clause to count the number of trusted contacts by checking if the contact's email exists in the Customers table.GROUP BY clause to group results by invoice_id.invoice_id.erDiagram
Customers ||--o{ Invoices : has
Customers ||--o{ Contacts : has
Invoices {
int invoice_id PK
int price
int user_id FK
}
Customers {
int customer_id PK
varchar customer_name
varchar email
}
Contacts {
int user_id PK
varchar contact_name
varchar contact_email PK
}