PostgreSQL 풀이 | Second Highest Salary (LEAD, OFFSET, MAX)
·
SQL
문제 1.  Second Highest SalaryImagine you're an HR analyst at a tech company tasked with analyzing employee salaries. Your manager is keen on understanding the pay distribution and asks you to determine the second highest salary among all employees.It's possible that multiple employees may share the same second highest salary. In case of duplicate, display the salary only once.https://datalemur.co..
PostgreSQL 풀이 | User's Third Transaction (ROW_NUMBER, RANK, DENSE_RANK)
·
SQL
문제 1.  User's Third TransactionAssume you are given the table below on Uber transactions made by users. Write a query to obtain the third transaction of every user. Output the user id, spend and transaction date.https://datalemur.com/questions/sql-third-transaction Uber SQL Interview Question | DataLemurUber SQL Interview Question: Write a query to find the user's third transaction.datalemur.com..
PostgreSQL 풀이 | Tweets' Rolling Averages (윈도우함수 ROWS BETWEEN)
·
SQL
문제1.  Tweets' Rolling AveragesGiven a table of tweet data over a specified time period, calculate the 3-day rolling average of tweets for each user. Output the user ID, tweet date, and rolling averages rounded to 2 decimal places.Notes:A rolling average, also known as a moving average or running mean is a time-series technique that examines trends in data over a specified period of time.In this ..
MySQL 풀이 | Customer Who Visited but Did Not Make Any Transactions
·
SQL
문제 1.  Customer Who Visited but Did Not Make Any TransactionsTable: Visits+-------------+---------+| Column Name | Type    |+-------------+---------+| visit_id    | int     || customer_id | int     |+-------------+---------+visit_id is the column with unique values for this table.This table contains information about the customers who visited the mall. Table: Transactions+----------------+------..
MySQL 풀이 | Product Sales Analysis I
·
SQL
문제 1.  Product Sales Analysis ITable: Sales+-------------+-------+| Column Name | Type  |+-------------+-------+| sale_id     | int   || product_id  | int   || year        | int   || quantity    | int   || price       | int   |+-------------+-------+(sale_id, year) is the primary key (combination of columns with unique values) of this table.product_id is a foreign key (reference column) to Produ..
MySQL 풀이 | Replace Employee ID With The Unique Identifier
·
SQL
문제 1.  Replace Employee ID With The Unique IdentifierWrite a solution to show the unique ID of each user, If a user does not have a unique ID replace just show null.Return the result table in any order.Example 1:Input: Employees table:+----+----------+| id | name |+----+----------+| 1 | Alice || 7 | Bob || 11 | Meir || 90 | Winston || 3 | Jonathan |+----+----------+EmployeeUN..
MySQL 풀이 | Invalid Tweets
·
SQL
문제 1.  Invalid TweetsWrite a solution to find the IDs of the invalid tweets. The tweet is invalid if the number of characters used in the content of the tweet is strictly greater than 15.Return the result table in any order.The result format is in the following example.Example 1:Input: Tweets table:+----------+-----------------------------------+| tweet_id | content |+-..
MySQL 풀이 | Article Views I
·
SQL
문제 1.  Article Views IWrite a solution to find all the authors that viewed at least one of their own articles.자기 자신의 기사를 한번이라도 읽은 저자 찾기Return the result table sorted by id in ascending order.The result format is in the following example.https://leetcode.com/problems/article-views-i/description/💡 문제 풀이 `내 풀이`select distinct author_id as idfrom Viewswhere author_id = viewer_idorder by id실행 결과
MySQL 풀이 | Big Countries
·
SQL
문제 1.  Big CountriesA country is big if:it has an area of at least three million (i.e., 3000000 km2), orit has a population of at least twenty-five million (i.e., 25000000).Write a solution to find the name, population, and area of the big countries.Return the result table in any order.The result format is in the following example.https://leetcode.com/problems/big-countries/💡 문제 풀이 `내 풀이`select..
MySQL 풀이 | Find Customer Referee
·
SQL
문제 1.  Find Customer RefereeTable: Customer+-------------+---------+| Column Name | Type    |+-------------+---------+| id          | int     || name        | varchar || referee_id  | int     |+-------------+---------+In SQL, id is the primary key column for this table.Each row of this table indicates the id of a customer, their name, and the id of the customer who referred them. Find the names ..