본문 바로가기

SQL

(20)
(SQL) - LeetCode (easy) 1407. Top Travellers https://leetcode.com/problems/top-travellers/description/ left join과 COALESECE함수를 사용해 본 문제였습니다. 📕 풀이방법 📔 풀이과정 1. users table에 rides table을 user_id에 대해 left join해줍니다. 이는 left outer join과 같은 keyword입니다. users.id에 대한 값이 rides.user_id에 없으면 자동으로 rides의 column에 null을 채워주게 됩니다.2. group by로 u.id, u.name에 대해 진행한 후 sum값으로 각 user_id의 distance합을 구해 null값인 경우 0으로 만들어 주도록 coalesce함수를 사용해줍니다. 📕 Code 📔 ANSI SQL..
(SQL) - LeetCode (easy) 1378. Replace Employee ID With The Unique Identifier https://leetcode.com/problems/replace-employee-id-with-the-unique-identifier/ Replace Employee ID With The Unique Identifier - LeetCode Can you solve this real interview question? Replace Employee ID With The Unique Identifier - Table: Employees +---------------+---------+ | Column Name | Type | +---------------+---------+ | id | int | | name | varchar | +---------------+---------+ id is t leetc..
(Tibero 7) - varray 찍먹하기 🍳머리말 tibero7 에서는 list data type이 없기 때문에 그에 준하는 여러 type으로 column을 선언해 사용합니다. json보다 조회 및 data 변경이 빠른 varray를 다뤄보는 기본 예제에 대한 설명입니다. 📕Prerequisite 📔 Tibero 7 📔 DBeaver 📕생성 📔 varray type선언으로 생성해야됩니다. 📑 DDL CREATE OR REPLACE TYPE "EX_VARRAY_TYPE" AS VARRAY(1000) OF NUMBER; 📔 table 조직, 요리사, 과학자, 회사원 table이 존재하며 조직이 요리사, 과학자 id 들을 varray로 들고 있습니다. 하나의 조직에 속한 여러 요리사들과 과학자들 그리고 회사원을 의미합니다. 📑 DDL CREATE S..
(SQL) - LeetCode (easy) 1280. Students and Examinations https://leetcode.com/problems/students-and-examinations/description/ Students and Examinations - LeetCode Can you solve this real interview question? Students and Examinations - Table: Students +---------------+---------+ | Column Name | Type | +---------------+---------+ | student_id | int | | student_name | varchar | +---------------+---------+ student_id is leetcode.com cross join, left join을..
(SQL) - LeetCode (easy) 1179. Reformat Department Table https://leetcode.com/problems/reformat-department-table/description/ Reformat Department Table - LeetCode Can you solve this real interview question? Reformat Department Table - Table: Department +-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | revenue | int | | month | varchar | +-------------+---------+ In SQL,(id, mo leetcode.com 집계함수와 CASE WHEN 절을 사용해..
(SQL) - LeetCode (easy) 1084. Sales Analysis III https://leetcode.com/problems/sales-analysis-iii/description/ Sales Analysis III - LeetCode Can you solve this real interview question? Sales Analysis III - Table: Product +--------------+---------+ | Column Name | Type | +--------------+---------+ | product_id | int | | product_name | varchar | | unit_price | int | +--------------+---------+ pro leetcode.com join과 group by를 사용해본 문제였습니다. 📕 풀이방법 ..
(SQL) - LeetCode (easy) 1075. Project Employees I https://leetcode.com/problems/project-employees-i/description/ Project Employees I - LeetCode Can you solve this real interview question? Project Employees I - Table: Project +-------------+---------+ | Column Name | Type | +-------------+---------+ | project_id | int | | employee_id | int | +-------------+---------+ (project_id, employee_id) is th leetcode.com 집계함수와 join을 사용해보는 문제였습니다. 📕 풀이방법 📔..
(SQL) - LeetCode (easy) 627. Swap Salary https://leetcode.com/problems/swap-salary/description/ Swap Salary - LeetCode Can you solve this real interview question? Swap Salary - Table: Salary +-------------+----------+ | Column Name | Type | +-------------+----------+ | id | int | | name | varchar | | sex | ENUM | | salary | int | +-------------+----------+ id is the primar leetcode.com update문에 case when절을 사용해본 문제였습니다. 📕 풀이방법 📔 풀이과정 성별..