https://leetcode.com/problems/group-sold-products-by-the-date/
Group Sold Products By The Date - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
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;
best
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
References
https://fruitdev.tistory.com/16
[MySQL] GROUP_CONCAT 사용하기
필요에 의해 서로 다른 결과를 한줄로 합쳐서 보여줘야 할 경우가 있다. 전체 결과값을 가져와서 java 와 같은 프로그램 언어에서 for 문을 돌며 문자열을 붙여도 되긴 하지만 Select 쿼리를 던질때
fruitdev.tistory.com
728x90
반응형
'자료구조 알고리즘 > 코딩테스트' 카테고리의 다른 글
1965. Employees With Missing Information (0) | 2022.05.30 |
---|---|
1527. Patients With a Condition (0) | 2022.05.30 |
1667. Fix Names in a Table (0) | 2022.05.30 |
196. Delete Duplicate Emails (0) | 2022.05.30 |
627. Swap Salary (0) | 2022.05.30 |