본문 바로가기

SQL

(22)
(SQL) - LeetCode (easy) 1587. Bank Account Summary II https://leetcode.com/problems/bank-account-summary-ii/description/join, group by를 사용해본 문제였습니다.📕 풀이방법📔 풀이과정users와 transactions를 join한 후 users name과 transactions amount총합을 구해줍니다. 총합을 구하기 위해 sum 함수를 사용해야 하므로 account, name에 대해 group by를 해줍니다.📕 Code📔 ANSI SQLselect u.name, sum(t.amount) as balance from users ujoin transactions t on u.account = t.accountgroup by t.account, u.namehaving sum(t.amoun..
(SQL) - LeetCode (easy) 1581. Customer Who Visited but Did Not Make Any Transactions https://leetcode.com/problems/customer-who-visited-but-did-not-make-any-transactions/description/join을 사용해본 문제였습니다.📕 풀이방법📔 풀이과정visit_id로 visits와 transactions table을 join한 후 customer_id로 goup by햐 transaction_id가 null인 column의 visit_id를 count해 준 후 customer_id와 함께 select합니다.📕 Code📔 ANSI SQLselect v.customer_id, count(v.visit_id) as count_no_transfrom visits vleft join transactions t on v.visit_..
(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를 사용해본 문제였습니다. 📕 풀이방법 ..