본문 바로가기
🛠️Skill/CodingTest

[leetcode] 1484. Group Sold Products By The Date / GROUP_CONCAT

by Istj_eff 2022. 11. 7.

1484. Group Sold Products By The Date

 

https://leetcode.com/problems/group-sold-products-by-the-date/

 

Group Sold Products By The Date - LeetCode

Can you solve this real interview question? Group Sold Products By The Date - Table Activities: +-------------+---------+ | Column Name | Type | +-------------+---------+ | sell_date | date | | product | varchar | +-------------+---------+ There is no prim

leetcode.com

 

Write an SQL query 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 query result format is in the following example.

 

SELECT sell_date,
       COUNT(DISTINCT(product), sell_date) AS num_sold, 
       GROUP_CONCAT(DISTINCT product ORDER BY product) AS products
FROM Activities
GROUP BY sell_date
ORDER BY sell_date;

 

 

2022.12.14 - [🛠️Skill/SQL] - [SQL문법] GROUP_CONCAT 그룹별 집계

 

[SQL문법] GROUP_CONCAT 그룹별 집계

그룹별로 묶어서 한줄로 결과를 보여줘야 할 때 사용 SELECT 컬럼명1 , GROUP_CONAT(컬럼명2 ORDER BY 컬럼명3 SEPERATOR ':') FROM 테이블명 GROUP BY 컬럼명1 문자들은 기본적으로 ','으로 구분되지만 SEPERATOR를

dataanalysisdot.tistory.com

 

 

 

댓글