1364. Number of Trusted Contacts of a Customer

https://leetcode.com/problems/number-of-trusted-contacts-of-a-customer

Description

Table: Customers

+---------------+---------+
| Column Name   | Type    |
+---------------+---------+
| customer\_id   | int     |
| customer\_name | varchar |
| email         | varchar |
+---------------+---------+
customer\_id is the primary key for this table.
Each row of this table contains the name and the email of a customer of an online shop.

Table: Contacts

+---------------+---------+
| Column Name   | Type    |
+---------------+---------+
| user\_id       | id      |
| contact\_name  | varchar |
| contact\_email | varchar |
+---------------+---------+
(user\_id, contact\_email) is the primary key for this table.
Each row of this table contains the name and email of one contact of customer with user\_id.
This table contains information about people each customer trust. The contact may or may not exist in the Customers table.

Table: Invoices

Write an SQL query to find the following for each invoice_id:

  • customer_name: The name of the customer the invoice is related to.

  • price: The price of the invoice.

  • contacts_cnt: The number of contacts related to the customer.

  • trusted_contacts_cnt: The number of contacts related to the customer and at the same time they are customers to the shop. (i.e His/Her email exists in the Customers table.)

Order the result table by invoice\_id.

The query result format is in the following example:

ac

Last updated

Was this helpful?