반응형
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
*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.
'SQL' 카테고리의 다른 글
(SQL) - LeetCode (easy) 1741. Find Total Time Spent by Each Employee (0) | 2024.07.10 |
---|---|
(SQL) - LeetCode (easy) 1729. Find Followers Count (0) | 2024.06.23 |
(SQL) - LeetCode (easy) 1683. Invalid Tweets (0) | 2024.06.07 |
(SQL) - LeetCode (easy) 1667. Fix Names in a Table (0) | 2024.05.30 |
(SQL) - LeetCode (easy) 1656. Design an Ordered Stream (0) | 2024.05.27 |