- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1364.sql
14 lines (13 loc) · 481 Bytes
/
_1364.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
--credit: https://leetcode.com/problems/number-of-trusted-contacts-of-a-customer/discuss/522435/mysql-simple-solution
selecti.invoice_id,
c.customer_name,
i.price,
count(cont.contact_name) contacts_cnt,
sum(
if(cont.contact_namein (select distinct customer_name from customers), 1, 0)
) as trusted_contacts_cnt
from invoices i
join customers c onc.customer_id=i.user_id
left join Contacts cont oncont.user_id=c.customer_id
group byi.invoice_id
order byi.invoice_id;