문제
입력 코드
SELECT sell_date,
COUNT(DISTINCT(product)) AS num_sold,
GROUP_CONCAT(DISTINCT(product)) AS products
FROM Activities
GROUP BY sell_date
ORDER BY sell_date
SELECT sell_date,
COUNT(DISTINCT(product)) AS num_sold,
GROUP_CONCAT(DISTINCT(product)
ORDER BY product ASC
SEPARATOR ',') AS products
FROM Activities
GROUP BY sell_date
ORDER BY sell_date ASC
코드 설명
#SELECT #COUNT #DISTINCT #GROUP_CONCAT #GROUP BY #ORDER BY
GROUP_CONCAT()
- GROUP_CONCAT(컬럼명)
- GROUP_CONCAT(DISTINCT 컬럼명) : 중복 제거
- GROUP_CONCAT(컬럼명 SEPERATOR '구분자') : 구분자 변경
- GROUP_CONCAT(컬럼명 ORDER BY 컬럼명) : 문자열 정렬
문제 출처
'SQL' 카테고리의 다른 글
#124. [LeetCode / MySQL] 1517. Find Users With Valid E-Mails (0) | 2024.06.23 |
---|---|
#123. [LeetCode / MySQL] 1327. List the Products Ordered in a Period (0) | 2024.06.23 |
#121. [LeetCode / MySQL] 176. Second Highest Salary (0) | 2024.06.22 |
#120. [LeetCode / MySQL] 196. Delete Duplicate Emails (0) | 2024.06.21 |
#119. [LeetCode / MySQL] 1527. Patients With a Condition (0) | 2024.06.21 |