LeetCode 1364: Number of Trusted Contacts of a Customer [SQL]

preview_player
Показать описание
Solution and walkthrough of leetcode database problem 1364: Number of Trusted Contacts of a Customer. I'm using MySQL but this solution should work in any SQL dialect such as PostgreSQL SQL Server, etc.

Playlists:

Рекомендации по теме
Комментарии
Автор

you videos are very helpful, kindly continue making videos .

sachin-bcm
Автор

why have you not joined invoices with contact

kirthikka
Автор

Count(contact_email) AS contacts_cnt confused as to why this outputs the proper count. seems like you would need a statement like " (select count(user_id) from contacts where user_id=cus.customer_id) as contact_cnt" for this to work.

ayeoh
Автор

Frederik Müller : Will this below code works:

select i.invoice_id, cus.customer_name, i.price,
(select count(user_id) from contacts where user_id=cus.customer_id) as contact_cnt,
(select count(email) from customer where email in
(select contact_email from contacts where user_id=cus.customer_id)) as trusted_contacts_cnt
from invocies i left join customer cus
on i.userid=cos.userid

rishianand
Автор

Is there a way to avoid select distinct.. I think it kind of degrades the performance.

pushpanthkumar