LeetCode - 1484. Group Sold Products By The Date (MySQL)

조민수·2024년 6월 13일
0

LeetCode

목록 보기
33/61

Easy, SQL - GROUP_CONCAT

RunTime : 422 ms


문제

Write a solution to find for each date the number of different products sold and their names.

The sold products names for each date should be sorted lexicographically.

Return the result table ordered by sell_date.

The result format is in the following example.


풀이

  • 도대체 product들의 종류를 어떻게 가져올 지 몰랐다.
  • GROUP_CONCAT을 통해 SEPARATOR를 기준으로 값들을 나누어 가져올 수 있었다.
SELECT sell_date, COUNT(DISTINCT product) as num_sold, 
GROUP_CONCAT(
    DISTINCT product ORDER BY product SEPARATOR ','
) as products
FROM Activities
GROUP BY sell_date
ORDER BY sell_date
profile
사람을 좋아하는 Front-End 개발자

0개의 댓글