본문 바로가기

Algorithm/SQL

(42)
(SQL) - LeetCode (easy) 1527. Patients With a Condition https://leetcode.com/problems/patients-with-a-condition/ 📕 풀이방법 📔 정답 출력 | 반환 LIKE절을 사용해 DIAB1으로 시작하는 conditions를 select합니다. 📕 Code 📔 ANSI SQL SELECT * FROM patients WHERE conditions LIKE 'DIAB1%' OR conditions LIKE '% DIAB1%'; *더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.
(SQL) - LeetCode (easy) 1507. Reformat Date https://leetcode.com/problems/find-users-with-valid-e-mails/ 정규 표현식을 사용해본 문제였습니다. 📕 풀이방법 📔 풀이과정 첫 글자는 alphabat, 다음부터는 alphabat, '.', '_', '-', 숫자가 존재하며 domain name이 있는 valid 한 email 주소만 찾아 select합니다. 📕 Code 📔 MySQL SELECT user_id, name, mail FROM Users WHERE mail REGEXP '^[a-zA-Z][a-zA-Z0-9._-]*@leetcode\\.com$'; *더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.
(SQL) - LeetCode (easy) 1484. Group Sold Products By The Date https://leetcode.com/problems/group-sold-products-by-the-date/ 언어별 group by 시 연속되는 문자열을 포함하는 여러 방식을 사용해본 문제였습니다. 📕 풀이방법 📔 풀이과정 sell_date와 distinct한 product 개수 num_sold와, group 화 된 product는 나열할 수 있는 MySQL의 GROUP_CONCAT나 PostgreSQL의 STRING_AGG나 Oracle의 LISTAGG를 사용해 products열을 select해줍니다. 📕 Code 📔 MySQL SELECT sell_date, COUNT(DISTINCT product) AS num_sold, GROUP_CONCAT(DISTINCT product ORDER BY pr..
(SQL) - LeetCode (easy) 1251. Average Selling Price https://leetcode.com/problems/average-selling-price/description/ Average Selling Price - LeetCode Can you solve this real interview question? Average Selling Price - Table: Prices +---------------+---------+ | Column Name | Type | +---------------+---------+ | product_id | int | | start_date | date | | end_date | date | | price | int | +--------------- leetcode.com case, join, group by를 사용해 본 문제..
(SQL) - LeetCode (easy) 1211. Queries Quality and Percentage https://leetcode.com/problems/queries-quality-and-percentage/description/ Queries Quality and Percentage - LeetCode Can you solve this real interview question? Queries Quality and Percentage - Table: Queries +-------------+---------+ | Column Name | Type | +-------------+---------+ | query_name | varchar | | result | varchar | | position | int | | rating | int | +------ leetcode.com 집계함수를 사용해본 문..
(SQL) - LeetCode (easy) 1148. Article Views I https://leetcode.com/problems/article-views-i/description/ Article Views I - LeetCode Can you solve this real interview question? Article Views I - Table: Views +---------------+---------+ | Column Name | Type | +---------------+---------+ | article_id | int | | author_id | int | | viewer_id | int | | view_date | date | +---------------+--- leetcode.com distinct를 사용해 해결한 문제였습니다. 📕 풀이방법 📔 풀이과정 자기..
(SQL) - LeetCode (easy) 1141. User Activity for the Past 30 Days I https://leetcode.com/problems/user-activity-for-the-past-30-days-i/description/ User Activity for the Past 30 Days I - LeetCode Can you solve this real interview question? User Activity for the Past 30 Days I - Table: Activity +---------------+---------+ | Column Name | Type | +---------------+---------+ | user_id | int | | session_id | int | | activity_date | date | | activity_typ leetcode.com ..
(SQL) - LeetCode (easy) 1050. Actors and Directors Who Cooperated At Least Three Times https://leetcode.com/problems/actors-and-directors-who-cooperated-at-least-three-times/ Actors and Directors Who Cooperated At Least Three Times - LeetCode Can you solve this real interview question? Actors and Directors Who Cooperated At Least Three Times - Table: ActorDirector +-------------+---------+ | Column Name | Type | +-------------+---------+ | actor_id | int | | director_id | int | | ..