본문 바로가기

SQL

(SQL) - LeetCode (easy) 1693. Daily Leads and Partners

반응형

https://leetcode.com/problems/daily-leads-and-partners/description/

group by와 distinct를 사용해본 문제였습니다.

📕 풀이방법

📔 풀이과정

date_id, make_name에 대해 group화를 진행한 후 lead_id, partner_id의 unique 값을 count해 select해줍니다.


📕 Code

📔 MySQL

select date_id, make_name, count(distinct lead_id) as unique_leads, count(distinct partner_id) as unique_partners
from dailysales
group by date_id, make_name
order by date_id desc

📔 Oracle

SELECT TO_CHAR(date_id, 'YYYY-MM-DD') as "date_id",
       make_name as "make_name", 
       COUNT(DISTINCT lead_id) AS "unique_leads", 
       COUNT(DISTINCT partner_id) AS "unique_partners"
FROM DailySales
GROUP BY date_id, make_name

*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.