SQL/문제

SQL | Group Sold Products By The Date, Find Users With Valid E-Mails

jjangdoll 2025. 1. 13. 11:47

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


Group Sold Products By The Date

내가 쓴 답 (1021ms) : 

# 각 날짜별 판매된 제품수, 이름
# 사전순으로 정렬
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

-GROUP_CONCAT을 사용


다른 사람이 쓴 답 (373ms) : 

# Write your MySQL query statement below
select 
sell_date, count(distinct product) as num_sold, 
group_concat(distinct product) as products 
from activities 
group by sell_date;

https://leetcode.com/problems/find-users-with-valid-e-mails/description/


Find Users With Valid E-Mails

# 유효한 이메일 가진 사용자 조회
# 접두사 이름은 문자로 시작
SELECT *
FROM Users
WHERE mail REGEXP '^[a-zA-Z][a-zA-Z0-9_.-]*@leetcode[.]com$'