코린이의 소소한 공부노트

[LeetCode/Easy] 1693. Daily Leads and Partners 본문

코딩테스트 풀이/SQL

[LeetCode/Easy] 1693. Daily Leads and Partners

무지맘 2023. 4. 15. 02:46

1. Input

1) Table: DailySales (pk: 없음)

 

2. Output

1) 각 날짜와 이름별로 lead_idpartner_id의 수를 센 결과를 출력

- 중복은 세지 않는다.

- 출력 순서는 상관 없다.

 

3. Example

 

4. Code

1) 첫 코드(2023/04/15)

select a.date_id, a.make_name, a.unique_leads, b.unique_partners
from (select date_id, make_name, count(distinct lead_id) as unique_leads
      from DailySales group by date_id, make_name) a,
     (select date_id, make_name, count(distinct partner_id) as unique_partners
      from DailySales group by date_id, make_name) b
where a.date_id=b.date_id and a.make_name=b.make_name;